diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b8dc63..a5432f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.1.0] - 2026-10-24 + +First release. The Changed, Removed and Fixed sections describe differences from +the unreleased code on `main` before this version, for anyone who built it from +source. + ### Added -- Initial project structure - Dockerfile parser with multi-stage build support - Lint rules for base images, layer optimization, security, and best practices - CLI with file and stdin input support @@ -47,6 +52,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 `--no-config` flags - The GitHub Action lints several paths or patterns (one per line) and takes a `config` input +- `--version` falls back to the version Go records in the binary, so builds from + `go install github.com/devblac/docker-lint/cmd/docker-lint@v0.1.0` report it ### Changed - **Breaking:** rule IDs move from `DLxxxx`, which collide with hadolint's IDs for @@ -73,9 +80,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 corpus they fired on 51 and 39 of 52 files, and Kubernetes ignores HEALTHCHECK - DKL103 judges only the base of the final image -### Deprecated -- N/A - ### Removed - Hand-written Dockerfile lexer (`internal/parser/lexer.go`), superseded by BuildKit @@ -103,5 +107,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 (`COPY go.mod go.sum ./`, `COPY package*.json ./`) because it inspected the destination instead of the sources -### Security -- N/A +[Unreleased]: https://github.com/devblac/docker-lint/compare/v0.1.0...HEAD +[0.1.0]: https://github.com/devblac/docker-lint/releases/tag/v0.1.0 diff --git a/cmd/docker-lint/main.go b/cmd/docker-lint/main.go index 51b3134..34e9341 100644 --- a/cmd/docker-lint/main.go +++ b/cmd/docker-lint/main.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "os" + "runtime/debug" "strings" "github.com/devblac/docker-lint/internal/analyzer" @@ -402,7 +403,32 @@ Exit Codes: } func printVersion(w io.Writer) { - fmt.Fprintf(w, "docker-lint version %s (commit %s, built %s)\n", version, commit, date) + info, _ := debug.ReadBuildInfo() + v, c, d := buildVersion(info) + fmt.Fprintf(w, "docker-lint version %s (commit %s, built %s)\n", v, c, d) +} + +// buildVersion returns the version, commit and build date to report. Release +// builds set them with -ldflags. Other builds fall back to what Go records in +// the binary: the module version for "go install ...@v0.1.0", and the VCS +// revision and commit time for a build inside a Git checkout. +func buildVersion(info *debug.BuildInfo) (v, c, d string) { + v, c, d = version, commit, date + if info == nil { + return v, c, d + } + if v == "dev" && info.Main.Version != "" && info.Main.Version != "(devel)" { + v = strings.TrimPrefix(info.Main.Version, "v") + } + for _, setting := range info.Settings { + switch { + case setting.Key == "vcs.revision" && c == "none": + c = setting.Value + case setting.Key == "vcs.time" && d == "unknown": + d = setting.Value + } + } + return v, c, d } func listRules(w io.Writer) { diff --git a/cmd/docker-lint/main_test.go b/cmd/docker-lint/main_test.go index cea48fc..f92f438 100644 --- a/cmd/docker-lint/main_test.go +++ b/cmd/docker-lint/main_test.go @@ -6,6 +6,7 @@ import ( "encoding/json" "os" "path/filepath" + "runtime/debug" "strings" "testing" ) @@ -866,3 +867,61 @@ func TestSARIFKeepsExitCode(t *testing.T) { t.Errorf("expected an error-level result:\n%s", stdout.String()) } } + +// TestBuildVersionFallback verifies binaries built without -ldflags, such as +// by "go install ...@v0.1.0", report the version Go recorded in the binary. +func TestBuildVersionFallback(t *testing.T) { + origVersion, origCommit, origDate := version, commit, date + defer func() { + version, commit, date = origVersion, origCommit, origDate + }() + + tests := []struct { + name string + ldflags [3]string + info *debug.BuildInfo + wantV, wantC, wantD string + }{ + { + name: "go install from the module proxy", + ldflags: [3]string{"dev", "none", "unknown"}, + info: &debug.BuildInfo{Main: debug.Module{Version: "v0.1.0"}}, + wantV: "0.1.0", wantC: "none", wantD: "unknown", + }, + { + name: "go build in a checkout", + ldflags: [3]string{"dev", "none", "unknown"}, + info: &debug.BuildInfo{ + Main: debug.Module{Version: "(devel)"}, + Settings: []debug.BuildSetting{ + {Key: "vcs.revision", Value: "abc123"}, + {Key: "vcs.time", Value: "2026-10-24T18:00:00Z"}, + }, + }, + wantV: "dev", wantC: "abc123", wantD: "2026-10-24T18:00:00Z", + }, + { + name: "ldflags win", + ldflags: [3]string{"0.2.0", "def456", "2026-11-01"}, + info: &debug.BuildInfo{ + Main: debug.Module{Version: "v0.1.0"}, + Settings: []debug.BuildSetting{{Key: "vcs.revision", Value: "abc123"}}, + }, + wantV: "0.2.0", wantC: "def456", wantD: "2026-11-01", + }, + { + name: "no build info", + ldflags: [3]string{"dev", "none", "unknown"}, + wantV: "dev", wantC: "none", wantD: "unknown", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + version, commit, date = tt.ldflags[0], tt.ldflags[1], tt.ldflags[2] + v, c, d := buildVersion(tt.info) + if v != tt.wantV || c != tt.wantC || d != tt.wantD { + t.Errorf("buildVersion() = %q, %q, %q; want %q, %q, %q", v, c, d, tt.wantV, tt.wantC, tt.wantD) + } + }) + } +} diff --git a/scripts/release-notes.sh b/scripts/release-notes.sh index d9ef506..1575f9e 100644 --- a/scripts/release-notes.sh +++ b/scripts/release-notes.sh @@ -15,6 +15,8 @@ notes="$(awk -v version="$version" ' if (found) exit if (index($0, "## [" version "]") == 1) { found = 1; next } } + # Link reference definitions at the end of the file belong to no section. + found && /^\[[^]]+\]: / { next } found { print } ' "$changelog")"