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
6 changes: 3 additions & 3 deletions .github/workflows/compat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ jobs:
# run boots the release's base image, so a change to it reaches nothing this checks.
- name: Does the change reach the machine
id: machine
run: spin-machine-dev changed --base "$BASE" --pins qemu-builder,alpine,qemu,debian,debian-snapshot,qboot,kernel,moby-check-config,sparse machine cmd/spin-machine qemu kernel cmd/spin-machine-dev internal/build internal/lab/compat.go internal/lab/tree.go internal/lab/sources.go boot/harness_test.go boot/record_test.go boot/patches_test.go boot/events_test.go boot/verbs_test.go boot/cpuplug_test.go boot/lockdown_test.go boot/testdata/lockdown-check.sh boot/Taskfile.yml go.mod .github/workflows/compat.yml
run: spin-machine-dev changed --base "$BASE" --part qemu --part kernel machine cmd/spin-machine cmd/spin-machine-dev internal/build internal/lab/compat.go internal/lab/tree.go internal/lab/sources.go boot/harness_test.go boot/record_test.go boot/patches_test.go boot/events_test.go boot/verbs_test.go boot/cpuplug_test.go boot/lockdown_test.go boot/testdata/lockdown-check.sh boot/Taskfile.yml go.mod .github/workflows/compat.yml

- name: Does the change reach QEMU
id: qemu
run: spin-machine-dev changed --base "$BASE" --pins qemu-builder,alpine,qemu,debian,debian-snapshot,qboot qemu go.mod cmd/spin-machine-dev internal/build
run: spin-machine-dev changed --base "$BASE" --part qemu go.mod cmd/spin-machine-dev internal/build

- name: Does the change reach the kernel
id: kernel
run: spin-machine-dev changed --base "$BASE" --pins debian,debian-snapshot,kernel,moby-check-config,sparse kernel go.mod cmd/spin-machine-dev internal/build
run: spin-machine-dev changed --base "$BASE" --part kernel go.mod cmd/spin-machine-dev internal/build

resume:
needs: changed
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/parts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ jobs:

- name: Does the change reach QEMU
id: qemu
run: spin-machine-dev changed --base "$BASE" --pins qemu-builder,alpine,qemu,debian,debian-snapshot,qboot qemu go.mod cmd/spin-machine-dev internal/build .github/workflows/parts.yml
run: spin-machine-dev changed --base "$BASE" --part qemu go.mod cmd/spin-machine-dev internal/build .github/workflows/parts.yml

- name: Does the change reach the kernel
id: kernel
run: spin-machine-dev changed --base "$BASE" --pins debian,debian-snapshot,kernel,moby-check-config,sparse kernel go.mod cmd/spin-machine-dev internal/build .github/workflows/parts.yml
run: spin-machine-dev changed --base "$BASE" --part kernel go.mod cmd/spin-machine-dev internal/build .github/workflows/parts.yml

- name: Does the change reach e2fsprogs or the image
id: image
run: spin-machine-dev changed --base "$BASE" --pins e2fsprogs-builder,e2fsprogs,ubuntu,systemd-source,openssh-source,mkosi,task,git-lfs,buildkit,docker-ce,docker-ce-cli,docker-ce-rootless-extras,containerd-io,docker-buildx-plugin,docker-compose-plugin image e2fsprogs cmd/spin-machine-pressure internal/pressure go.mod go.sum cmd/spin-machine-dev internal/build .github/workflows/parts.yml
run: spin-machine-dev changed --base "$BASE" --part image cmd/spin-machine-dev internal/build .github/workflows/parts.yml

qemu:
needs: changed
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ coverage.html

# Agent worktrees, made inside the repository by Claude Code.
.claude/worktrees/

# What a plain `go build ./cmd/...` leaves at the root; spin-machine-dev build puts them in _output/bin.
/spin-machine-dev
/spin-machine
/spin-machine-pressure
41 changes: 29 additions & 12 deletions cmd/spin-machine-dev/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,34 +275,51 @@ fetch qemu pulls. main's parts.yml runs it, with a docker login that can write p

