From edb5f2b11f392c31ea7e5afad35647cf46a3d647 Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Sun, 22 Nov 2026 14:11:56 -0300 Subject: [PATCH 1/7] task: release is cut only where the include states how, in a map no command line can spell Every repository that includes the common tasks has a `release`, and it refused in the ones that do not release only because two vars were absent. Under Task 3.54.0 a var of the command line or the environment reaches an included task wherever the include states none of that name. spin-machine, which is released by its own workflow, and spin-ami, which cuts no release, both have a ci.yml with a job named Gate, the values the pages showed: there `go tool task release GATE_WORKFLOW=ci.yml GATE_JOBS=Gate` named a release, and without RELEASE_DRY would have published an empty one marked latest (spin-stack/machine#529, spin-stack/ami#212). A repository now states how it is released in one var of the include, RELEASE, a map: `proof` and `jobs` where this task cuts the releases, with `files`; `elsewhere`, naming the workflow, where it releases but not with this task, as the four repositories whose release is built from its tag do; `none` where it does not release. They are keys and not a comment so that a gate can read them (spin-stack/devcontainer-cli#85 had only a comment to write). The command line and the environment hold strings, and no string is a map; where the include states the map it wins over both; and the task reads it through vars of its own, which Task reads after every other. So a repository that states nothing, `elsewhere` or `none` is refused with that reason whatever is typed, and one that releases is asked the proof and the jobs it states and no others. The tests run each case under Task. GATE_WORKFLOW, GATE_JOBS and RELEASE_FILES are read by nothing. "Gate" is the required check's name in spin-ami, and the two vars were set there for that reason. go-tools' own include states the map, and every other repository that set the vars states it in a commit of its own. Part of #135 Co-Authored-By: Claude Fable 5.2 --- Taskfile.yml | 6 +- internal/tasks/tasks.yml | 57 ++++++++++++++--- internal/tasks/tasks_test.go | 72 ++++++++++++++++++---- site/src/content/docs/start.md | 6 +- site/src/content/docs/tasks.md | 108 +++++++++++++++++++++++++++++---- 5 files changed, 212 insertions(+), 37 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 7e4ba6b..7a19ef5 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -31,9 +31,9 @@ includes: flatten: true vars: GO_TOOLS: 'go run ./cmd/' - GATE_WORKFLOW: ci.yml - GATE_JOBS: Gate - RELEASE_FILES: _output/release/*.tar.gz _output/release/checksums.txt + # release.yml runs `task release` once ci.yml's Gate has passed on the commit. + RELEASE: + map: {proof: ci.yml, jobs: Gate, files: _output/release/*.tar.gz _output/release/checksums.txt} # The others are the pins go tool sfw and go tool exposure embed for every repository. VERSIONS_FILES: versions.yaml cmd/sfw/versions.yaml cmd/exposure/versions.yaml # The site's CI page shows this workflow for a repository to copy. diff --git a/internal/tasks/tasks.yml b/internal/tasks/tasks.yml index 63b5262..6b93d16 100644 --- a/internal/tasks/tasks.yml +++ b/internal/tasks/tasks.yml @@ -7,17 +7,14 @@ # common: # taskfile: '{{.GO_TOOLS_TASKS}}' # flatten: true -# vars: {GATE_WORKFLOW: ci.yml, GATE_JOBS: Gate} # # flatten: the tasks keep these names, `task versions` and not `task common:versions`, and a # repository that defines one of them itself is refused by Task ("Found multiple tasks"), so a # name here has one meaning everywhere. What differs between repositories is the include's vars, # and nothing else: # -# GATE_WORKFLOW the workflow whose pass proves a commit, as ci.yml; a repository that sets -# GATE_JOBS neither does not release, and `task release` says so. The jobs are those the -# pass must have run, by the start of their name and comma-separated. -# RELEASE_FILES what a release carries besides its tag: files, or globs of them. +# RELEASE how the repository is released, a map: `release` below says what it holds and +# why it is one. # VERSIONS_FILES every file of pins the repository has, when versions.yaml is not the only one. # WORKFLOWS_ALSO a second .github directory the repository holds - an example it publishes. # CONSUMERS where the consumers table is, when it is not consumers.toml. @@ -53,13 +50,53 @@ tasks: - '{{.GO_TOOLS}}versions bump -file {{.FILE | default "versions.yaml"}} {{.NAME}} {{.TO}}' release: - desc: Release main's head (or SHA) as the next v. of today, in UTC, with RELEASE_FILES. A person runs it, with gh logged in, or a workflow with GH_TOKEN; it refuses a commit GATE_JOBS of GATE_WORKFLOW has not passed on, and one released already. RELEASE_DRY=1 refuses what a release would and prints the name, and releases nothing. - requires: - vars: [GATE_WORKFLOW, GATE_JOBS] + desc: Release main's head (or SHA) as the next v. of today, in UTC, with RELEASE's files - in a repository whose include states RELEASE's proof and jobs, and refused in every other. A person runs it, with gh logged in, or a workflow with GH_TOKEN; it refuses a commit the jobs of the proof workflow have not passed on, and one released already. RELEASE_DRY=1 refuses what a release would and prints the name, and releases nothing. + # RELEASE is a map, of the include's vars: + # + # vars: + # RELEASE: + # map: {proof: ci.yml, jobs: Gate, files: _output/*.tar.gz} + # + # proof the workflow whose pass proves a commit can be released. + # jobs the jobs that pass must have run, by the start of their name and comma-separated. + # files what the release carries besides its tag: files, or globs of them. + # elsewhere the repository releases, but not with this task: the file under + # .github/workflows that does, as release.yml. A release built from its tag - by + # GoReleaser, an image, a signature - is one this task cannot cut. + # none the repository does not release, and why in a sentence. + # + # The task refuses with `elsewhere` or `none`, whatever else the map holds. They are keys of + # the Taskfile and not a comment in it so that a gate can read them: a repository with a + # release workflow that has not said `elsewhere` is one a check can find. + # + # A map because the command line and the environment hold strings and nothing else. Under Task + # 3.54.0 a var of the command line or the environment reaches an included task wherever the + # include states none of that name, so two plain vars would be two words away from a release: in a + # repository that releases by its own workflow and has a ci.yml with a Gate job, `task release` + # with those two words would publish an empty release marked latest. No string is a map, and where + # the include states one it wins over both. So a repository that states nothing, `elsewhere` + # or `none` is one this task cannot be made to release. The vars below are the task's own, which Task + # reads after every other: none of them is the command line's either. + vars: + RELEASE_STATED: '{{kindIs "map" .RELEASE}}' + RELEASE_ELSEWHERE: '{{if kindIs "map" .RELEASE}}{{.RELEASE.elsewhere}}{{end}}' + RELEASE_NONE: '{{if kindIs "map" .RELEASE}}{{.RELEASE.none}}{{end}}' + RELEASE_PROOF: '{{if kindIs "map" .RELEASE}}{{.RELEASE.proof}}{{end}}' + RELEASE_JOBS: '{{if kindIs "map" .RELEASE}}{{.RELEASE.jobs}}{{end}}' + RELEASE_FILES: '{{if kindIs "map" .RELEASE}}{{.RELEASE.files}}{{end}}' + preconditions: + - sh: '{{.RELEASE_STATED}}' + msg: "release: this repository's include of the common tasks states no RELEASE, so nothing says how it is released and this task releases nothing. RELEASE is a map of the include's vars, written in the Taskfile - `map: {proof: , jobs: }` where this task cuts the releases, `map: {elsewhere: }` where the repository releases but not with this task, `map: {none: }` where it does not release - and a value on the command line or in the environment is not one." + - sh: '{{if .RELEASE_ELSEWHERE}}false{{else}}true{{end}}' + msg: "release: this repository releases, but not with this task: {{.RELEASE_ELSEWHERE}} does. Its Taskfile says so (RELEASE's elsewhere), and this task releases nothing here." + - sh: '{{if .RELEASE_NONE}}false{{else}}true{{end}}' + msg: "release: this repository does not release. Its Taskfile says why (RELEASE's none): {{.RELEASE_NONE}}" + - sh: '{{if and .RELEASE_PROOF .RELEASE_JOBS}}true{{else}}false{{end}}' + msg: "release: this repository's RELEASE names no proof and jobs, the workflow whose pass proves a commit and the jobs that pass must have run: without both nothing is proven, and nothing released." cmds: # The name is counted from every tag there is, and main's head is origin's as it is now. - git fetch --quiet --tags origin main - # proven: the gate passed on this commit, or on a pull request's with the same tree, which + # proven: the proof passed on this commit, or on a pull request's with the same tree, which # is what a rebase merge leaves main with. The release makes the tag, last, so one that # failed to publish is no tag naming a commit with no files. --latest: a repository # publishes other things as releases too (brand its screens, with --latest=false), and @@ -70,7 +107,7 @@ tasks: sha="$(git rev-parse --verify '{{.SHA | default "origin/main"}}^{commit}')" repo="${GITHUB_REPOSITORY:-}" [ -n "$repo" ] || repo="$(gh repo view --json nameWithOwner --jq .nameWithOwner)" - {{.GO_TOOLS}}proven release -repo "$repo" -sha "$sha" -workflow '{{.GATE_WORKFLOW}}' -events push,pull_request -ran '{{.GATE_JOBS}}' -also '' + {{.GO_TOOLS}}proven release -repo "$repo" -sha "$sha" -workflow '{{.RELEASE_PROOF}}' -events push,pull_request -ran '{{.RELEASE_JOBS}}' -also '' name="$({{.GO_TOOLS}}release "$sha")" # Every refusal above has been made, and gh's own for a file that is not there: what is # left is the release. Its files are listed, so a glob that matches nothing is seen. diff --git a/internal/tasks/tasks_test.go b/internal/tasks/tasks_test.go index 876712f..83b1f9a 100644 --- a/internal/tasks/tasks_test.go +++ b/internal/tasks/tasks_test.go @@ -160,10 +160,10 @@ func TestVersionsAsksEveryFileOfPins(t *testing.T) { } } -// A repository's parameters reach release: its gate's workflow and jobs are what proven is -// asked, and its files are on the release - of main's head, or of the commit named. -func TestReleaseIsOfTheRepositorysGateAndFiles(t *testing.T) { - r := newRepository(t, map[string]string{"Taskfile.yml": including("GATE_WORKFLOW: pages.yml, GATE_JOBS: 'Gate,Site', RELEASE_FILES: _output/a.tar.gz _output/checksums.txt", "")}) +// What a repository states of its release reaches it: its proof's workflow and jobs are what +// proven is asked, and its files are on the release - of main's head, or of the commit named. +func TestReleaseIsOfTheRepositorysProofAndFiles(t *testing.T) { + r := newRepository(t, map[string]string{"Taskfile.yml": including("RELEASE: {map: {proof: pages.yml, jobs: 'Gate,Site', files: _output/a.tar.gz _output/checksums.txt}}", "")}) asked := "proven release -repo o/r -sha 0123abc -workflow pages.yml -events push,pull_request -ran Gate,Site -also " r.ran([]string{ "git fetch --quiet --tags origin main", "gh auth token", "git rev-parse --verify origin/main^{commit}", @@ -190,7 +190,7 @@ func TestReleaseIsOfTheRepositorysGateAndFiles(t *testing.T) { // asked of proven and named, the files a release carries are listed, and gh creates nothing. A // commit proven refuses is refused dry too, and so is a file that is not there. func TestADryReleaseRefusesWhatAReleaseWouldAndReleasesNothing(t *testing.T) { - r := newRepository(t, map[string]string{"Taskfile.yml": including("GATE_WORKFLOW: ci.yml, GATE_JOBS: Gate, RELEASE_FILES: _output/*.tar.gz _output/checksums.txt", ""), + r := newRepository(t, map[string]string{"Taskfile.yml": including("RELEASE: {map: {proof: ci.yml, jobs: Gate, files: _output/*.tar.gz _output/checksums.txt}}", ""), "_output/a.tar.gz": "", "_output/checksums.txt": ""}) dry := []string{ "git fetch --quiet --tags origin main", "gh auth token", "git rev-parse --verify origin/main^{commit}", @@ -207,7 +207,7 @@ func TestADryReleaseRefusesWhatAReleaseWouldAndReleasesNothing(t *testing.T) { } } - bare := newRepository(t, map[string]string{"Taskfile.yml": including("GATE_WORKFLOW: ci.yml, GATE_JOBS: Gate", "")}) + bare := newRepository(t, map[string]string{"Taskfile.yml": including("RELEASE: {map: {proof: ci.yml, jobs: Gate}}", "")}) bare.ran(dry, "release", "RELEASE_DRY=1") if err := os.Remove(filepath.Join(r.dir, "_output/checksums.txt")); err != nil { @@ -222,12 +222,62 @@ func TestADryReleaseRefusesWhatAReleaseWouldAndReleasesNothing(t *testing.T) { } } -// A repository that names no gate does not release, and is told so before anything runs. -func TestARepositoryWithNoGateDoesNotRelease(t *testing.T) { - r := newRepository(t, map[string]string{"Taskfile.yml": including("", "")}) - if ran := r.refused("missing required variables: GATE_WORKFLOW, GATE_JOBS", "release"); len(ran) != 0 { - t.Errorf("ran %v", ran) +// A repository this task does not release cannot be made to: one that states nothing of its +// release, one that releases elsewhere, one that does not release, and one whose statement proves nothing are +// each refused with that reason before anything runs, whatever the command line and the +// environment say - the vars the task reads, the vars it had before, the map spelled as a string. +// spin-machine and spin-ami both have a ci.yml with a Gate job, and two words were a release. +func TestNoCommandLineReleasesARepositoryThatDoesNot(t *testing.T) { + said := []string{ + "RELEASE=ci.yml", "RELEASE={proof: ci.yml, jobs: Gate}", `RELEASE={"proof":"ci.yml","jobs":"Gate"}`, "RELEASE=map[jobs:Gate proof:ci.yml]", + "RELEASE_STATED=true", "RELEASE_ELSEWHERE=", "RELEASE_NONE=", "RELEASE_PROOF=ci.yml", "RELEASE_JOBS=Gate", "RELEASE_FILES=a.tar.gz", + "GATE_WORKFLOW=ci.yml", "GATE_JOBS=Gate", "proof=ci.yml", "jobs=Gate", + } + for name, tc := range map[string]struct{ vars, says string }{ + "states nothing": {"", "states no RELEASE, so nothing says how it is released"}, + "states something else": {"VERSIONS_FILES: versions.yaml", "states no RELEASE, so nothing says how it is released"}, + "states a word": {"RELEASE: ci.yml", "states no RELEASE, so nothing says how it is released"}, + "releases elsewhere": {"RELEASE: {map: {elsewhere: release.yml}}", "this repository releases, but not with this task: release.yml does"}, + "does not release": {"RELEASE: {map: {none: its workflow publishes another's}}", "this repository does not release. Its Taskfile says why (RELEASE's none): its workflow publishes another's"}, + "elsewhere, and a proof": {"RELEASE: {map: {proof: ci.yml, jobs: Gate, elsewhere: release.yml}}", "this repository releases, but not with this task: release.yml does"}, + "none, and a proof": {"RELEASE: {map: {proof: ci.yml, jobs: Gate, none: nothing releases it}}", "this repository does not release."}, + "names a proof and no jobs": {"RELEASE: {map: {proof: ci.yml}}", "RELEASE names no proof and jobs"}, + "names jobs and no proof": {"RELEASE: {map: {jobs: Gate}}", "RELEASE names no proof and jobs"}, + "names files and nothing else": {"RELEASE: {map: {files: a.tar.gz}}", "RELEASE names no proof and jobs"}, + } { + t.Run(name, func(t *testing.T) { + r := newRepository(t, map[string]string{"Taskfile.yml": including(tc.vars, "")}) + lines := [][]string{{"release"}, {"release", "RELEASE_DRY=1"}, append([]string{"release"}, said...), append([]string{"release", "RELEASE_DRY=1"}, said...)} + for _, one := range said { + lines = append(lines, []string{"release", one}) + } + for _, args := range lines { + if ran := r.refused(tc.says, args...); len(ran) != 0 { + t.Errorf("task %v ran %v", args, ran) + } + } + r.env = append(r.env, said...) + if ran := r.refused(tc.says, "release"); len(ran) != 0 { + t.Errorf("with %v in the environment, task release ran %v", said, ran) + } + }) + } +} + +// What a repository states is what is asked, whatever the command line and the environment say +// beside it: another proof, other jobs, more files. +func TestNoCommandLineChangesWhatARepositoryStatesOfItsRelease(t *testing.T) { + r := newRepository(t, map[string]string{"Taskfile.yml": including("RELEASE: {map: {proof: pages.yml, jobs: Site}}", "")}) + stated := []string{ + "git fetch --quiet --tags origin main", "gh auth token", "git rev-parse --verify origin/main^{commit}", + "gh repo view --json nameWithOwner --jq .nameWithOwner", + "proven release -repo o/r -sha 0123abc -workflow pages.yml -events push,pull_request -ran Site -also ", "release 0123abc", + "gh release create v20261122.01 --repo o/r --target 0123abc --title v20261122.01 --latest --generate-notes", } + said := []string{"RELEASE=ci.yml", "RELEASE_PROOF=ci.yml", "RELEASE_JOBS=Gate", "RELEASE_FILES=a.tar.gz", "RELEASE_ELSEWHERE=x", "RELEASE_NONE=x", "RELEASE_STATED=false"} + r.ran(stated, append([]string{"release"}, said...)...) + r.env = append(r.env, said...) + r.ran(stated, "release") } // A repository that defines a common name itself is refused by Task, whatever task is asked for: diff --git a/site/src/content/docs/start.md b/site/src/content/docs/start.md index 3dedd11..3df6b7f 100644 --- a/site/src/content/docs/start.md +++ b/site/src/content/docs/start.md @@ -46,11 +46,13 @@ move it as any dependency, and `go get github.com/spin-stack/go-tools@latest` ta ```yaml title="Taskfile.yml" includes: - common: {taskfile: '{{.GO_TOOLS_TASKS}}', flatten: true, vars: {GATE_WORKFLOW: ci.yml, GATE_JOBS: Gate}} + common: {taskfile: '{{.GO_TOOLS_TASKS}}', flatten: true} ``` gives the repository `versions`, `bump`, `release`, `lint:workflows` and `consumers` as every -other has them. [The common tasks](../tasks/) says what each does and what the vars are. +other has them. [The common tasks](../tasks/) says what each does, and what a repository states +in the include's `vars`: among them [how it is released](../tasks/#releasing), without which +`release` refuses. ## Run them where developers already run checks diff --git a/site/src/content/docs/tasks.md b/site/src/content/docs/tasks.md index 3822211..ea7c0c7 100644 --- a/site/src/content/docs/tasks.md +++ b/site/src/content/docs/tasks.md @@ -19,10 +19,9 @@ includes: common: taskfile: '{{.GO_TOOLS_TASKS}}' flatten: true - vars: {GATE_WORKFLOW: ci.yml, GATE_JOBS: Gate} ``` -That is all a repository writes. `flatten` keeps the names as they are - `go tool task versions`, +That is all a repository writes, unless [this task cuts its releases](#releasing). `flatten` keeps the names as they are - `go tool task versions`, not `common:versions` - and makes a second definition an error: a repository that writes its own `versions` task is refused by Task for every task it is asked (`Found multiple tasks (versions)`), so a name has one meaning everywhere. Nothing is fetched when a task runs: the file is in the @@ -72,7 +71,7 @@ gate says it once `go.mod` has moved. |---|---| | `versions` | says which pins are behind their upstream, in every file of pins; exits 1 when any is | | `bump NAME= [TO=] [FILE=]` | pins one entry at a version, the newest by default | -| `release [SHA=] [RELEASE_DRY=1]` | releases main's head as the next `v.`: asks [`proven`](../proven/) that the gate passed on the commit, names it with [`release`](../release/), and publishes it with `gh`, which tags it | +| `release [SHA=] [RELEASE_DRY=1]` | in a repository whose include [says this task releases it](#releasing), releases main's head as the next `v.`: asks [`proven`](../proven/) that the proof passed on the commit, names it with [`release`](../release/), and publishes it with `gh`, which tags it | | `lint:workflows` | `actionlint` at the version `versions.yaml` pins (an `actionlint` entry of kind `module`), and a failure for an action used by a tag rather than a commit | | `consumers` | the [`consumers`](../consumers/) report, for a repository with a `consumers.toml` | @@ -82,8 +81,7 @@ Only what differs, as the include's `vars`: | var | meaning | when absent | |---|---|---| -| `GATE_WORKFLOW`, `GATE_JOBS` | the workflow whose pass proves a commit, and the jobs that pass must have run (by the start of their name, comma-separated) | the repository does not release: `task release` is refused | -| `RELEASE_FILES` | files, or globs of them, a release carries | a release is its tag and its notes | +| `RELEASE` | how the repository is released, a map: see [Releasing](#releasing) | `release` is refused: nothing says how the repository is released | | `VERSIONS_FILES` | every file of pins the repository has | `versions.yaml` | | `WORKFLOWS_ALSO` | a second `.github` directory, such as an example the repository publishes | `.github` alone | | `CONSUMERS` | where the consumers table is | `consumers.toml` | @@ -101,20 +99,105 @@ version it pinned. ## Releasing +Every repository that includes the tasks has a `release` task, and in most of them it must do +nothing: spin-machine is released by a workflow of its own that builds, signs and then tags, and +spin-ami cuts no release at all. So a repository states how it is released, in the include, and +the task refuses everywhere it is not told that it is the one that releases. + +### A repository that releases with this task + +```yaml title="Taskfile.yml" +includes: + common: + taskfile: '{{.GO_TOOLS_TASKS}}' + flatten: true + vars: + RELEASE: + map: {proof: ci.yml, jobs: Gate, files: _output/release/*.tar.gz} +``` + +| key | meaning | +|---|---| +| `proof` | the workflow whose pass proves a commit can be released | +| `jobs` | the jobs that pass must have run, by the start of their display name (`Gate`, not the job's key) and comma-separated | +| `files` | files, or globs of them, the release carries; without it a release is its tag and its notes | + +Do not copy `ci.yml` and `Gate` because the repository has them. They are not "the check a pull +request needs": they are the statement that `go tool task release` publishes this repository's +releases, and most repositories have a `ci.yml` with a `Gate` job and are released some other way. + +### A repository that releases, but not with this task + +This task assumes a release is a tag and files that already exist. A release that is built from +its tag - by GoReleaser, as an image, with a signature made after the build - is not one it can +cut: it publishes as it tags, so the latest release would have no artefact until the build +finished, and none for good when the build failed. spin-machine, spin-ami, devcontainer-cli and +spin release that way, each by a workflow of its own. Such a repository says which: + +```yaml title="Taskfile.yml" + vars: + RELEASE: + map: {elsewhere: release.yml} +``` + +`elsewhere` is the file under `.github/workflows` that releases the repository. It is a key of +the Taskfile, and not a comment beside the include, so that a check can read it. The task refuses +with it: + +``` +task: release: this repository releases, but not with this task: release.yml does. Its Taskfile says so (RELEASE's elsewhere), and this task releases nothing here. +``` + +### A repository that does not release + +```yaml title="Taskfile.yml" + vars: + RELEASE: + map: {none: "its outputs are copied at a commit, which consumers.toml lists"} +``` + +`none` is a sentence for a person, and the task refuses with it. A repository that states no +`RELEASE` at all is refused too, and told to state one of the three. `elsewhere` and `none` win +over the other keys, and `proof` without `jobs` proves nothing and is refused. + +### A repository whose own `release` task means something else + +It renames its own, after what the task does: devcontainer-cli's `release` ran GoReleaser and is +`release:artifacts`. `excludes: [release]` on the include is not a way out. Task accepts it, and +`go tool task release` would then run GoReleaser in that repository and cut a release in every +other, when the one thing the include is for is that a name means the same everywhere. + +### Why a map + +Under Task 3.54.0 a var given on the command line, or set in the environment, reaches an included +task wherever the include states none of that name. Were the proof and the jobs two plain vars, a +repository that set neither would refuse only for want of them, and two words on a command line +would publish an empty release, marked latest, in a repository released by its own workflow: +spin-machine and spin-ami both have a `ci.yml` with a `Gate` job. + +The command line and the environment hold strings. `RELEASE` is a map, which no string is, and +where the include states one it wins over both. So no command line and no environment turns a +repository that states nothing, `elsewhere` or `none` into one this task releases, and none changes the +proof, the jobs or the files of one that does: `internal/tasks/tasks_test.go` runs each of those +under Task. + +### Cutting one + A release is cut by a person: `go tool task release`, with `gh` logged in. go-tools' own `release.yml` runs the same task once its binaries are built, with the run's `GH_TOKEN`. `go tool task release RELEASE_DRY=1` is the release without the release. It fetches, asks -`proven`, names the commit and lists `RELEASE_FILES`, so it refuses what a release would - a -commit the gate has not passed on, one released already, a file that is not there - and then +`proven`, names the commit and lists the files, so it refuses what a release would - a +commit the proof has not passed on, one released already, a file that is not there - and then prints the name and stops before `gh release create`: ``` RELEASE_DRY: 0123abc would be released to spin-stack/brand as v20261122.01, and is not ``` -It is how a repository that has just taken the tasks proves its `GATE_WORKFLOW` and `GATE_JOBS` -on a main that is proven and not yet released. +It is how a repository that has just taken the tasks proves its `proof` and `jobs` +on a main that is proven and not yet released. It reads `origin/main`, and says nothing about a +branch. ## Every task is listed everywhere @@ -123,7 +206,9 @@ apply there. The ones that do not apply refuse, before running anything: | task | where | it says | exit | |---|---|---|---| -| `release` | the include sets no `GATE_WORKFLOW` and `GATE_JOBS`: the repository does not release | `Task "release" cancelled because it is missing required variables: GATE_WORKFLOW, GATE_JOBS` | 206 | +| `release` | the include states no `RELEASE` | `release: this repository's include of the common tasks states no RELEASE, so nothing says how it is released and this task releases nothing. ...` | 201 | +| `release` | `RELEASE` says `elsewhere` | `release: this repository releases, but not with this task: release.yml does. ...` | 201 | +| `release` | `RELEASE` says `none` | `release: this repository does not release. Its Taskfile says why (RELEASE's none): ...` | 201 | | `consumers` | there is no `consumers.toml` | `no consumers.toml: this repository names nobody that copies from it` | 201 | | `bump` | no `NAME` was given | `Task "bump" cancelled because it is missing required variables: NAME` | 206 | @@ -137,5 +222,6 @@ apply there. The ones that do not apply refuse, before running anything: | `versions: there is no actionlint in versions.yaml`, from `lint:workflows` | the task runs `actionlint` at the repository's pin, and there is none | add the `actionlint` entry (kind `module`, source `github.com/rhysd/actionlint/cmd/actionlint`) | | `Taskfile.yml includes go-tools' tasks, and its task lint:workflows reads actionlint: versions: there is no actionlint in versions.yaml`, from the repository's tests | the same, found by the [versions gate](../versions/#the-gate) before the task is run | the same | | `versions.yaml pins actionlint, and nothing reads it`, from the repository's tests, in a repository that includes the tasks | `go.mod` requires a go-tools whose gate does not count what the common tasks read (`v0.20261122.4` or before), or the include is not one the gate reads: it is a Taskfile's `includes` entry whose `taskfile` is `'{{.GO_TOOLS_TASKS}}'` | `go get github.com/spin-stack/go-tools@latest`; never a comment that spells the read | -| `missing required variables: GATE_WORKFLOW, GATE_JOBS` (exit 206), `no consumers.toml` (exit 201) | a task that does not apply to this repository | nothing: see above | +| `release: this repository releases, but not with this task` or `release: this repository does not release` (exit 201), `no consumers.toml` (exit 201) | a task that does not apply to this repository | nothing: see above | +| `release: this repository's include of the common tasks states no RELEASE` (exit 201) | the Taskfile does not say how the repository is released. `GATE_WORKFLOW` and `GATE_JOBS`, where an include still has them, are read by nothing | state `RELEASE` in the include: [Releasing](#releasing) | | `consumers.toml: scope is no field of the table`, from `consumers` | the table has `scope = "..."`; it is `scopes`, a list | `scopes = ["@fontsource", "@fontsource-variable"]` | From fb09be25b3bc11d94cbe23b8ff435abc94f53f84 Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Sun, 22 Nov 2026 14:15:58 -0300 Subject: [PATCH 2/7] versions: check counts an entry it could not read, and fails apart for it A row whose upstream did not answer was a row with a note and no count. website asked without a token got a 404 for its private upstream and `1 behind` where there were 2 (spin-stack/website#140); spin-machine's qemu, pinned at 11.2.0-rc0, got `strconv.Atoi: parsing "0-rc0"` and `8 behind` with no word of it (spin-stack/machine#529). A missing token read as nothing more to bump. upstream.Status has Unread: the upstream did not answer, or answered what the pin cannot be ordered against. Behind says nothing of such a row. check marks it `not read:`, counts it apart, says how many rows the count of what is behind is of, and exits 2 where a row behind exits 1, as diff does for a file it could not read. The versions task keeps the worst status of its files, so a later file that is only behind does not hide one that was not read. A kernel series that is over was read, and so was an entry that follows another. A pin with a -suffix after its numbers is now ordered by the tags track, not refused. A release tag is numbers alone, so the comparison this package has is of numbers, and what it can say of 11.2.0-rc0 is that 11.2.0 is newer and 11.1.2 is not. A pin that starts with no number is said to be one the track cannot order, which is a row not read. Part of #135 Co-Authored-By: Claude Fable 5.2 --- cmd/versions/main.go | 43 +++++++++++--- cmd/versions/main_test.go | 46 +++++++++++++++ internal/tasks/tasks.yml | 7 ++- internal/tasks/tasks_test.go | 22 ++++--- site/src/content/docs/versions.md | 21 ++++++- site/src/content/docs/versions/reference.md | 2 +- versions/upstream/check_test.go | 63 ++++++++++++++------- versions/upstream/upstream.go | 43 +++++++++++--- versions/upstream/upstream_test.go | 26 +++++++-- 9 files changed, 219 insertions(+), 54 deletions(-) diff --git a/cmd/versions/main.go b/cmd/versions/main.go index d26a44f..1ad6f29 100644 --- a/cmd/versions/main.go +++ b/cmd/versions/main.go @@ -35,10 +35,23 @@ func main() { msg = "versions: " + msg } fmt.Fprintln(os.Stderr, msg) - os.Exit(1) + os.Exit(status(err)) } } +// unread is check's failure when it could not read a row: another exit status than a row behind, +// so that what a script reads as "nothing to bump" is never a file it was not shown. +type unread struct{ error } + +// status is the exit status of a failure: 2 for rows check could not read, 1 for any other, a +// row behind among them - as diff answers 1 for a difference and 2 for a file it could not read. +func status(err error) int { + if errors.As(err, &unread{}) { + return 2 + } + return 1 +} + const usage = `versions - what versions.yaml pins Usage: @@ -49,7 +62,9 @@ Usage: versions url a download's URL, at its version versions fetch a download in dir, only as the bytes it pins, and its path versions newer when it is newer than the pin, nothing when not - versions check what is behind its upstream; exits 1 when anything is + versions check what is behind its upstream; exits 1 when anything is, + and 2 when an entry could not be read, which may be + behind versions bump [version] pin an entry at a version, the newest by default, and every entry tracked with it at the same versions refresh ... bump each to its newest, a commit each, and say what moved @@ -115,7 +130,7 @@ func run(ctx context.Context, argv []string) error { if len(names) != 0 { return errors.New("check: takes no names; it checks every entry") } - return check(ctx, v) + return check(os.Stdout, upstream.Check(ctx, v)) case "bump": return bump(ctx, v, *file, names) case "refresh": @@ -238,13 +253,19 @@ func pins(v *versions.Versions, names []string, prefix string) ([]string, error) return out, nil } -func check(ctx context.Context, v *versions.Versions) error { - tw := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0) +// check prints where each entry stands and fails when one is behind, or could not be read. The +// two are counted apart and fail apart: a row not read - a private upstream asked without a token +// answers 404 - may be behind, so a count of what is behind says "of those read" beside it. +func check(w io.Writer, rows []upstream.Status) error { + tw := tabwriter.NewWriter(w, 0, 0, 2, ' ', 0) _, _ = fmt.Fprintln(tw, "NAME\tPINNED\tNEWEST\t") - behind := 0 - for _, st := range upstream.Check(ctx, v) { + behind, unreadRows := 0, 0 + for _, st := range rows { mark := "" - if st.Behind { + switch { + case st.Unread: + mark, unreadRows = "not read:", unreadRows+1 + case st.Behind: mark, behind = "behind", behind+1 } _, _ = fmt.Fprintf(tw, "%s\t%s\t%s\t%s %s\n", st.Entry.Name, st.Entry.Version, st.Newest, mark, st.Note) @@ -252,7 +273,11 @@ func check(ctx context.Context, v *versions.Versions) error { if err := tw.Flush(); err != nil { return err } - if behind > 0 { + switch { + case unreadRows > 0: + return unread{fmt.Errorf("%d not read, and %d behind of the %d that were: a row not read may be behind, and says why "+ + "(GITHUB_TOKEN or GH_TOKEN reads a private repository, and more than sixty requests an hour)", unreadRows, behind, len(rows)-unreadRows)} + case behind > 0: return fmt.Errorf("%d behind; versions bump moves one", behind) } return nil diff --git a/cmd/versions/main_test.go b/cmd/versions/main_test.go index ce862eb..271b26d 100644 --- a/cmd/versions/main_test.go +++ b/cmd/versions/main_test.go @@ -9,6 +9,7 @@ import ( "net/http/httptest" "os" "path/filepath" + "strings" "testing" "time" @@ -206,3 +207,48 @@ func TestABumpSaysEveryEntryItMoved(t *testing.T) { err = run(t.Context(), []string{"bump", "-file", file, "snapshot", today, "x"}) assert.ErrorContains(t, err, "bump: [version]") } + +// check counts what is behind and what it could not read apart, and fails apart for them: a row +// not read may be behind, so its failure is another exit status and its message says how many +// rows the count of what is behind is of. Each file here is answered without a network: an entry +// with another in the file, and a track check does not know, which is a row it cannot read. +func TestCheckCountsARowItCouldNotReadAndFailsApartForIt(t *testing.T) { + const lead = "- name: lead\n kind: date\n version: v2\n track: branch\n" + const behind = "- name: behind\n kind: date\n version: v1\n track: with lead\n" + const unknown = "- name: unknown\n kind: date\n version: v1\n track: rumour\n" + for name, tc := range map[string]struct { + file string + rows []string + says string + status int + }{ + "nothing behind": {file: lead, rows: []string{"lead v2 v2"}}, //nolint:dupword // a row: its pin, then its newest + "one behind": {file: lead + behind, rows: []string{"behind v1 v2 behind"}, + says: "1 behind; versions bump moves one", status: 1}, + "one not read": {file: lead + unknown, rows: []string{"unknown v1 not read: versions: unknown tracks \"rumour\", which check does not know"}, + says: "1 not read, and 0 behind of the 1 that were: a row not read may be behind", status: 2}, + "one behind and two not read": {file: lead + behind + unknown + "- name: other\n kind: date\n version: v1\n track: gossip\n", + says: "2 not read, and 1 behind of the 2 that were: a row not read may be behind", status: 2}, + } { + t.Run(name, func(t *testing.T) { + file := filepath.Join(t.TempDir(), "versions.yaml") + require.NoError(t, os.WriteFile(file, []byte(tc.file), 0o600)) + var err error + out := stdout(t, func() { err = run(t.Context(), []string{"check", "-file", file}) }) + // A row's columns, whatever the widest entry made their width. + var rows []string + for line := range strings.Lines(out) { + rows = append(rows, strings.Join(strings.Fields(line), " ")) + } + for _, row := range tc.rows { + assert.Contains(t, rows, row) + } + if tc.says == "" { + require.NoError(t, err) + return + } + require.ErrorContains(t, err, tc.says) + assert.Equal(t, tc.status, status(err)) + }) + } +} diff --git a/internal/tasks/tasks.yml b/internal/tasks/tasks.yml index 6b93d16..af21d2e 100644 --- a/internal/tasks/tasks.yml +++ b/internal/tasks/tasks.yml @@ -32,13 +32,14 @@ version: '3' tasks: versions: - desc: Say which pins of versions.yaml (and of every file in VERSIONS_FILES) are behind their upstream; exits 1 when any is. + desc: Say which pins of versions.yaml (and of every file in VERSIONS_FILES) are behind their upstream. It fails when any is, and when an entry could not be read, which may be behind; the last line of a file's rows says which. cmds: - # Every file, whichever is behind. + # Every file, whichever is behind. The status is the worst any file had: 2, an entry that + # could not be read, is not hidden by a later file's 1 or 0. - | status=0 for file in {{.VERSIONS_FILES | default "versions.yaml"}}; do - {{.GO_TOOLS}}versions check -file "$file" || status=1 + {{.GO_TOOLS}}versions check -file "$file" || { s=$?; [ "$s" -le "$status" ] || status=$s; } done exit $status diff --git a/internal/tasks/tasks_test.go b/internal/tasks/tasks_test.go index 83b1f9a..f63cab8 100644 --- a/internal/tasks/tasks_test.go +++ b/internal/tasks/tasks_test.go @@ -23,12 +23,13 @@ func taskExe(t *testing.T) string { // stubs is a directory of the commands tasks.yml calls, each a program that writes its name and // arguments as a line of log and answers what a task reads from it. `versions check` fails for -// a file named behind.yaml, and `proven` when REFUSE is set. +// a file named behind.yaml, and as it does for an entry it could not read for one named +// unread.yaml; `proven` fails when REFUSE is set. func stubs(t *testing.T) (bin, log string) { t.Helper() bin, log = t.TempDir(), filepath.Join(t.TempDir(), "log") for name, answer := range map[string]string{ - "versions": `case "$*" in "version actionlint") echo v1.7.12 ;; *behind.yaml) exit 1 ;; esac`, + "versions": `case "$*" in "version actionlint") echo v1.7.12 ;; *behind.yaml) exit 1 ;; *unread.yaml) exit 2 ;; esac`, "proven": `[ -z "${REFUSE:-}" ]`, "release": `echo v20261122.01`, "consumers": ``, @@ -151,12 +152,19 @@ func TestARepositoryThatIncludesTheTasksHasThem(t *testing.T) { } } -// Every file of pins is asked, whichever is behind, and one behind fails the task. +// Every file of pins is asked, whichever is behind, and one behind fails the task. A file with +// an entry that could not be read fails it as that, wherever it is among files that are behind. func TestVersionsAsksEveryFileOfPins(t *testing.T) { - r := newRepository(t, map[string]string{"Taskfile.yml": including("VERSIONS_FILES: versions.yaml behind.yaml cmd/sfw/versions.yaml", "")}) - ran := r.refused("exit status 1", "versions") - if want := "versions check -file versions.yaml\nversions check -file behind.yaml\nversions check -file cmd/sfw/versions.yaml"; strings.Join(ran, "\n") != want { - t.Errorf("ran:\n%s\nwant:\n%s", strings.Join(ran, "\n"), want) + for files, status := range map[string]string{ + "versions.yaml behind.yaml cmd/sfw/versions.yaml": "exit status 1", + "unread.yaml behind.yaml versions.yaml": "exit status 2", + "behind.yaml unread.yaml": "exit status 2", + } { + r := newRepository(t, map[string]string{"Taskfile.yml": including("VERSIONS_FILES: "+files, "")}) + ran := r.refused(status, "versions") + if want := "versions check -file " + strings.ReplaceAll(files, " ", "\nversions check -file "); strings.Join(ran, "\n") != want { + t.Errorf("ran:\n%s\nwant:\n%s", strings.Join(ran, "\n"), want) + } } } diff --git a/site/src/content/docs/versions.md b/site/src/content/docs/versions.md index a512ecf..186c7f1 100644 --- a/site/src/content/docs/versions.md +++ b/site/src/content/docs/versions.md @@ -113,7 +113,7 @@ that arrived whole: a file that is not the pin is refused, not tried again. ## Keeping up ```sh -go tool versions check # what is behind; exits 1 when anything is +go tool versions check # what is behind; exits 1 when anything is, 2 when an entry could not be read go tool versions bump kernel # to the newest the track finds go tool versions bump kernel 7.2.9 # or to a version you name ``` @@ -124,6 +124,25 @@ for the digest. It builds nothing, and the entry's `note` says what to run befor `GITHUB_TOKEN`, when set, is sent to api.github.com, which answers only sixty unauthenticated requests an hour. +### An entry check could not read + +An upstream that does not answer is not an entry that is up to date. A private repository asked +without a token answers 404, a registry can be down, and a version can be one its track cannot +order. `check` marks such a row `not read:` with what the upstream said, counts it apart, and +exits 2 rather than 1: + +``` +NAME PINNED NEWEST +spin v20261114.01 not read: versions: https://api.github.com/repos/spin-stack/spin/releases/latest answered 404 Not Found +brand main main behind main is now c6d8cb1f... +versions: 1 not read, and 1 behind of the 1 that were: a row not read may be behind, and says why (GITHUB_TOKEN or GH_TOKEN reads a private repository, and more than sixty requests an hour) +``` + +Exit 1 is "something is behind, and every entry was read"; exit 2 is "what is behind is not all +known". Exit 0 is never a file `check` was not shown whole. A `kernel` whose series kernel.org no +longer lists was read - the answer is that the pin stays - and so was an entry that `follows` +another. + ## A refresh, on a schedule `refresh` is the bump a workflow runs: each entry named moved to its newest, one commit each, and diff --git a/site/src/content/docs/versions/reference.md b/site/src/content/docs/versions/reference.md index 1701b1b..753ae4d 100644 --- a/site/src/content/docs/versions/reference.md +++ b/site/src/content/docs/versions/reference.md @@ -34,7 +34,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 ``; 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 | +| `tags ` | the highest release-numbered tag of a git repository; for a download, the highest whose file is published. A tag with anything after its numbers (`v11.2.0-rc0`) is no release. A download pinned at one is ordered by its numbers, before the release of the same numbers: `11.2.0-rc0` is behind once `11.2.0` is published, and not behind `11.1.2`. A pin that starts with no number is not ordered, and `check` says it could not read the entry | | `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`) | | `kernel` | the newest release of the pinned series; moving to another series is naming it (`versions bump kernel 7.4.1`), and a series kernel.org no longer lists is reported and the pin stays | diff --git a/versions/upstream/check_test.go b/versions/upstream/check_test.go index 038810a..b799a51 100644 --- a/versions/upstream/check_test.go +++ b/versions/upstream/check_test.go @@ -159,7 +159,8 @@ func TestTheNewestIsWhatTheTrackFinds(t *testing.T) { } // Check says where each entry stands: at its newest, behind it, behind at the same version because -// the name points elsewhere now, or a note saying why it cannot tell. +// the name points elsewhere now, or unread with a note saying why it cannot tell - and an unread +// entry is never called behind or not, since it may be either. func TestCheckSaysWhereEachEntryStands(t *testing.T) { r := newGitRepo(t) srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { @@ -201,29 +202,51 @@ func TestCheckSaysWhereEachEntryStands(t *testing.T) { got := Check(t.Context(), &versions.Versions{Entries: []versions.Entry{git, moved, gone, image, download, current, atHead, unread, gitByCommit, follows, unknown, lead, withBehind, withAt}}) want := []struct { - newest string - behind bool - note string + newest string + behind, unread bool + note string }{ - {"master", false, ""}, - {"master", true, "master is now " + r.head}, - {"master", false, "ls-remote"}, - {"1.27", true, "1.27 is now " + now}, - {"v1.2.0", true, ""}, - {"v1.2.0", false, ""}, - {r.head, false, ""}, - {r.head, true, "404"}, - {r.head, true, ""}, - {"", false, "follows spin: spin says"}, - {"", false, "which check does not know"}, - {"v2", false, ""}, - {"2", true, ""}, - {"v2", false, ""}, + {"master", false, false, ""}, + {"master", true, false, "master is now " + r.head}, + {"master", false, true, "ls-remote"}, + {"1.27", true, false, "1.27 is now " + now}, + {"v1.2.0", true, false, ""}, + {"v1.2.0", false, false, ""}, + {r.head, false, false, ""}, + {r.head, false, true, "404"}, + {r.head, true, false, ""}, + {"", false, false, "follows spin: spin says"}, + {"", false, true, "which check does not know"}, + {"v2", false, false, ""}, + {"2", true, false, ""}, + {"v2", false, false, ""}, } for i, w := range want { st := got[i] - if st.Newest != w.newest || st.Behind != w.behind || !strings.Contains(st.Note, w.note) || (w.note == "" && st.Note != "") { - t.Errorf("%s: %+v, want newest %q behind %v note %q", st.Entry.Name, st, w.newest, w.behind, w.note) + if st.Newest != w.newest || st.Behind != w.behind || st.Unread != w.unread || !strings.Contains(st.Note, w.note) || (w.note == "" && st.Note != "") { + t.Errorf("%s: %+v, want newest %q behind %v unread %v note %q", st.Entry.Name, st, w.newest, w.behind, w.unread, w.note) } } } + +// A kernel whose series kernel.org no longer lists was read: the answer is that the pin stays, and +// a kernel.org that answers nothing is an entry not read. +func TestAKernelSeriesThatIsOverWasRead(t *testing.T) { + kernel := &versions.Versions{Entries: []versions.Entry{{Name: "kernel", Kind: versions.Download, Version: "7.2.8", Track: "kernel"}}} + serve(t, map[string]string{"https://www.kernel.org/releases.json": `{"releases": [{"version": "7.3.1", "moniker": "stable"}]}`}) + if st := Check(t.Context(), kernel)[0]; st.Unread || st.Behind || !strings.Contains(st.Note, "the series is over") { + t.Errorf("a series that is over: %+v", st) + } + serve(t, nil) + if st := Check(t.Context(), kernel)[0]; !st.Unread || st.Behind || !strings.Contains(st.Note, "kernel.org/releases.json answered") { + t.Errorf("a kernel.org that answers 404: %+v", st) + } +} + +// An image whose registry does not answer for its digest is unread, not at its newest. +func TestAnImageWhoseRegistryDoesNotAnswerIsUnread(t *testing.T) { + image := versions.Entry{Name: "i", Kind: versions.Image, Source: registry(t) + "/nothing", Version: "1.27", Pin: "sha256:old", Track: "digest"} + if st := Check(t.Context(), &versions.Versions{Entries: []versions.Entry{image}})[0]; !st.Unread || st.Behind || st.Note == "" { + t.Errorf("an image the registry has not: %+v", st) + } +} diff --git a/versions/upstream/upstream.go b/versions/upstream/upstream.go index 88fd05e..3900129 100644 --- a/versions/upstream/upstream.go +++ b/versions/upstream/upstream.go @@ -481,17 +481,23 @@ func releaseTags(ctx context.Context, repo string, withV bool) ([]string, error) // A tag is not a release. QEMU tagged v11.1.2 before download.qemu.org had its tarball // (2026-09-28), so check called qemu behind and a bump to the newest failed on a 404. What a // download entry builds from is the download, so that is what is asked. +// +// A pin can be what a release tag never is: spin-machine built QEMU 11.2.0-rc0. It is ordered by +// its numbers, and the release of those numbers is newer than it, since a tag with anything after +// its numbers is no release (releaseTags). A pin that starts with no number is not ordered at all, +// and is said to be so rather than called current. func newestPublished(ctx context.Context, e versions.Entry, tags []string) (string, error) { - current, err := numbers(strings.TrimPrefix(e.Version, "v")) - if err != nil { - return "", fmt.Errorf("versions: %s's version %q: %w", e.Name, e.Version, err) + current, before, ok := numbered(e.Version) + if !ok { + return "", fmt.Errorf("versions: %s's version %q is not numbers between dots, alone or with a -suffix after them: "+ + "the tags track cannot order it against a release", e.Name, e.Version) } for _, tag := range tags { n, err := numbers(strings.TrimPrefix(tag, "v")) if err != nil { return "", fmt.Errorf("versions: %s's tag %q: %w", e.Name, tag, err) } - if slices.Compare(n, current) <= 0 { + if c := slices.Compare(n, current); c < 0 || (c == 0 && !before) { break } c := e @@ -524,6 +530,18 @@ func branchHead(ctx context.Context, repo, branch string) (string, error) { return sha, nil } +// numbered is a version as the numbers it starts with, a leading v apart, and whether a -suffix +// follows them: 11.2.0-rc0 is 11.2.0 and more, as 1.27.4-bookworm is 1.27.4 and more. ok is false +// for what starts with no number or goes on in any other way: a branch, a commit, a date and time. +func numbered(version string) (n []int, suffixed, ok bool) { + m := variant.FindStringSubmatch(version) + if m == nil || (m[1] != "" && !strings.HasPrefix(m[1], "-")) { + return nil, false, false + } + n, err := numbers(strings.TrimSuffix(strings.TrimPrefix(version, "v"), m[1])) + return n, m[1] != "", err == nil +} + // numbers is a dotted version as numbers, so 11.10 comes after 11.9. func numbers(version string) ([]int, error) { var out []int @@ -618,12 +636,18 @@ type Status struct { Newest string // Behind is a newer version, or the same one at another pin. Behind bool + // Unread is an entry check could not place: its upstream did not answer - a private repository + // asked without a token is a 404 - or answered with what cannot be ordered against the pin. + // Note says which, and Behind says nothing: the entry may be behind. + Unread bool Note string } // Check is where each entry stands against its upstream. An image tracked by its digest, or a // commit tracked by its branch, is behind when the name now points at something else; a download -// only when its version moves, since its pin is what that version was published as. +// only when its version moves, since its pin is what that version was published as. An entry +// whose upstream could not be read is Unread, never "not behind": a caller that counts only +// Behind would call a file with no token up to date. func Check(ctx context.Context, v *versions.Versions) []Status { var out []Status for _, e := range v.Entries { @@ -632,8 +656,11 @@ func Check(ctx context.Context, v *versions.Versions) []Status { switch { case errors.Is(err, errFollows): st.Note = "follows " + strings.TrimPrefix(e.Track, "follows ") + ": " + e.Note - case err != nil: + case errors.Is(err, errSeriesOver): + // kernel.org answered, and what it said is that the pin stays. st.Note = err.Error() + case err != nil: + st.Unread, st.Note = true, err.Error() default: st.Newest = latest st.Behind = latest != e.Version @@ -643,7 +670,7 @@ func Check(ctx context.Context, v *versions.Versions) []Status { pin, err := resolve(ctx, e, latest) switch { case err != nil: - st.Note = err.Error() + st.Behind, st.Unread, st.Note = false, true, err.Error() case pin == e.Pin: st.Behind, st.Note = false, "the branch moved; the file did not" } @@ -651,7 +678,7 @@ func Check(ctx context.Context, v *versions.Versions) []Status { if !st.Behind && (e.Kind == versions.Image || e.Kind == versions.Git) { pin, err := resolve(ctx, e, latest) if err != nil { - st.Note = err.Error() + st.Unread, st.Note = true, err.Error() } else if pin != e.Pin { st.Behind, st.Note = true, e.Version+" is now "+pin } diff --git a/versions/upstream/upstream_test.go b/versions/upstream/upstream_test.go index 9cf1cba..2082444 100644 --- a/versions/upstream/upstream_test.go +++ b/versions/upstream/upstream_test.go @@ -104,26 +104,42 @@ func TestTheNewestTagIsTheHighestRelease(t *testing.T) { // was published, and a bump to it failed on a 404. func TestTheNewestDownloadIsTheNewestPublished(t *testing.T) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path != "/qemu-11.1.1.tar.xz" && r.URL.Path != "/qemu-11.0.0.tar.xz" { + if r.URL.Path != "/qemu-11.1.1.tar.xz" && r.URL.Path != "/qemu-11.0.0.tar.xz" && r.URL.Path != "/qemu-v11.1.1.tar.xz" { http.NotFound(w, r) } })) defer srv.Close() e := versions.Entry{Name: "qemu", Kind: versions.Download, Source: srv.URL + "/qemu-{version}.tar.xz", Version: "11.0.0"} for _, tc := range []struct { + pin string tags []string want string }{ - {[]string{"11.1.2", "11.1.1", "11.0.0"}, "11.1.1"}, - {[]string{"11.1.2", "11.0.0"}, "11.0.0"}, - {[]string{"11.0.0", "10.2.0"}, "11.0.0"}, + {"11.0.0", []string{"11.1.2", "11.1.1", "11.0.0"}, "11.1.1"}, + {"11.0.0", []string{"11.1.2", "11.0.0"}, "11.0.0"}, + {"11.0.0", []string{"11.0.0", "10.2.0"}, "11.0.0"}, + // A release candidate is before the release of its numbers and after every release before + // it: spin-machine pinned 11.2.0-rc0, and check could not read the row. + {"11.1.1-rc0", []string{"11.1.2", "11.1.1", "11.0.0"}, "11.1.1"}, + {"11.1.2-rc0", []string{"11.1.2", "11.1.1", "11.0.0"}, "11.1.2-rc0"}, + {"11.2.0-rc0", []string{"11.1.2", "11.1.1", "11.0.0"}, "11.2.0-rc0"}, + {"v11.0.0-rc3", []string{"v11.1.2", "v11.1.1", "v11.0.0"}, "v11.1.1"}, } { + e.Version = tc.pin got, err := newestPublished(t.Context(), e, tc.tags) if err != nil { t.Fatal(err) } if got != tc.want { - t.Errorf("tags %v: newest %q, want %q", tc.tags, got, tc.want) + t.Errorf("%s, tags %v: newest %q, want %q", tc.pin, tc.tags, got, tc.want) + } + } + // What starts with no number, or goes on other than with a -suffix, is not ordered: said, and + // never called current. The served file is not asked. + for _, pin := range []string{"master", "0123abc", "11.1.1rc0", "11.1.x", "20261122T000000Z", "99999999999999999999.1"} { + e.Version = pin + if got, err := newestPublished(t.Context(), e, []string{"11.1.1"}); err == nil || !strings.Contains(err.Error(), "cannot order it") { + t.Errorf("%s: newest %q, %v; want refused as a version the track cannot order", pin, got, err) } } } From e75a7eb218434a42eb5c3e1a929ce60991142301 Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Sun, 22 Nov 2026 14:17:34 -0300 Subject: [PATCH 3/7] task: versions and bump read upstreams with gh's token, as release does release exported gh's token when none was set; versions and bump did not. A repository with a private upstream - website pins spin - had to be run as `GITHUB_TOKEN=$(gh auth token) go tool task versions`, and without it the private row was a 404 (spin-stack/website#140). Both tasks now take gh's token when neither GITHUB_TOKEN nor GH_TOKEN is set. A workflow's token is left as it is and gh is not asked. Where gh is logged out or not there the task runs without a token, which release cannot: check marks what it could not read and fails for it. Part of #135 Co-Authored-By: Claude Fable 5.2 --- internal/tasks/tasks.yml | 12 +++++++- internal/tasks/tasks_test.go | 48 +++++++++++++++++++++++++------ site/src/content/docs/versions.md | 7 +++-- 3 files changed, 55 insertions(+), 12 deletions(-) diff --git a/internal/tasks/tasks.yml b/internal/tasks/tasks.yml index af21d2e..7746e93 100644 --- a/internal/tasks/tasks.yml +++ b/internal/tasks/tasks.yml @@ -36,7 +36,14 @@ tasks: cmds: # Every file, whichever is behind. The status is the worst any file had: 2, an entry that # could not be read, is not hidden by a later file's 1 or 0. + # + # The token is a person's, as release's is: GitHub answers sixty requests an hour without + # one, and a private repository none - an entry check then cannot read. A workflow sets + # GITHUB_TOKEN or GH_TOKEN and the line does nothing; a person has gh logged in, and the + # token is gh's. With neither - no gh, or not logged in - the task goes on without, and + # says of each entry it could not read that it could not. - | + if [ -z "${GITHUB_TOKEN:-}${GH_TOKEN:-}" ] && token="$(gh auth token 2>/dev/null)"; then export GH_TOKEN="$token"; fi status=0 for file in {{.VERSIONS_FILES | default "versions.yaml"}}; do {{.GO_TOOLS}}versions check -file "$file" || { s=$?; [ "$s" -le "$status" ] || status=$s; } @@ -48,7 +55,10 @@ tasks: requires: vars: [NAME] cmds: - - '{{.GO_TOOLS}}versions bump -file {{.FILE | default "versions.yaml"}} {{.NAME}} {{.TO}}' + # A bump reads the upstreams check reads, with the token check has. + - | + if [ -z "${GITHUB_TOKEN:-}${GH_TOKEN:-}" ] && token="$(gh auth token 2>/dev/null)"; then export GH_TOKEN="$token"; fi + {{.GO_TOOLS}}versions bump -file {{.FILE | default "versions.yaml"}} {{.NAME}} {{.TO}} release: desc: Release main's head (or SHA) as the next v. of today, in UTC, with RELEASE's files - in a repository whose include states RELEASE's proof and jobs, and refused in every other. A person runs it, with gh logged in, or a workflow with GH_TOKEN; it refuses a commit the jobs of the proof workflow have not passed on, and one released already. RELEASE_DRY=1 refuses what a release would and prints the name, and releases nothing. diff --git a/internal/tasks/tasks_test.go b/internal/tasks/tasks_test.go index f63cab8..5a19af8 100644 --- a/internal/tasks/tasks_test.go +++ b/internal/tasks/tasks_test.go @@ -24,18 +24,19 @@ func taskExe(t *testing.T) string { // stubs is a directory of the commands tasks.yml calls, each a program that writes its name and // arguments as a line of log and answers what a task reads from it. `versions check` fails for // a file named behind.yaml, and as it does for an entry it could not read for one named -// unread.yaml; `proven` fails when REFUSE is set. +// unread.yaml, and with SHOW_TOKEN set `versions` also logs the tokens it was run with; `proven` +// fails when REFUSE is set, and `gh auth token` when LOGGED_OUT is. func stubs(t *testing.T) (bin, log string) { t.Helper() bin, log = t.TempDir(), filepath.Join(t.TempDir(), "log") for name, answer := range map[string]string{ - "versions": `case "$*" in "version actionlint") echo v1.7.12 ;; *behind.yaml) exit 1 ;; *unread.yaml) exit 2 ;; esac`, + "versions": `[ -z "${SHOW_TOKEN:-}" ] || echo "GITHUB_TOKEN=${GITHUB_TOKEN:-} GH_TOKEN=${GH_TOKEN:-}" >> '` + log + `'; case "$*" in "version actionlint") echo v1.7.12 ;; *behind.yaml) exit 1 ;; *unread.yaml) exit 2 ;; esac`, "proven": `[ -z "${REFUSE:-}" ]`, "release": `echo v20261122.01`, "consumers": ``, "go": ``, "git": `case "$1" in rev-parse) echo 0123abc ;; esac`, - "gh": `case "$1" in auth) echo a-token ;; repo) echo o/r ;; esac`, + "gh": `case "$1" in auth) [ -z "${LOGGED_OUT:-}" ] && echo a-token ;; repo) echo o/r ;; esac`, } { script := "#!/bin/sh\necho \"" + name + " $*\" >> '" + log + "'\n" + answer + "\n" if err := os.WriteFile(filepath.Join(bin, name), []byte(script), 0o700); err != nil { //nolint:gosec // a program the test runs @@ -142,11 +143,11 @@ func TestARepositoryThatIncludesTheTasksHasThem(t *testing.T) { t.Errorf("%d tasks, and the repository wrote none: %v", len(listed.Tasks), has) } - if out, ok, ran := r.task("internal/x", "versions"); !ok || len(ran) != 1 || ran[0] != "versions check -file versions.yaml" { + if out, ok, ran := r.task("internal/x", "versions"); !ok || strings.Join(ran, "\n") != "gh auth token\nversions check -file versions.yaml" { t.Errorf("from a directory of the repository, task versions passed=%t and ran %v\n%s", ok, ran, out) } - r.ran([]string{"versions bump -file versions.yaml golangci-lint"}, "bump", "NAME=golangci-lint") - r.ran([]string{"versions bump -file cmd/sfw/versions.yaml socket v1.2.0"}, "bump", "NAME=socket", "TO=v1.2.0", "FILE=cmd/sfw/versions.yaml") + r.ran([]string{"gh auth token", "versions bump -file versions.yaml golangci-lint"}, "bump", "NAME=golangci-lint") + r.ran([]string{"gh auth token", "versions bump -file cmd/sfw/versions.yaml socket v1.2.0"}, "bump", "NAME=socket", "TO=v1.2.0", "FILE=cmd/sfw/versions.yaml") if ran := r.refused("missing required variables: NAME", "bump"); len(ran) != 0 { t.Errorf("a bump of nothing ran %v", ran) } @@ -162,12 +163,41 @@ func TestVersionsAsksEveryFileOfPins(t *testing.T) { } { r := newRepository(t, map[string]string{"Taskfile.yml": including("VERSIONS_FILES: "+files, "")}) ran := r.refused(status, "versions") - if want := "versions check -file " + strings.ReplaceAll(files, " ", "\nversions check -file "); strings.Join(ran, "\n") != want { + if want := "gh auth token\nversions check -file " + strings.ReplaceAll(files, " ", "\nversions check -file "); strings.Join(ran, "\n") != want { t.Errorf("ran:\n%s\nwant:\n%s", strings.Join(ran, "\n"), want) } } } +// The tasks that read upstreams read them with a token: the one a workflow set, untouched and gh +// not asked, or a person's from gh - and with none, where gh is logged out, they run all the +// same, since check says of an entry it could not read that it could not. +func TestVersionsAndBumpReadUpstreamsWithATokenWhereThereIsOne(t *testing.T) { + for name, tc := range map[string]struct { + env []string + asks bool + tokens string + }{ + "a person, gh logged in": {nil, true, "GITHUB_TOKEN= GH_TOKEN=a-token"}, + "a person, gh logged out": {[]string{"LOGGED_OUT=1"}, true, "GITHUB_TOKEN= GH_TOKEN="}, + "a workflow's GITHUB_TOKEN": {[]string{"GITHUB_TOKEN=the-runs"}, false, "GITHUB_TOKEN=the-runs GH_TOKEN="}, + "a workflow's GH_TOKEN": {[]string{"GH_TOKEN=an-apps"}, false, "GITHUB_TOKEN= GH_TOKEN=an-apps"}, + "a workflow's two": {[]string{"GITHUB_TOKEN=the-runs", "GH_TOKEN=an-apps"}, false, "GITHUB_TOKEN=the-runs GH_TOKEN=an-apps"}, + "a person's, exported empty": {[]string{"GITHUB_TOKEN=", "GH_TOKEN="}, true, "GITHUB_TOKEN= GH_TOKEN=a-token"}, + } { + t.Run(name, func(t *testing.T) { + r := newRepository(t, map[string]string{"Taskfile.yml": including("", "")}) + r.env = append(r.env, append(tc.env, "SHOW_TOKEN=1")...) + var asked []string + if tc.asks { + asked = []string{"gh auth token"} + } + r.ran(append(asked, "versions check -file versions.yaml", tc.tokens), "versions") + r.ran(append(asked, "versions bump -file versions.yaml task", tc.tokens), "bump", "NAME=task") + }) + } +} + // What a repository states of its release reaches it: its proof's workflow and jobs are what // proven is asked, and its files are on the release - of main's head, or of the commit named. func TestReleaseIsOfTheRepositorysProofAndFiles(t *testing.T) { @@ -341,8 +371,8 @@ func TestConsumersReadsTheRepositorysTable(t *testing.T) { // go-tools sets GO_TOOLS, and each command is then its tree's. func TestGoToolsRunsItsTreesCommands(t *testing.T) { r := newRepository(t, map[string]string{"Taskfile.yml": including("GO_TOOLS: 'go run ./cmd/'", ""), "consumers.toml": ""}) - r.ran([]string{"go run ./cmd/versions check -file versions.yaml"}, "versions") - r.ran([]string{"go run ./cmd/versions bump -file versions.yaml task"}, "bump", "NAME=task") + r.ran([]string{"gh auth token", "go run ./cmd/versions check -file versions.yaml"}, "versions") + r.ran([]string{"gh auth token", "go run ./cmd/versions bump -file versions.yaml task"}, "bump", "NAME=task") r.ran([]string{"git fetch --quiet --tags origin main", "go run ./cmd/consumers -table consumers.toml"}, "consumers") } diff --git a/site/src/content/docs/versions.md b/site/src/content/docs/versions.md index 186c7f1..60d645c 100644 --- a/site/src/content/docs/versions.md +++ b/site/src/content/docs/versions.md @@ -121,8 +121,11 @@ go tool versions bump kernel 7.2.9 # or to a version you name A bump downloads what the new version names and pins its hash; for an image, it asks the registry for the digest. It builds nothing, and the entry's `note` says what to run before committing. -`GITHUB_TOKEN`, when set, is sent to api.github.com, which answers only sixty unauthenticated -requests an hour. +`GITHUB_TOKEN` or `GH_TOKEN`, when set, is sent to api.github.com, which answers only sixty +unauthenticated requests an hour, and nothing of a private repository. Through +[the common tasks](../tasks/) a person needs neither: `go tool task versions` and +`go tool task bump` take `gh`'s token when no token is set and `gh` is logged in, as `release` +does. ### An entry check could not read From 33f1a7676d7da6aecc570d8286ceebd40242674f Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Sun, 22 Nov 2026 14:20:39 -0300 Subject: [PATCH 4/7] versions: a bump does not move a pin backwards unless it is told to `versions bump spin v20261024.01` moved website's pin from v20261114.01 to a release three weeks older and exited 0 (spin-stack/website#140). website's own `sources:bump` refuses that, and the rule is nobody's in particular, so it is upstream.Bump's: every repository's command that bumps through it has it. Backwards is what can be ordered. A version, by the numbers it starts with, refused before anything is fetched: that also stops a bump with no version named where the upstream's latest is older than the pin, which refresh now leaves where it is rather than failing or moving it. And a commit, for a git entry of a GitHub repository whose versions say neither way - a branch, or a commit of main moved to a tag: GitHub's compare is asked whether the pinned commit already holds the new one, which is website's rule that a pin on main moves only to a release that holds it. Where GitHub cannot be asked the bump is refused. Branches that parted are not called backwards, a version that starts with no number is not ordered, and an entry tracked with another goes where that one is. upstream.BumpBackwards, `versions bump -back` and `task bump BACK=1` are the bump of a person who means it. Part of #135 Co-Authored-By: Claude Fable 5.2 --- cmd/versions/main.go | 17 ++- cmd/versions/main_test.go | 45 ++++++++ cmd/versions/refresh.go | 5 + cmd/versions/refresh_test.go | 13 +++ internal/tasks/tasks.yml | 4 +- internal/tasks/tasks_test.go | 1 + site/src/content/docs/tasks.md | 2 +- site/src/content/docs/versions.md | 25 +++++ versions/upstream/upstream.go | 103 +++++++++++++++++- versions/upstream/upstream_test.go | 161 +++++++++++++++++++++++++++++ 10 files changed, 367 insertions(+), 9 deletions(-) diff --git a/cmd/versions/main.go b/cmd/versions/main.go index 1ad6f29..58008d0 100644 --- a/cmd/versions/main.go +++ b/cmd/versions/main.go @@ -66,7 +66,8 @@ Usage: and 2 when an entry could not be read, which may be behind versions bump [version] pin an entry at a version, the newest by default, and - every entry tracked with it at the same + every entry tracked with it at the same; never at an + older version or commit than the pin's, unless -back versions refresh ... bump each to its newest, a commit each, and say what moved and what is a new major, left for a person; -propose pushes them as refresh/