From 60849a1ec16a75f7df9eb24f08d5676ad9a92aa4 Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Wed, 18 Nov 2026 17:45:21 -0300 Subject: [PATCH] versions: github-release keeps an image's variant, and golangci-lint is the -alpine image An image pinned at v2.15.0-alpine was behind for ever under github-release, whose newest is the release, v2.15.0, and a refresh moved it to the image without the variant. The track now spells the newest as the pin does, as go does for 1.27.4-trixie. Co-Authored-By: Claude Opus 5.5 --- site/src/content/docs/versions/reference.md | 2 +- versions.yaml | 4 +-- versions/upstream/upstream.go | 23 ++++++++++++------ versions/upstream/upstream_test.go | 27 +++++++++++++-------- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/site/src/content/docs/versions/reference.md b/site/src/content/docs/versions/reference.md index c025777..f752f27 100644 --- a/site/src/content/docs/versions/reference.md +++ b/site/src/content/docs/versions/reference.md @@ -33,7 +33,7 @@ description: Every kind of entry versions.yaml takes, the build arguments each b | track | the newest is | |---|---| -| `github-release [repo] [prefix]` | the repository's latest release (`source`'s by default), with a `v` only when the version has one; with a prefix, a release is `` | +| `github-release [repo] [prefix]` | the repository's latest release (`source`'s by default), with a `v` only when the version has one; with a prefix, a release is ``; for an image, the same variant of it: `v2.15.0-alpine` moves to `v2.16.0-alpine` | | `tags ` | the highest release-numbered tag of a git repository; for a download, the highest whose file is published | | `commit ` | the commit a branch is at, for a download whose version is a commit: behind only when the file changed | | `go` | the newest stable Go, spelled as the tag is (`1.27.1-trixie`) | diff --git a/versions.yaml b/versions.yaml index bf8fbf3..db56928 100644 --- a/versions.yaml +++ b/versions.yaml @@ -5,8 +5,8 @@ - name: golangci-lint kind: image source: golangci/golangci-lint - version: v2.15.0 - pin: sha256:fbfcfd12a6f8d7f1b97b3362ca80fc2a244d46863148c73cb88e7793af96c481 + version: v2.15.0-alpine + pin: sha256:2ba875b990f1d8501ad4ec19be1ea0701e316ec3a4b764f7b129f62f01318bbf track: github-release https://github.com/golangci/golangci-lint note: >- task lint, with spin's .golangci.yml: spin's version (its versions.yaml's golangci-lint), so diff --git a/versions/upstream/upstream.go b/versions/upstream/upstream.go index 3511bbc..629c15b 100644 --- a/versions/upstream/upstream.go +++ b/versions/upstream/upstream.go @@ -53,7 +53,7 @@ func newest(ctx context.Context, v *versions.Versions, e versions.Entry) (string if err != nil { return "", err } - return releaseVersion(tag, prefix, strings.HasPrefix(e.Version, "v")) + return releaseVersion(tag, prefix, e) case "go": return newestGo(ctx, e.Version) case "kernel": @@ -377,21 +377,30 @@ func sha256Of(ctx context.Context, url string) (string, error) { return sum, nil } -// releaseVersion is a release's tag as the pin spells a version: prefix taken off, for a -// repository whose releases are named prefix (cli-1.4.2 beside a library's tags), and the v -// its tags have only when the pin has one, since a download's URL may add it. A tag that does not -// start with prefix is no release of the kind the entry pins. -func releaseVersion(tag, prefix string, withV bool) (string, error) { +// releaseVersion is a release's tag as e spells a version: prefix taken off, for a repository +// whose releases are named prefix (cli-1.4.2 beside a library's tags), and the v its tags +// have only when e's version has one, since a download's URL may add it. An image keeps what its +// tag says after the version - v2.15.0-alpine is a variant of the release v2.15.0, and the newest +// is the same variant of the next, not the image without it. A tag that does not start with prefix +// is no release of the kind the entry pins. +func releaseVersion(tag, prefix string, e versions.Entry) (string, error) { version, ok := strings.CutPrefix(tag, prefix) if !ok { return "", fmt.Errorf("versions: the newest release, %s, is not %s", tag, prefix) } - if !withV { + if !strings.HasPrefix(e.Version, "v") { version = strings.TrimPrefix(version, "v") } + if m := variant.FindStringSubmatch(e.Version); m != nil && e.Kind == versions.Image { + version += m[1] + } return version, nil } +// variant is what an image's tag says after its version: -alpine of v2.15.0-alpine, nothing of +// v2.15.0. +var variant = regexp.MustCompile(`^v?[0-9]+(?:\.[0-9]+)*(.*)$`) + func githubRelease(ctx context.Context, repo string) (string, error) { path, ok := strings.CutPrefix(repo, "https://github.com/") if !ok { diff --git a/versions/upstream/upstream_test.go b/versions/upstream/upstream_test.go index 3f27aa0..3ff0af8 100644 --- a/versions/upstream/upstream_test.go +++ b/versions/upstream/upstream_test.go @@ -291,24 +291,31 @@ func TestAPinnedFileIsOnlyThePinnedBytes(t *testing.T) { require.ErrorContains(t, err, "go is a image, not a download") } -// A release's tag is the version the pin spells: a prefix the track names taken off, and a v kept -// only when the pin has one. +// A release's tag is the version the pin spells: a prefix the track names taken off, a v kept only +// when the pin has one, and an image's variant - what its tag says after the version - kept too. func TestAReleasesTagIsTheVersionThePinSpells(t *testing.T) { for _, tc := range []struct { tag, prefix string - withV bool + pinned versions.Entry want string }{ - {"v3.54.0", "", false, "3.54.0"}, - {"v3.54.0", "", true, "v3.54.0"}, - {"bin-20261109.193146", "bin-", false, "20261109.193146"}, - {"bin-v2", "bin-", true, "v2"}, + {"v3.54.0", "", versions.Entry{Version: "3.53.0"}, "3.54.0"}, + {"v3.54.0", "", versions.Entry{Version: "v3.53.0"}, "v3.54.0"}, + {"bin-20261109.193146", "bin-", versions.Entry{Version: "20261108.1"}, "20261109.193146"}, + {"bin-v2", "bin-", versions.Entry{Version: "v1"}, "v2"}, + {"v2.16.0", "", versions.Entry{Kind: versions.Image, Version: "v2.15.0-alpine"}, "v2.16.0-alpine"}, + {"v2.16.0", "", versions.Entry{Kind: versions.Image, Version: "v2.15.0"}, "v2.16.0"}, + {"1.0.5", "", versions.Entry{Kind: versions.Image, Version: "1.0.4-slim"}, "1.0.5-slim"}, + // Only an image's tag names a variant: a download's -linux is no part of its version. + {"v2.16.0", "", versions.Entry{Kind: versions.Download, Version: "v2.15.0-linux"}, "v2.16.0"}, + // A tag that does not start with a version has no variant to keep. + {"v2.16.0", "", versions.Entry{Kind: versions.Image, Version: "latest"}, "2.16.0"}, } { - if got, err := releaseVersion(tc.tag, tc.prefix, tc.withV); err != nil || got != tc.want { - t.Errorf("%s with %q: %q, %v; want %q", tc.tag, tc.prefix, got, err, tc.want) + if got, err := releaseVersion(tc.tag, tc.prefix, tc.pinned); err != nil || got != tc.want { + t.Errorf("%s with %q for %s: %q, %v; want %q", tc.tag, tc.prefix, tc.pinned.Version, got, err, tc.want) } } - if _, err := releaseVersion("v3.54.0", "bin-", false); err == nil { + if _, err := releaseVersion("v3.54.0", "bin-", versions.Entry{Version: "3.53.0"}); err == nil { t.Error("a release that is not bin- was read as one") } }