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
11 changes: 11 additions & 0 deletions cmd/versions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"slices"
"strings"
"text/tabwriter"
"time"

"github.com/spin-stack/go-tools/versions"
"github.com/spin-stack/go-tools/versions/upstream"
Expand Down Expand Up @@ -51,6 +52,10 @@ Usage:
versions check what is behind its upstream; exits 1 when anything is
versions bump <name> [version] pin an entry at a version, the newest by default, and
every entry tracked with it at the same
versions refresh <name>... bump each to its newest, a commit each, and say what moved;
-propose pushes them as refresh/<label>-<sum> and opens
the pull request (GITHUB_TOKEN or GH_TOKEN), once per set,
closing the open one it supersedes (-label, -base)

Every command takes -file, versions.yaml by default. Nothing is built by a bump: each entry's
note says what it is checked with afterwards.
Expand All @@ -69,6 +74,9 @@ func run(ctx context.Context, argv []string) error {
fs := flag.NewFlagSet(cmd, flag.ContinueOnError)
fs.SetOutput(io.Discard)
file := fs.String("file", versions.File, "the versions.yaml to read")
propose := fs.Bool("propose", false, "refresh: open a pull request of what moved")
label := fs.String("label", "versions", "refresh: the name of the branches it proposes")
base := fs.String("base", "main", "refresh: the branch the pull request is into")
if err := fs.Parse(argv); err != nil {
if errors.Is(err, flag.ErrHelp) {
fmt.Print(usage)
Expand Down Expand Up @@ -109,6 +117,9 @@ func run(ctx context.Context, argv []string) error {
return check(ctx, v)
case "bump":
return bump(ctx, v, *file, names)
case "refresh":
r := refresher{file: *file, git: runGit, label: *label, base: *base, out: os.Stdout, now: time.Now()}
return refresh(ctx, r, *propose, names)
default:
fmt.Fprint(os.Stderr, usage)
return fmt.Errorf("unknown command %q", cmd)
Expand Down
53 changes: 27 additions & 26 deletions cmd/versions/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,33 @@ func TestTheCommandsAnswerFromTheFile(t *testing.T) {
out string
fails bool
}{
"args": {argv: []string{"args", "-file", file, "kernel"}, out: "--build-arg KERNEL_SHA256=1111111111111111111111111111111111111111111111111111111111111111 --build-arg KERNEL_VERSION=7.2.8\n"},
"env": {argv: []string{"env", "-file", file, "kernel"}, out: "KERNEL_SHA256=1111111111111111111111111111111111111111111111111111111111111111\nKERNEL_VERSION=7.2.8\n"},
"version": {argv: []string{"version", "-file", file, "kernel"}, out: "7.2.8\n"},
"newer": {argv: []string{"newer", "-file", file, "kernel", "7.2.9"}, out: "7.2.9\n"},
"not newer": {argv: []string{"newer", "-file", file, "kernel", "7.2.8"}},
"newer, no form": {argv: []string{"newer", "-file", file, "kernel", "v7.2.9"}, fails: true},
"newer, no name": {argv: []string{"newer", "-file", file, "kernel"}, fails: true},
"newer, no entry": {argv: []string{"newer", "-file", file, "nope", "1"}, fails: true},
"url": {argv: []string{"url", "-file", file, "kernel"}, out: "https://cdn.kernel.org/pub/linux/kernel/v7.x/linux-7.2.8.tar.xz\n"},
"help": {argv: []string{"help"}, out: usage},
"-h": {argv: []string{"-h"}, out: usage},
"--help": {argv: []string{"--help"}, out: usage},
"nothing": {fails: true},
"an unknown one": {argv: []string{"frob", "-file", file}, fails: true},
"an unknown flag": {argv: []string{"version", "-nope"}, fails: true},
"help as a flag": {argv: []string{"version", "-h"}, out: usage, fails: true},
"no file": {argv: []string{"version", "-file", filepath.Join(t.TempDir(), "none"), "kernel"}, fails: true},
"args of nothing": {argv: []string{"args", "-file", file}, fails: true},
"args of none": {argv: []string{"args", "-file", file, "qemu"}, fails: true},
"check of names": {argv: []string{"check", "-file", file, "kernel"}, fails: true},
"bump of nothing": {argv: []string{"bump", "-file", file}, fails: true},
"bump of three": {argv: []string{"bump", "-file", file, "a", "b", "c"}, fails: true},
"bump of none": {argv: []string{"bump", "-file", file, "qemu"}, fails: true},
"fetch of one": {argv: []string{"fetch", "-file", file, "kernel"}, fails: true},
"fetch of three": {argv: []string{"fetch", "-file", file, "kernel", "a", "b"}, fails: true},
"fetch of none": {argv: []string{"fetch", "-file", file, "qemu", t.TempDir()}, fails: true},
"args": {argv: []string{"args", "-file", file, "kernel"}, out: "--build-arg KERNEL_SHA256=1111111111111111111111111111111111111111111111111111111111111111 --build-arg KERNEL_VERSION=7.2.8\n"},
"env": {argv: []string{"env", "-file", file, "kernel"}, out: "KERNEL_SHA256=1111111111111111111111111111111111111111111111111111111111111111\nKERNEL_VERSION=7.2.8\n"},
"version": {argv: []string{"version", "-file", file, "kernel"}, out: "7.2.8\n"},
"newer": {argv: []string{"newer", "-file", file, "kernel", "7.2.9"}, out: "7.2.9\n"},
"not newer": {argv: []string{"newer", "-file", file, "kernel", "7.2.8"}},
"newer, no form": {argv: []string{"newer", "-file", file, "kernel", "v7.2.9"}, fails: true},
"newer, no name": {argv: []string{"newer", "-file", file, "kernel"}, fails: true},
"newer, no entry": {argv: []string{"newer", "-file", file, "nope", "1"}, fails: true},
"url": {argv: []string{"url", "-file", file, "kernel"}, out: "https://cdn.kernel.org/pub/linux/kernel/v7.x/linux-7.2.8.tar.xz\n"},
"help": {argv: []string{"help"}, out: usage},
"-h": {argv: []string{"-h"}, out: usage},
"--help": {argv: []string{"--help"}, out: usage},
"nothing": {fails: true},
"an unknown one": {argv: []string{"frob", "-file", file}, fails: true},
"an unknown flag": {argv: []string{"version", "-nope"}, fails: true},
"help as a flag": {argv: []string{"version", "-h"}, out: usage, fails: true},
"no file": {argv: []string{"version", "-file", filepath.Join(t.TempDir(), "none"), "kernel"}, fails: true},
"args of nothing": {argv: []string{"args", "-file", file}, fails: true},
"args of none": {argv: []string{"args", "-file", file, "qemu"}, fails: true},
"check of names": {argv: []string{"check", "-file", file, "kernel"}, fails: true},
"bump of nothing": {argv: []string{"bump", "-file", file}, fails: true},
"bump of three": {argv: []string{"bump", "-file", file, "a", "b", "c"}, fails: true},
"bump of none": {argv: []string{"bump", "-file", file, "qemu"}, fails: true},
"refresh of nothing": {argv: []string{"refresh", "-file", file}, fails: true},
"fetch of one": {argv: []string{"fetch", "-file", file, "kernel"}, fails: true},
"fetch of three": {argv: []string{"fetch", "-file", file, "kernel", "a", "b"}, fails: true},
"fetch of none": {argv: []string{"fetch", "-file", file, "qemu", t.TempDir()}, fails: true},
} {
t.Run(name, func(t *testing.T) {
var err error
Expand Down
Loading
Loading