Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion site/src/content/docs/versions/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<prefix><version>` |
| `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 `<prefix><version>`; for an image, the same variant of it: `v2.15.0-alpine` moves to `v2.16.0-alpine` |
| `tags <repo>` | the highest release-numbered tag of a git repository; for a download, the highest whose file is published |
| `commit <repo> <branch>` | 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`) |
Expand Down
4 changes: 2 additions & 2 deletions versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 16 additions & 7 deletions versions/upstream/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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<version> (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<version> (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<version>", 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 {
Expand Down
27 changes: 17 additions & 10 deletions versions/upstream/upstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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-<version> was read as one")
}
}
Expand Down
Loading