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/cmd/versions/main.go b/cmd/versions/main.go index d26a44f..0bb55ac 100644 --- a/cmd/versions/main.go +++ b/cmd/versions/main.go @@ -26,17 +26,39 @@ import ( func main() { ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) - err := run(ctx, os.Args[1:]) + err := run(ctx, os.Args[1:]) // mutate-exempt: the process's own arguments; run is what the tests drive stop() - if err != nil && !errors.Is(err, flag.ErrHelp) { - // The package names itself in its errors already; this names the rest. - msg := err.Error() - if !strings.HasPrefix(msg, "versions: ") { - msg = "versions: " + msg - } + if msg, code := failure(err); code != 0 { // mutate-exempt: the process's exit; failure is what the tests drive fmt.Fprintln(os.Stderr, msg) - os.Exit(1) + os.Exit(code) + } +} + +// failure is what a command that failed says and the status it exits with: nothing and 0 for one +// that did not, and for a help that was asked for. +func failure(err error) (string, int) { + if err == nil || errors.Is(err, flag.ErrHelp) { + return "", 0 + } + // The package names itself in its errors already; this names the rest. + msg := err.Error() + if !strings.HasPrefix(msg, "versions: ") { + msg = "versions: " + msg } + return msg, 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 @@ -49,9 +71,14 @@ 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 (-task: its last line names the task that + moves one, for a run through the common tasks) 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, + and not an entry whose bump: names another command 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/