func changedCmd() *cobra.Command {
var base string
var pins []string
var parts, pins []string
c := &cobra.Command{
Use: "changed --base <commit> --pins <entry,...> <path>...",
Use: "changed --base <commit> (--part <part> | --pins <entry,...>)... [path...]",
Short: "Say whether the commits since a base can change what a part builds",
Hidden: true,
Long: `Say whether the commits since --base can change what is built from the pins and paths named:
true when anything under the paths changed or versions.yaml hands those pins other build arguments
than it did at the base. A workflow's path filter cannot say which lines of versions.yaml moved; this
can, so a bump of e2fsprogs does not rebuild QEMU and the kernel.
Long: `Say whether the commits since --base can change what the parts named build: true when
anything under their paths, the parts they are made with, or the paths named changed, or when
versions.yaml hands their pins other build arguments than it did at the base. The pins and paths
are internal/build's, so a workflow names the part and only what it adds, and a part's pin added to
internal/build reaches every workflow at once. --pins names entries for a check that is not a part
(codeql.yml's patched trees). A workflow's path filter cannot say which lines of versions.yaml
moved; this can, so a bump of e2fsprogs does not rebuild QEMU and the kernel.

Prints build=true or build=false, and writes it to the step's outputs. It errs towards building: no
base, a base this clone lacks, or a versions.yaml there it cannot read is true.`,
Args: cobra.MinimumNArgs(1),
RunE: func(c *cobra.Command, paths []string) error {
RunE: func(c *cobra.Command, extra []string) error {
w, err := open()
if err != nil {
return err
}
if len(pins) == 0 {
return couldNot(fmt.Errorf("--pins names none: say which versions.yaml entries the part is built from"))
if len(parts) == 0 && len(pins) == 0 {
return couldNot(fmt.Errorf("--part and --pins name none: say which parts (%s) or versions.yaml entries the change is to reach", strings.Join(build.Names(), ", ")))
}
touched := build.Touches(c.Context(), w.root, base, w.pins, pins, paths)
var paths []string
if len(parts) > 0 {
plan, err := build.Plan(parts)
if err != nil {
return couldNot(err)
}
for _, p := range plan {
pins = append(pins, p.Pins...)
paths = append(paths, p.Paths...)
}
}
if len(paths)+len(extra) == 0 {
return couldNot(fmt.Errorf("no paths: --pins needs the paths its check is made from"))
}
touched := build.Touches(c.Context(), w.root, base, w.pins, pins, append(paths, extra...))
_, _ = fmt.Fprintf(c.OutOrStdout(), "build=%t\n", touched)
return output("build", fmt.Sprint(touched))
},
}
c.Flags().StringVar(&base, "base", "", "the commit the change is to; none builds")
c.Flags().StringSliceVar(&pins, "pins", nil, "the versions.yaml entries the part's Dockerfile is handed")
c.Flags().StringSliceVar(&parts, "part", nil, "the parts whose pins and paths decide it, with the parts they are made with")
c.Flags().StringSliceVar(&pins, "pins", nil, "versions.yaml entries that decide it, for a check that is not a part")
return c
}

Expand Down
53 changes: 48 additions & 5 deletions cmd/spin-machine-dev/verbs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,17 +442,60 @@ func TestVerifySaysWhatIsMissingAndAsksQEMUForTheArguments(t *testing.T) {
}

func TestChangedSaysWhetherAPartBuilds(t *testing.T) {
checkout(t)
stdout, _, status := verb(t, "changed", "--pins", "e2fsprogs", "e2fsprogs")
dir := checkout(t)
// A part's own path and one the workflow adds.
stdout, _, status := verb(t, "changed", "--part", "e2fsprogs", "go.mod")
if status != 0 || stdout != "build=true\n" || read(t, os.Getenv("GITHUB_OUTPUT")) != "build=true\n" {
t.Errorf("no base: exit %d, %q, %q", status, stdout, read(t, os.Getenv("GITHUB_OUTPUT")))
}
if _, stderr, status := verb(t, "changed", "e2fsprogs"); status != 2 || !strings.Contains(stderr, "--pins") {
t.Errorf("no pins: exit %d, %q", status, stderr)
if _, stderr, status := verb(t, "changed", "e2fsprogs"); status != 2 || !strings.Contains(stderr, "--part") {
t.Errorf("no part: exit %d, %q", status, stderr)
}
if _, stderr, status := verb(t, "changed", "--part", "nope"); status != 2 || !strings.Contains(stderr, "nope") {
t.Errorf("a part that is not one: exit %d, %q", status, stderr)
}
if _, _, status := verb(t, "changed", "--pins", "e2fsprogs"); status == 0 {
t.Error("no paths was taken")
t.Error("--pins with no paths was taken")
}

// A part's pins and paths are internal/build's, with those of the parts it is made with: a
// bump of a package only the image installs, and a change to the e2fsprogs the image is made
// with, each reach the image and not the kernel.
gitRepo(t, dir)
base := strings.TrimSpace(gitOut(t, dir, "rev-parse", "HEAD"))
changes := map[string]func(){
"docker-ce bumped": func() {
raw := read(t, filepath.Join(dir, "versions.yaml"))
before, entry, _ := strings.Cut(raw, "- name: docker-ce\n")
pin, rest, _ := strings.Cut(entry, " pin: ")
entry = pin + " pin: " + strings.Repeat("0", 64) + rest[64:]
put(t, filepath.Join(dir, "versions.yaml"), before+"- name: docker-ce\n"+entry, 0o644)
},
"e2fsprogs changed": func() { put(t, filepath.Join(dir, "e2fsprogs", "Dockerfile"), "x\n", 0o644) },
}
for name, change := range changes {
gitOut(t, dir, "reset", "-q", "--hard", base)
change()
gitOut(t, dir, "add", "-A")
gitOut(t, dir, "-c", "user.name=t", "-c", "user.email=t@t", "commit", "-q", "-m", name)
for part, want := range map[string]string{"image": "build=true\n", "kernel": "build=false\n"} {
if stdout, stderr, status := verb(t, "changed", "--base", base, "--part", part); status != 0 || stdout != want {
t.Errorf("%s, --part %s: exit %d, %q, %q", name, part, status, stdout, stderr)
}
}
}
}

// gitOut runs git in dir and is its output.
func gitOut(t *testing.T, dir string, args ...string) string {
t.Helper()
cmd := exec.Command("git", args...)
cmd.Dir = dir
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("git %v: %v: %s", args, err, out)
}
return string(out)
}

// gitRepo makes dir a repository with one commit, tagged with tags.
Expand Down
4 changes: 2 additions & 2 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ PATH. Under `go run`, a step would exit 1 whatever the verb's status. taskgate
ci.yml task lint ; task test ; task coverage ; task mutate ; task bin ;
spin-machine-dev build spin-machine ; spin-machine-dev fetch qemu ;
spin-machine-dev vsock ; spin-machine-dev verify args
parts.yml changed: spin-machine-dev changed --base $BASE --pins ... <paths>, once a part
parts.yml changed: spin-machine-dev changed --base $BASE --part <part> <paths>, once a part
qemu: spin-machine-dev build qemu --cache-registry ; vsock ; verify args ;
publish qemu (main)
kernel: spin-machine-dev build kernel --cache-registry ;
release traceable-kernel --cache-registry
image: spin-machine-dev build e2fsprogs ; spin-machine-dev build image
parts: spin-machine-dev needs
compat.yml changed: spin-machine-dev changed --base $BASE --pins ... <paths>, for the machine,
compat.yml changed: spin-machine-dev changed --base $BASE --part <part> <paths>, for the machine,
QEMU and the kernel
resume: (when the change reaches the machine) spin-machine-dev vsock ;
spin-machine-dev build qemu, or fetch qemu when the change does not reach it ;
Expand Down