diff --git a/.github/scripts/check-release-version.py b/.github/scripts/check-release-version.py index 0ad351f6..500e9976 100755 --- a/.github/scripts/check-release-version.py +++ b/.github/scripts/check-release-version.py @@ -10,9 +10,14 @@ release asset names via `@v`. The k0s and OpenZFS sysexts pin their own upstream versions in include/k0s.yml and include/zfs.yml. -This script fails closed on drift. +This script fails closed on drift. It is also the one parser of the pinned +FSDK point release: + + --print-fsdk print it (the Justfile's fsdk_version) + --fix set installer-version to it, then check (track-junctions.yml) """ +import argparse import re import sys from pathlib import Path @@ -25,6 +30,8 @@ r"^\s*installer-version:\s*[\"']?([0-9]+\.[0-9]+\.[0-9]+)[\"']?\s*$", re.MULTILINE ) FSDK_REF_RE = re.compile(r"freedesktop-sdk-([0-9]+\.[0-9]+\.[0-9]+)") +# Any installer-version value, valid or not, for --fix to replace. +INSTALLER_LINE_RE = re.compile(r"^([ \t]*installer-version:[ \t]*).*$", re.MULTILINE) def read(path): @@ -33,10 +40,38 @@ def read(path): return path.read_text(encoding="utf-8") -def main(): +def pinned_fsdk_version(): + fsdk_match = FSDK_REF_RE.search(read(FSDK_JUNCTION)) + if not fsdk_match: + sys.exit( + "ERROR: elements/freedesktop-sdk.bst has no " + "'freedesktop-sdk-X.Y.Z' point release in its ref." + ) + return fsdk_match.group(1) + + +def fix_installer_version(fsdk_pinned): conf = read(PROJECT_CONF) - junction = read(FSDK_JUNCTION) + fixed = INSTALLER_LINE_RE.sub(lambda m: f'{m.group(1)}"{fsdk_pinned}"', conf, count=1) + if fixed != conf: + PROJECT_CONF.write_text(fixed, encoding="utf-8") + +def main(argv=()): + parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + action = parser.add_mutually_exclusive_group() + action.add_argument("--print-fsdk", action="store_true", help="print the pinned FSDK point release") + action.add_argument("--fix", action="store_true", help="sync installer-version to the pinned FSDK point release") + args = parser.parse_args(argv) + + fsdk_pinned = pinned_fsdk_version() + if args.print_fsdk: + print(fsdk_pinned) + return + if args.fix: + fix_installer_version(fsdk_pinned) + + conf = read(PROJECT_CONF) installer_match = INSTALLER_VERSION_RE.search(conf) if not installer_match: sys.exit( @@ -45,14 +80,6 @@ def main(): ) installer_declared = installer_match.group(1) - fsdk_match = FSDK_REF_RE.search(junction) - if not fsdk_match: - sys.exit( - "ERROR: elements/freedesktop-sdk.bst has no " - "'freedesktop-sdk-X.Y.Z' point release in its ref." - ) - fsdk_pinned = fsdk_match.group(1) - if installer_declared != fsdk_pinned: sys.exit( "ERROR: installer-version drift.\n" @@ -71,4 +98,4 @@ def main(): if __name__ == "__main__": - main() + main(sys.argv[1:]) diff --git a/.github/scripts/image-build-needed.py b/.github/scripts/image-build-needed.py index 82343a18..384d4e9f 100644 --- a/.github/scripts/image-build-needed.py +++ b/.github/scripts/image-build-needed.py @@ -4,7 +4,8 @@ Reads the PR's changed paths (one per line, renames listed under both names) on stdin and prints ``true`` or ``false`` for the build workflow's `changes` job, which runs this script from the PR's base revision. Only changes that -cannot reach the image set or the boot test skip the ~2 h build: docs, +cannot reach the image set or the boot test skip the full build (figures in +docs/skills/ci-tooling.md, "Build time and caches"): docs, Markdown outside the build inputs, unit/e2e tests and the workflows that run them. Anything else, and anything under a build input root, builds; so does any change to this classifier or to the build workflow, and an empty or diff --git a/.github/scripts/propose-pr.sh b/.github/scripts/propose-pr.sh new file mode 100755 index 00000000..8b65c6a1 --- /dev/null +++ b/.github/scripts/propose-pr.sh @@ -0,0 +1,94 @@ +#!/usr/bin/env bash +# Propose the working-tree changes to PATHs as one commit on BRANCH and open +# or update its pull request against BASE. Shared by the trackers +# (track-junctions.yml, track-binaries.yml). +# +# propose-pr.sh --branch B --title T --body-file F [--base main] +# [--remote origin] [--skip-closed-title] -- PATH... +# +# Does nothing when: +# - PATHs do not differ from the checked-out commit (nothing to propose); +# - an open pull request's branch already holds exactly these PATHs, so a +# daily run neither force-pushes an identical commit nor restarts its CI; +# - --skip-closed-title and a closed pull request from BRANCH had this +# title: it was turned down, and the next upstream version brings a new +# title. +# Otherwise it commits onto BRANCH (from the checked-out commit), force-pushes +# with a lease on the branch state it saw, and creates or edits the pull +# request. GH_TOKEN authenticates `gh` and the push: checkouts do not persist +# credentials, so the push passes it as a one-off header that never reaches +# .git/config. +# +# No `|| true` on the queries: a failed `gh` or `git ls-remote` must stop the +# run, not pass for "no pull request" or "no branch". +set -euo pipefail + +die() { echo "propose-pr: $*" >&2; exit 1; } + +branch="" title="" body="" base=main remote=origin skip_closed=0 +while [ $# -gt 0 ]; do + case "$1" in + --branch) branch="$2"; shift 2 ;; + --title) title="$2"; shift 2 ;; + --body-file) body="$2"; shift 2 ;; + --base) base="$2"; shift 2 ;; + --remote) remote="$2"; shift 2 ;; + --skip-closed-title) skip_closed=1; shift ;; + --) shift; break ;; + *) die "unknown argument: $1" ;; + esac +done +[ -n "${branch}" ] && [ -n "${title}" ] || die "--branch and --title are required" +[ -f "${body}" ] || die "--body-file must name a file" +[ $# -gt 0 ] || die "no paths to propose" +paths=("$@") + +git add -- "${paths[@]}" +if git diff --cached --quiet -- "${paths[@]}"; then + echo "Nothing to propose: ${paths[*]} already match $(git rev-parse --short HEAD)." + exit 0 +fi + +remote_head="" +if git ls-remote --exit-code --heads "${remote}" "refs/heads/${branch}" >/dev/null; then + git fetch --quiet "${remote}" "+refs/heads/${branch}:refs/remotes/${remote}/${branch}" + remote_head="$(git rev-parse "refs/remotes/${remote}/${branch}")" +else + status=$? + [ "${status}" -eq 2 ] || die "cannot list ${branch} on ${remote} (git ls-remote exit ${status})" +fi + +open="$(gh pr list --head "${branch}" --base "${base}" --state open --json number --jq '.[0].number // empty')" +if [ -n "${open}" ] && [ -n "${remote_head}" ] && git diff --cached --quiet "${remote_head}" -- "${paths[@]}"; then + echo "#${open} already proposes this content on ${branch}; leaving it and its CI alone." + exit 0 +fi +if [ -z "${open}" ] && [ "${skip_closed}" = 1 ]; then + closed="$(gh pr list --head "${branch}" --base "${base}" --state closed --json title --jq '.[].title')" + if grep -Fxq -- "${title}" <<< "${closed}"; then + echo "A closed pull request already proposed '${title}'; not reopening it." + exit 0 + fi +fi + +# Deliberately no attribution trailers: the trackers' commits are the +# deterministic output of their tools, with no AI authorship to attribute +# (AGENTS.md's trailers are for AI-authored commits). Do not re-add the +# Copilot trailer the old track-refs job carried. +git checkout --quiet -B "${branch}" +git -c user.name="github-actions[bot]" \ + -c user.email="41898282+github-actions[bot]@users.noreply.github.com" \ + commit --quiet -m "${title}" +push_auth=() +if [ -n "${GH_TOKEN:-}" ]; then + push_auth=(-c "http.${GITHUB_SERVER_URL:-https://github.com}/.extraheader=AUTHORIZATION: basic $(printf 'x-access-token:%s' "${GH_TOKEN}" | base64 -w0)") +fi +git "${push_auth[@]}" push --quiet --force-with-lease="refs/heads/${branch}:${remote_head}" \ + "${remote}" "HEAD:refs/heads/${branch}" + +if [ -n "${open}" ]; then + gh pr edit "${open}" --title "${title}" --body-file "${body}" + echo "Updated PR: $(gh pr view "${open}" --json url --jq '.url')" +else + echo "Created PR: $(gh pr create --base "${base}" --head "${branch}" --title "${title}" --body-file "${body}")" +fi diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f5120673..f910c0e3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,7 +34,8 @@ jobs: # full-build label or when it changes the FSDK junction or its patches, # and never when it cannot change the image set (docs, unit tests; see # .github/scripts/image-build-needed.py). Other pull requests run - # `validate` in minutes instead of the ~1.5 h build. + # `validate` in minutes instead of the full build (build-time figures: + # docs/skills/ci-tooling.md#build-time-and-caches). # A skipped job reports as passing, so `build` and `boot-test` can be # required checks without blocking those PRs. The classifier script is # checked out from the base revision, so editing it does not skip the PR's @@ -131,9 +132,10 @@ jobs: - name: Validate Element Graph run: just validate - # FSDK's kernel is ~70 of the ~85 build minutes, and no upstream cache holds - # it (our module certificate and kernel config patches change its key). This - # job builds it (and Go) with the committed release module certificate and no + # FSDK's kernel is most of a cold build + # (docs/skills/ci-tooling.md#build-time-and-caches), and no upstream cache + # holds it (our module certificate and kernel config patches change its + # key). This job builds it (and Go) with the committed release module certificate and no # signing secrets, and pushes the key-free artifacts to the project CAS unless # a remote already holds them; every build pulls them through project.conf # (scripts/kernel-cache.sh). @@ -157,22 +159,8 @@ jobs: with: tool: just@1.58.0 - # BuildStream's cache on the runner's /mnt disk; the kernel build alone - # fills 15 GB. - name: Set up runner disk space - run: | - set -euo pipefail - sudo mkdir -p /mnt/podman /mnt/buildstream - sudo chown -R "$USER:$USER" /mnt/podman /mnt/buildstream - mkdir -p ~/.config/containers - cat > ~/.config/containers/storage.conf <> "$GITHUB_OUTPUT" - name: Set up runner disk space - run: | - set -euo pipefail - sudo mkdir -p /mnt/podman /mnt/buildstream - sudo chown -R "$USER:$USER" /mnt/podman /mnt/buildstream - mkdir -p ~/.config/containers - cat > ~/.config/containers/storage.conf <- oci/bluefin-server-image.bst oci/bluefin-server-boot.bst oci/bluefin-server-usr.bst + oci/bluefin-server-sbom.bst oci/k0s-sysext.bst oci/kubestellar-sysext.bst oci/kubeadm-sysext.bst @@ -38,7 +42,10 @@ jobs: oci/argo-workflows-sysext.bst oci/mcp-sysext.bst oci/zfs-sysext.bst + oci/nvidia-open-595-sysext.bst + oci/nvidia-container-toolkit-sysext.bst bluefin-server/os-sd-boot-signed.bst + homelab/homelab-templates.bst steps: - name: Checkout repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -51,19 +58,7 @@ jobs: tool: just@1.58.0 - name: Set up runner disk space - run: | - set -euo pipefail - sudo mkdir -p /mnt/podman /mnt/buildstream - sudo chown -R "$USER:$USER" /mnt/podman /mnt/buildstream - mkdir -p ~/.config/containers - cat > ~/.config/containers/storage.conf <> "$RUNNER_TEMP/pr-body.md" - if [ -n "$open" ]; then - gh pr edit "$number" --title "$title" --body-file "$RUNNER_TEMP/pr-body.md" - echo "Updated PR: $(gh pr view "$number" --json url --jq '.url')" - else - echo "Created PR: $(gh pr create --base main --head "$branch" --title "$title" --body-file "$RUNNER_TEMP/pr-body.md")" - fi + mapfile -t files < "$RUNNER_TEMP/files.txt" + # One pull request per component. A closed one with this exact title + # was turned down (or reverted); the next release brings a new title. + bash .github/scripts/propose-pr.sh --branch "auto/track-binaries/${COMPONENT}" \ + --title "chore(deps): update ${COMPONENT} ${FROM} -> ${TO}" \ + --body-file "$RUNNER_TEMP/pr-body.md" --skip-closed-title \ + -- "${files[@]}" diff --git a/.github/workflows/track-junctions.yml b/.github/workflows/track-junctions.yml index 71d417d7..6ba2c2a2 100644 --- a/.github/workflows/track-junctions.yml +++ b/.github/workflows/track-junctions.yml @@ -55,21 +55,12 @@ jobs: just bst source track freedesktop-sdk.bst - name: Sync installer-version to the tracked FSDK point release - run: | - set -euo pipefail - # project.conf's installer-version must equal the FSDK point - # release; check-release-version.py fails - # closed on drift and is the first thing `just validate` runs. Without - # this step an FSDK bump would open a PR that dies in seconds at - # "Validate Element Graph" — exactly the failure the old job produced. - pinned=$(grep -oE 'freedesktop-sdk-[0-9]+\.[0-9]+\.[0-9]+' elements/freedesktop-sdk.bst | head -1 | sed 's/freedesktop-sdk-//') - if [ -z "$pinned" ]; then - echo "ERROR: tracked freedesktop-sdk.bst ref carries no X.Y.Z point release" >&2 - exit 1 - fi - sed -i -E "s|^([[:space:]]*installer-version:[[:space:]]*).*|\1\"${pinned}\"|" project.conf - # Assert before opening the PR; a failure here means the sync broke. - python3 .github/scripts/check-release-version.py + # project.conf's installer-version must equal the FSDK point release: + # check-release-version.py fails closed on drift and is the first + # thing `just validate` runs, so without this sync an FSDK bump would + # open a PR that dies in seconds at "Validate Element Graph". --fix + # rewrites installer-version, then runs the same check. + run: python3 .github/scripts/check-release-version.py --fix # A GitHub App token, not secrets.GITHUB_TOKEN: pushes and PRs made with # GITHUB_TOKEN do not dispatch workflow runs, which is why the old job's @@ -89,27 +80,16 @@ jobs: - name: Create or update the junction bump PR env: GH_TOKEN: ${{ steps.app-token.outputs.token }} - BRANCH: auto/track-junctions RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} run: | set -euo pipefail - - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - old_fsdk=$(git show "HEAD:elements/freedesktop-sdk.bst" | awk '/^[[:space:]]*ref:/ { print $2; exit }') new_fsdk=$(awk '/^[[:space:]]*ref:/ { print $2; exit }' elements/freedesktop-sdk.bst) - - git checkout -B "$BRANCH" - git add elements/freedesktop-sdk.bst project.conf - if git diff --cached --quiet; then - echo "Junction refs already current — nothing to propose." - exit 0 - fi + point() { sed 's/^freedesktop-sdk-//;s/-[0-9]*-g[0-9a-f]*$//' <<< "$1"; } title="chore(deps): update BuildStream junctions" if [ "$old_fsdk" != "$new_fsdk" ]; then - title="${title} (freedesktop-sdk $(echo "$old_fsdk" | sed 's/^freedesktop-sdk-//;s/-[0-9]*-g[0-9a-f]*$//') -> $(echo "$new_fsdk" | sed 's/^freedesktop-sdk-//;s/-[0-9]*-g[0-9a-f]*$//'))" + title="${title} (freedesktop-sdk $(point "$old_fsdk") -> $(point "$new_fsdk"))" fi { @@ -129,27 +109,6 @@ jobs: echo "*Generated by [Track junction refs](${RUN_URL})*" } > "$RUNNER_TEMP/pr-body.md" - # Deliberately no attribution trailers. This commit is a deterministic - # `bst source track` result plus a `sed` on project.conf — machine - # output with no AI authorship to attribute. The `Co-authored-by: - # Copilot` trailer inherited from the old track-refs job was a false - # attribution that would accumulate across every junction bump. Please - # do not re-add it; AGENTS.md's trailer requirement is about - # AI-authored commits, which this is not. - git commit -m "$title" - git -c "http.${GITHUB_SERVER_URL}/.extraheader=AUTHORIZATION: basic $(printf 'x-access-token:%s' "$GH_TOKEN" | base64 -w0)" \ - push --force-with-lease origin "$BRANCH" - - # No `|| true`: `gh pr list` already exits 0 and prints nothing when - # no PR matches, so a fallback buys nothing for the normal case and - # only converts an auth failure or API outage into an empty - # `existing` that falls through to `gh pr create` against a branch - # that may already have an open PR. `// empty` is the legitimate - # mechanism for "no open PR"; a failed query must abort the step. - existing=$(gh pr list --head "$BRANCH" --base main --state open --json number --jq '.[0].number // empty') - if [ -n "$existing" ]; then - gh pr edit "$existing" --title "$title" --body-file "$RUNNER_TEMP/pr-body.md" - echo "Updated PR: $(gh pr view "$existing" --json url --jq '.url')" - else - echo "Created PR: $(gh pr create --base main --head "$BRANCH" --title "$title" --body-file "$RUNNER_TEMP/pr-body.md")" - fi + bash .github/scripts/propose-pr.sh --branch auto/track-junctions \ + --title "$title" --body-file "$RUNNER_TEMP/pr-body.md" \ + -- elements/freedesktop-sdk.bst project.conf diff --git a/Justfile b/Justfile index 47fdca62..85b644a4 100644 --- a/Justfile +++ b/Justfile @@ -3,7 +3,7 @@ default: @just --list -# Same bst2 container image FSDK/dakota CI uses -- pinned by SHA. +# Same bst2 container image FSDK/dakota CI uses -- pinned by commit-named tag. export oras_image := env("ORAS_IMAGE", "ghcr.io/oras-project/oras:v1.3.4") export bst2_image := env("BST2_IMAGE", "registry.gitlab.com/freedesktop-sdk/infrastructure/freedesktop-sdk-docker-images/bst2:64eb0b4930d57a92710822898fb73af6cc1ae35d") # bats for `just test-unit` when none is installed -- pinned by digest. @@ -14,9 +14,9 @@ export butane_image := env("BUTANE_IMAGE", "quay.io/coreos/butane:release@sha256 # Prefix for podman calls: empty when rootless podman works, "sudo" otherwise. sudo_cmd := if `podman info >/dev/null 2>&1 && echo 1 || echo 0` == "1" { "" } else { "sudo" } -# FSDK release parsed from the pinned junction ref — the single source of truth -# for image versioning. e.g. "25.08.13". -export fsdk_version := `grep -oE 'freedesktop-sdk-[0-9]+\.[0-9]+\.[0-9]+' elements/freedesktop-sdk.bst | head -1 | sed 's/freedesktop-sdk-//'` +# FSDK point release of the pinned junction ref, e.g. "26.08.0". +# check-release-version.py is its one parser. +export fsdk_version := `python3 .github/scripts/check-release-version.py --print-fsdk` # Exact junction commit ref (full ref: value), for provenance. export fsdk_ref := `grep -E '^\s*ref:' elements/freedesktop-sdk.bst | head -1 | sed -E 's/^\s*ref:\s*//'` diff --git a/docs/skills/bump-fsdk-version.md b/docs/skills/bump-fsdk-version.md index 3a7d4407..b0f08583 100644 --- a/docs/skills/bump-fsdk-version.md +++ b/docs/skills/bump-fsdk-version.md @@ -19,15 +19,17 @@ There is no application version for these images. Two version axes exist: - `installer-version` in `project.conf` tracks the pinned FSDK point release (the `ref:` line in `elements/freedesktop-sdk.bst`, e.g. `freedesktop-sdk-26.08.0-...`). `.github/scripts/check-release-version.py` - fails closed on drift between the two. + fails closed on drift between the two, and is the one parser of that point + release: `--print-fsdk` prints it (the Justfile's `fsdk_version`), `--fix` + syncs `installer-version` to it before checking. - `image-version` in `include/image.yml` is the per-build OS version shared by the usr DDI, the UKIs, and sysupdate transfers. CI sets it with `just set-version` (`YY.MM.` on main, `0.` on PRs); `systemd-sysupdate` orders it with `strverscmp()`, so keep it monotonic and at most 17 characters. -`just version` / `just tags` parse the FSDK-derived point release and tag set -(`latest`, minor line, point release) from the junction ref. +`just version` / `just tags` print the FSDK-derived point release and tag set +(`latest`, minor line, point release), from `check-release-version.py --print-fsdk`. ## Procedure @@ -92,7 +94,7 @@ Before merging a bump: Point releases are delivered by the scheduled `track-junctions.yml` workflow. - **Trigger:** `track-junctions.yml` runs daily and resolves the junction's own `track: freedesktop-sdk-26.08*` glob; it does not wait on a Renovate PR. -- **Mechanism:** `track-junctions.yml` runs `just bst source track freedesktop-sdk.bst`, syncs `project.conf`'s `installer-version` to the tracked point release, and opens its own PR on `auto/track-junctions`. It never runs on `pull_request`, so a junction bump can never be injected into an unrelated dependency PR. +- **Mechanism:** `track-junctions.yml` runs `just bst source track freedesktop-sdk.bst`, syncs `project.conf`'s `installer-version` to the tracked point release (`check-release-version.py --fix`), and opens or updates its own PR on `auto/track-junctions` through `.github/scripts/propose-pr.sh`, which leaves an open PR alone when it already proposes the same refs. It never runs on `pull_request`, so a junction bump can never be injected into an unrelated dependency PR. - **Build Loop:** When the PR is merged to `main`, GitHub Actions compiles the image set (OS DDI, UKIs, netboot ESP) and sysexts, and publishes them to a new GitHub Release tagged `v`. ## See also diff --git a/docs/skills/ci-tooling.md b/docs/skills/ci-tooling.md index 86c0d5e7..512ad032 100644 --- a/docs/skills/ci-tooling.md +++ b/docs/skills/ci-tooling.md @@ -53,9 +53,11 @@ a binary chosen by an upstream release rather than by a commit in this repo. tool: just@1.58.0 ``` -The version is repeated at each call site — currently `build.yml`, -`unit-tests.yml`, and `track-junctions.yml`. Bumping `just` means changing all -of them in one commit, so CI never runs two versions at once. +The version is repeated at each call site — currently six steps in four +workflows: `build.yml` (three jobs), `reproducibility.yml`, `unit-tests.yml` +and `track-junctions.yml`. Bumping `just` means changing all of them in one +commit, so CI never runs two versions at once; +`tests/unit/test_ci_tool_pins.py` fails if they drift. ### Workflow permissions @@ -84,7 +86,7 @@ Junction ref tracking must never run on `pull_request`. It used to, as a `track-refs` job gated on `startsWith(github.head_ref, 'renovate/')`, and a branch name is not an identity. It also pushed its result onto whatever PR branch happened to be open, so unrelated dependency PRs silently carried -freedesktop-sdk and gnome-build-meta bumps. It now lives in +freedesktop-sdk junction bumps. It now lives in `track-junctions.yml` on a schedule, opening its own PR on its own branch. The `build` job (validation, compile, signing) runs with the read-only default @@ -180,8 +182,16 @@ use: remove only this repository from their repository access. | `unit` | `unit-tests.yml` | `pull_request`, `push/main` | Runs pytest and BATS unit test suites. Read-only token. | | `check`, `propose` | `track-binaries.yml` | `schedule` (08:30 UTC), `workflow_dispatch` | `check` finds the newest patch release in each pinned series of the upstream components pinned by version + sha256 (Kubernetes, cri-tools, containerd, runc, CNI plugins, k0s, each NVIDIA driver flavour inside its branch, ORAS) or by version + git commit (NVIDIA Container Toolkit), and the newest dated snapshot of the IANA registries behind `/etc/protocols` and `/etc/services` (`iana-etc`, no series), with `.github/scripts/track-binaries.py`; `propose` moves each version together with its sha256 pins for every pinned architecture (amd64 and the `arch == "aarch64"` sources), verified against upstream's checksum files and the downloaded assets (a git commit: the GitHub API and `git ls-remote` must agree), and opens or updates one PR per component on `auto/track-binaries/`. Minor bumps stay manual (`kubeadm-sysext.md`, `k0s-sysext.md`); a new NVIDIA branch is a new flavour (`nvidia-sysext.md`). Read-only `GITHUB_TOKEN`; writes use the mergeraptor app token (`trackers` environment, `propose` only), minted after the apply step and narrowed to `contents` + `pull-requests` (+ `workflows` for ORAS, pinned in `build.yml`). Never on `pull_request`. | +Both trackers commit, push and open or update their pull request through +`.github/scripts/propose-pr.sh`. It pushes nothing when the paths already +match `main`, or when an open PR's branch already holds the same content, so +a daily run neither force-pushes an identical commit nor restarts that PR's +build; `track-binaries` also passes `--skip-closed-title`, so a release +whose PR was closed is not proposed again. + GitHub Actions runs the **complete BuildStream compilation pipeline** using `/mnt` -SSD storage on the runner for podman and BuildStream caches. Release assets are +SSD storage on the runner for podman and BuildStream caches +(`scripts/ci-runner-disk.sh`, called by every job that builds). Release assets are uploaded to a GitHub Release tagged `v` (`YY.MM.` on main). ## Core Process @@ -189,81 +199,90 @@ uploaded to a GitHub Release tagged `v` (`YY.MM.` on main). 1. **Renovate tracking:** `renovate.json` is configured with a custom regex manager to scan the BuildStream junction (`freedesktop-sdk.bst`) using the `git-refs` datasource. - 2. **Auto-resolution:** The scheduled `track-junctions` workflow executes - `just bst source track` to resolve raw tags to full `git-describe` refs, - syncs `installer-version` to the tracked FSDK point release, and proposes the - result as its own pull request against `main`. - 3. **Full Compilation:** Builds the OS DDI, signed UKIs, netboot ESP, and the - k0s, KubeStellar, kubeadm, OpenZFS and NVIDIA systemd-sysext assets for every push to - `main`, every night, and on pull requests that carry `full-build` or change - the FSDK junction or its patches, and signs the combined `SHA256SUMS` - inside `oci/bluefin-server-image.bst` (gpg sign plus a `gpgv` proof - against the shipped keyring). Other pull requests run `validate`. - 4. **Boot test:** Downloads the exported image sets and runs, in QEMU with - Secure Boot OVMF, each as one `scripts/dogfood-diskless.sh --check` or - `scripts/dogfood-install.sh` or `scripts/dogfood-installer.sh` call. The firmware is Fedora's - `edk2-ovmf` (Koji URL + SHA-256 in `build.yml`), not Ubuntu's `ovmf`: - Ubuntu 26.04's OVMF 2025.11 rejects systemd-boot's PK enrollment - (`Failed to write PK secure boot variable: Security violation`), and - until this was caught every CI boot ran in setup mode with Secure Boot - off. `--check` now fails unless the probe reports - `secureboot=enabled` (or, for tamper runs, the kernel logs - `Secure boot enabled`). Bump the pin by hand; Renovate does not track it. - - diskless netboot, no failed units; `tests/fixtures/nfs/netdb.probe` - must see `tcp` and `sunrpc` resolve, the local portmapper answer - `rpcinfo`, and an NFSv3 mount get past the protocol lookup - (`DOGFOOD_EXPECT`); - - `DOGFOOD_TAMPER=raw`: a corrupted DDI must be refused by the manifest - check (`DOWNLOAD INVALID: Checksum of ... did not check out`); - `DOGFOOD_TAMPER=sums`: the same DDI with `SHA256SUMS` re-hashed to match - it must be refused by the signature check (`DOWNLOAD INVALID: Signature - verification failed`). Both only after the image, `SHA256SUMS` and - `SHA256SUMS.gpg` were served, and nothing may boot; - - Ignition from the `ignition.config` credential, and UEFI HTTP boot with - `bluefin-node.ign` served next to the UKI, both with - `tests/fixtures/ignition/apply-marker.ign`: the probe must see the - written file and the Ignition-enabled unit active (`DOGFOOD_EXPECT`); - - releases: diskless boot, `systemd-sysinstall` to disk, boot the disk; - - every other build (the nightly build of `main`, `full-build` and FSDK - pull requests, dispatches): the same, then `systemd-sysupdate` A->B to - `1..1` and a boot-counted rollback from a corrupted `1..2`, - with the ZFS and NVIDIA sysexts merged together - (`DOGFOOD_SYSEXT=zfs,nvidia`; see - [ddi-installer-build.md](ddi-installer-build.md), also for why not - `0..N`). Releases skip this because their extra sets would be - release-signed versions nobody publishes; the nightly dev-key build of - `main` runs it instead. - - `scripts/dogfood-installer.sh`: the offline USB installer installs - unattended onto a blank disk, which then boots with and without the - installer attached. Outside releases it then gets `1..1` - (`dist/diskless-next`) the way a PC installed from the stick does: - an unreachable and a foreign-signed source must fail - `systemd-sysupdate.service` and show on the login banner, the update - must stage, boot and be blessed (see "Update health on the node" in - [systemd-sysupdate-verification.md](systemd-sysupdate-verification.md)). - Two more runs install onto disks that are not empty (#359): again over - a Bluefin install (`DOGFOOD_TARGET=prior-install`) and over another - OS's GPT disk (`DOGFOOD_TARGET=foreign-gpt`). - 5. **Version Derivation:** The release version is set per build with - `just set-version`: `YY.MM.` for releases, `0.` for every other - build so it can never sort above a release. - 6. **Automated Publishing:** For pushes to `main` (including Renovate PR - merges), GitHub Actions publishes `dist/diskless/` as-is: an immutable - GitHub Release `v` and an ORAS OCI artifact - `ghcr.io//bluefin-server:,latest`. Nodes verify updates - against the `SHA256SUMS` / `SHA256SUMS.gpg` already in that set. Every - pull request that builds rehearses this path in `release-dry-run`, so the - publish code is exercised before it first runs on main. Attestations, the SBOM - and the verify commands are in - [`systemd-sysupdate-verification.md`](systemd-sysupdate-verification.md). +2. **Auto-resolution:** The scheduled `track-junctions` workflow executes + `just bst source track` to resolve raw tags to full `git-describe` refs, + syncs `installer-version` to the tracked FSDK point release, and proposes the + result as its own pull request against `main`. +3. **Full Compilation:** Builds the OS DDI, signed UKIs, netboot ESP, and the + k0s, KubeStellar, kubeadm, OpenZFS and NVIDIA systemd-sysext assets for every push to + `main`, every night, and on pull requests that carry `full-build` or change + the FSDK junction or its patches, and signs the combined `SHA256SUMS` + inside `oci/bluefin-server-image.bst` (gpg sign plus a `gpgv` proof + against the shipped keyring). Other pull requests run `validate`. +4. **Boot test:** Downloads the exported image sets and runs, in QEMU with + Secure Boot OVMF, each as one `scripts/dogfood-diskless.sh --check` or + `scripts/dogfood-install.sh` or `scripts/dogfood-installer.sh` call. The firmware is Fedora's + `edk2-ovmf` (Koji URL + SHA-256 in `build.yml`), not Ubuntu's `ovmf`: + Ubuntu 26.04's OVMF 2025.11 rejects systemd-boot's PK enrollment + (`Failed to write PK secure boot variable: Security violation`), and + until this was caught every CI boot ran in setup mode with Secure Boot + off. `--check` now fails unless the probe reports + `secureboot=enabled` (or, for tamper runs, the kernel logs + `Secure boot enabled`). Bump the pin by hand; Renovate does not track it. + - diskless netboot, no failed units; `tests/fixtures/nfs/netdb.probe` + must see `tcp` and `sunrpc` resolve, the local portmapper answer + `rpcinfo`, and an NFSv3 mount get past the protocol lookup + (`DOGFOOD_EXPECT`); + - `DOGFOOD_TAMPER=raw`: a corrupted DDI must be refused by the manifest + check (`DOWNLOAD INVALID: Checksum of ... did not check out`); + `DOGFOOD_TAMPER=sums`: the same DDI with `SHA256SUMS` re-hashed to match + it must be refused by the signature check (`DOWNLOAD INVALID: Signature + verification failed`). Both only after the image, `SHA256SUMS` and + `SHA256SUMS.gpg` were served, and nothing may boot; + - Ignition from the `ignition.config` credential, and UEFI HTTP boot with + `bluefin-node.ign` served next to the UKI, both with + `tests/fixtures/ignition/apply-marker.ign`: the probe must see the + written file and the Ignition-enabled unit active (`DOGFOOD_EXPECT`); + - releases: diskless boot, `systemd-sysinstall` to disk, boot the disk; + - every other build (the nightly build of `main`, `full-build` and FSDK + pull requests, dispatches): the same, then `systemd-sysupdate` A->B to + `1..1` and a boot-counted rollback from a corrupted `1..2`, + with the ZFS and NVIDIA sysexts merged together + (`DOGFOOD_SYSEXT=zfs,nvidia`; see + [ddi-installer-build.md](ddi-installer-build.md), also for why not + `0..N`). Releases skip this because their extra sets would be + release-signed versions nobody publishes; the nightly dev-key build of + `main` runs it instead. + - `scripts/dogfood-installer.sh`: the offline USB installer installs + unattended onto a blank disk, which then boots with and without the + installer attached. Outside releases it then gets `1..1` + (`dist/diskless-next`) the way a PC installed from the stick does: + an unreachable and a foreign-signed source must fail + `systemd-sysupdate.service` and show on the login banner, the update + must stage, boot and be blessed (see "Update health on the node" in + [systemd-sysupdate-verification.md](systemd-sysupdate-verification.md)). + Two more runs install onto disks that are not empty (#359): again over + a Bluefin install (`DOGFOOD_TARGET=prior-install`) and over another + OS's GPT disk (`DOGFOOD_TARGET=foreign-gpt`). +5. **Version Derivation:** The release version is set per build with + `just set-version`: `YY.MM.` for releases, `0.` for every other + build so it can never sort above a release. +6. **Automated Publishing:** For pushes to `main` (including Renovate PR + merges), GitHub Actions publishes `dist/diskless/` as-is: an immutable + GitHub Release `v` and an ORAS OCI artifact + `ghcr.io//bluefin-server:,latest`. Nodes verify updates + against the `SHA256SUMS` / `SHA256SUMS.gpg` already in that set. Every + pull request that builds rehearses this path in `release-dry-run`, so the + publish code is exercised before it first runs on main. Attestations, the SBOM + and the verify commands are in + [`systemd-sysupdate-verification.md`](systemd-sysupdate-verification.md). ## Build time and caches -Measured on run 36499270842 (pull request, cold runner): `Build and export the -image set` took 2 h. BuildStream pulled 239 artifacts and built 85 (about 3.9 h -of build time over 4 cores). The critical path is FSDK's -`components/linux.bst`: 6 min to fetch its source (not in any source cache) -and 1 h 43 min to build. FSDK's caches never hold it for us, because the +The canonical build-time figures; other files link here instead of +restating them: + +- **Full image build:** the `build` job on `main` takes a median of about + 50 min and a 90th percentile of about 2 h (56 successful runs, + 2026-09-24 to 2026-10-04). The slow runs are the ones that compile the + kernel. +- **FSDK's kernel when no cache holds it:** 1 h 43 min to build, plus 6 min + to fetch its source; it is the critical path of a cold build. + +Where a cold build's time goes (run 36499270842, pull request, cold runner): +BuildStream pulled 239 artifacts and built 85 (about 3.9 h of build time over +4 cores), with FSDK's `components/linux.bst` on the critical path. FSDK's +caches never hold it for us, because the `components/linux-module-cert.bst` junction override (our module certificate) and `patches/freedesktop-sdk/0006-linux-*.patch` change its cache key. The other ~70 min of parallel build time on that run came from about 40 FSDK @@ -328,8 +347,8 @@ version) and the NVIDIA Container Toolkit (Go); the driver sysext adds about `nvidia-open-*-signed.bst` elements build-depend on it, so a release build's own cache must never be saved or pushed anywhere a pull request can read. -- **Most pull requests do not build the image.** The full build costs about - 1.5 h, most of it FSDK's kernel, so a pull request builds only with the +- **Most pull requests do not build the image.** The full build costs up to + 2 h (figures above), most of it FSDK's kernel, so a pull request builds only with the `full-build` label or when it changes `elements/freedesktop-sdk.bst` or `patches/` (an untested FSDK bump would otherwise merge unbuilt); the rest run `validate`. A regression outside those paths shows up in the next diff --git a/docs/skills/ddi-installer-build.md b/docs/skills/ddi-installer-build.md index b6af64ba..f9020a7e 100644 --- a/docs/skills/ddi-installer-build.md +++ b/docs/skills/ddi-installer-build.md @@ -89,7 +89,10 @@ Two outputs carry a signing time of their own: `SHA256SUMS.gpg` and the (they stay fixed as long as `bluefin-server/keys/efi-keys.bst` stays cached). `.github/workflows/reproducibility.yml` checks the rest weekly: it builds, deletes the final-assembly artifacts, rebuilds them without remote -caches, and compares every file except `*.gpg`. +caches, and compares every file except `*.gpg`. The final assembly +(`FINAL_ASSEMBLY`) is everything `oci/bluefin-server-image.bst` stages into +the release set plus every `oci/*` target `just validate` resolves; +`tests/unit/test_reproducibility_workflow.py` fails when a shipped element is missing. ## Dogfood: boot it in QEMU diff --git a/scripts/ci-runner-disk.sh b/scripts/ci-runner-disk.sh new file mode 100755 index 00000000..a069c75b --- /dev/null +++ b/scripts/ci-runner-disk.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# Put podman's container storage and BuildStream's cache on the GitHub +# runner's large /mnt disk; the root disk cannot hold a kernel build (15 GB) +# next to the bst2 image. +# +# bash scripts/ci-runner-disk.sh +# +# CI_RUNNER_MNT overrides /mnt (tests). Safe to run more than once: `ln -sfn` +# replaces the cache symlink instead of creating a link inside the directory +# it points to. +set -euo pipefail + +mnt="${CI_RUNNER_MNT:-/mnt}" +uid="$(id -u)" + +sudo mkdir -p "${mnt}/podman" "${mnt}/buildstream" +sudo chown -R "${uid}:$(id -g)" "${mnt}/podman" "${mnt}/buildstream" + +mkdir -p "${HOME}/.config/containers" +cat > "${HOME}/.config/containers/storage.conf" < CASD_CLIENT_KEY= kernel-cache.sh seed # -# The kernel is about 70 of the ~85 build minutes and no upstream cache holds -# it: its cache key depends on the module certificate it trusts (the +# The kernel is most of a cold build (figures: docs/skills/ci-tooling.md, +# "Build time and caches") and no upstream cache holds it: its cache key +# depends on the module certificate it trusts (the # linux-module-cert junction override) and on the patches in # patches/freedesktop-sdk/ that edit its config (0006 kubenet, 0007 watchdog). # Both the seed job and release builds stage the committed release diff --git a/tests/unit/test_ci_runner_disk.py b/tests/unit/test_ci_runner_disk.py new file mode 100644 index 00000000..70205e03 --- /dev/null +++ b/tests/unit/test_ci_runner_disk.py @@ -0,0 +1,52 @@ +"""scripts/ci-runner-disk.sh is the one runner disk setup, and is safe to run twice.""" + +from __future__ import annotations + +import os +import subprocess +from pathlib import Path + +import pytest +import yaml + +ROOT = Path(__file__).resolve().parents[2] +WORKFLOWS = ROOT / ".github" / "workflows" +DISK_SCRIPT = ROOT / "scripts" / "ci-runner-disk.sh" + + +@pytest.mark.parametrize("workflow", sorted(p.name for p in WORKFLOWS.glob("*.yml"))) +def test_runner_disk_setup_is_not_inlined(workflow: str) -> None: + text = (WORKFLOWS / workflow).read_text() + assert "graphroot" not in text and "ln -sf" not in text, f"{workflow}: use scripts/ci-runner-disk.sh" + + +def test_every_build_job_sets_up_the_runner_disk() -> None: + for workflow, job in (("build.yml", "kernel-cache"), ("build.yml", "build"), + ("reproducibility.yml", "reproducibility")): + steps = yaml.safe_load((WORKFLOWS / workflow).read_text())["jobs"][job]["steps"] + assert any(s.get("run") == "bash scripts/ci-runner-disk.sh" for s in steps), f"{workflow}:{job}" + + +@pytest.fixture +def runner(tmp_path: Path) -> dict[str, str]: + bin_dir = tmp_path / "bin" + bin_dir.mkdir() + (bin_dir / "sudo").write_text('#!/bin/sh\nexec "$@"\n') + (bin_dir / "sudo").chmod(0o755) + (tmp_path / "home").mkdir() + return {**os.environ, "PATH": f"{bin_dir}:{os.environ['PATH']}", "HOME": str(tmp_path / "home"), + "CI_RUNNER_MNT": str(tmp_path / "mnt")} + + +def test_runner_disk_moves_podman_and_buildstream_to_mnt(runner: dict[str, str]) -> None: + for _ in range(2): + subprocess.run(["bash", str(DISK_SCRIPT)], env=runner, check=True) + home, mnt = Path(runner["HOME"]), Path(runner["CI_RUNNER_MNT"]) + conf = (home / ".config" / "containers" / "storage.conf").read_text() + assert f'graphroot = "{mnt}/podman"' in conf + assert f'runroot = "/run/user/{os.getuid()}"' in conf and 'driver = "overlay"' in conf + cache = home / ".cache" / "buildstream" + assert cache.is_symlink() and os.readlink(cache) == f"{mnt}/buildstream" + # `ln -sf` on the second run would have put a link inside the target. + assert list((mnt / "buildstream").iterdir()) == [] + assert (mnt / "podman").is_dir() diff --git a/tests/unit/test_ci_tool_pins.py b/tests/unit/test_ci_tool_pins.py new file mode 100644 index 00000000..edb8984f --- /dev/null +++ b/tests/unit/test_ci_tool_pins.py @@ -0,0 +1,26 @@ +"""Every workflow installs the same `just`, so CI never runs two versions at once.""" + +from __future__ import annotations + +from pathlib import Path + +import yaml + +WORKFLOWS = Path(__file__).resolve().parents[2] / ".github" / "workflows" + + +def just_installs() -> list[tuple[str, str, str]]: + found = [] + for path in sorted(WORKFLOWS.glob("*.yml")): + for name, job in yaml.safe_load(path.read_text(encoding="utf-8"))["jobs"].items(): + for step in job.get("steps", []): + tool = str(step.get("with", {}).get("tool", "")) + if step.get("uses", "").startswith("taiki-e/install-action@") and tool.startswith("just@"): + found.append((f"{path.name}:{name}", step["uses"], tool)) + return found + + +def test_just_is_pinned_identically_everywhere() -> None: + installs = just_installs() + assert len(installs) >= 6, installs + assert len({(uses, tool) for _, uses, tool in installs}) == 1, installs diff --git a/tests/unit/test_propose_pr.py b/tests/unit/test_propose_pr.py new file mode 100644 index 00000000..0e1282eb --- /dev/null +++ b/tests/unit/test_propose_pr.py @@ -0,0 +1,208 @@ +""".github/scripts/propose-pr.sh: the trackers' "create or update the PR" step. + +Runs the script in a real git checkout whose origin is a local bare +repository, with `gh` stubbed. The contract: propose nothing when the paths +match HEAD; leave an open pull request alone when its branch already holds the +same content (no daily force-push, no restarted CI); push and edit it when the +content differs; open one otherwise; with --skip-closed-title, never reopen a +title that was turned down; and stop, without pushing, when `gh` fails. +""" + +from __future__ import annotations + +import os +import subprocess +from pathlib import Path + +import pytest + +ROOT = Path(__file__).resolve().parents[2] +SCRIPT = ROOT / ".github" / "scripts" / "propose-pr.sh" +BRANCH = "auto/track-test" +TITLE = "chore(deps): update thing 1.0 -> 1.1" + +GH = """#!/bin/sh +echo "$*" >> "$LOG/gh" +[ -z "$GH_FAIL" ] || { echo "gh: HTTP 502" >&2; exit 1; } +case "$*" in + "pr list"*"--state open"*) [ -z "$OPEN_PR" ] || echo "$OPEN_PR" ;; + "pr list"*"--state closed"*) [ -z "$CLOSED_TITLES" ] || printf '%s\\n' "$CLOSED_TITLES" ;; + "pr create"*) echo "https://github.com/o/r/pull/99" ;; + "pr view"*) echo "https://github.com/o/r/pull/$OPEN_PR" ;; +esac +""" + + +def git(cwd: Path, *args: str) -> str: + env = {**os.environ, "GIT_AUTHOR_NAME": "t", "GIT_AUTHOR_EMAIL": "t@t", "GIT_COMMITTER_NAME": "t", + "GIT_COMMITTER_EMAIL": "t@t"} + return subprocess.run(["git", *args], cwd=cwd, env=env, check=True, capture_output=True, text=True).stdout.strip() + + +@pytest.fixture +def repo(tmp_path: Path) -> Path: + remote = tmp_path / "remote.git" + git(tmp_path, "init", "--quiet", "--bare", "--initial-branch=main", str(remote)) + work = tmp_path / "work" + git(tmp_path, "clone", "--quiet", str(remote), str(work)) + (work / "pin.txt").write_text("1.0\n") + (work / "other.txt").write_text("x\n") + git(work, "add", ".") + git(work, "commit", "--quiet", "-m", "base") + git(work, "push", "--quiet", "origin", "HEAD:main") + return work + + +@pytest.fixture +def env(tmp_path: Path) -> dict[str, str]: + bin_dir = tmp_path / "bin" + bin_dir.mkdir() + (bin_dir / "gh").write_text(GH) + (bin_dir / "gh").chmod(0o755) + log = tmp_path / "log" + log.mkdir() + (tmp_path / "body.md").write_text("body\n") + inherited = {k: v for k, v in os.environ.items() if not k.startswith(("GIT_AUTHOR_", "GIT_COMMITTER_"))} + return {**inherited, "PATH": f"{bin_dir}:{os.environ['PATH']}", "LOG": str(log), "OPEN_PR": "", + "CLOSED_TITLES": "", "GH_FAIL": "", "BODY": str(tmp_path / "body.md")} + + +def propose(repo: Path, env: dict[str, str], *extra: str) -> subprocess.CompletedProcess: + return subprocess.run( + ["bash", str(SCRIPT), "--branch", BRANCH, "--title", TITLE, "--body-file", env["BODY"], *extra, + "--", "pin.txt"], + cwd=repo, env=env, capture_output=True, text=True, + ) + + +def remote_branch(repo: Path) -> str: + return git(repo, "ls-remote", "origin", f"refs/heads/{BRANCH}") + + +def gh_calls(env: dict[str, str]) -> list[str]: + log = Path(env["LOG"]) / "gh" + return log.read_text().splitlines() if log.exists() else [] + + +def push_branch_with(repo: Path, content: str) -> str: + git(repo, "checkout", "--quiet", "-b", "earlier") + (repo / "pin.txt").write_text(content) + git(repo, "commit", "--quiet", "-am", "earlier proposal") + git(repo, "push", "--quiet", "origin", f"HEAD:refs/heads/{BRANCH}") + git(repo, "checkout", "--quiet", "main") + git(repo, "branch", "--quiet", "-D", "earlier") + git(repo, "update-ref", "-d", f"refs/remotes/origin/{BRANCH}") + return remote_branch(repo).split()[0] + + +def test_nothing_to_propose_touches_nothing(repo: Path, env: dict[str, str]) -> None: + result = propose(repo, env) + assert result.returncode == 0, result.stderr + assert "Nothing to propose" in result.stdout + assert remote_branch(repo) == "" + assert gh_calls(env) == [] + + +def test_opens_a_pull_request_on_a_new_branch(repo: Path, env: dict[str, str]) -> None: + (repo / "pin.txt").write_text("1.1\n") + (repo / "other.txt").write_text("unrelated local change\n") + result = propose(repo, env) + assert result.returncode == 0, result.stderr + assert "Created PR: https://github.com/o/r/pull/99" in result.stdout + head = remote_branch(repo).split()[0] + assert git(repo, "show", f"{head}:pin.txt") == "1.1" + assert git(repo, "show", f"{head}:other.txt") == "x", "only the named paths are committed" + assert git(repo, "log", "-1", "--format=%s%n%an%n%b", head).splitlines() == [TITLE, "github-actions[bot]"] + assert any(c.startswith(f"pr create --base main --head {BRANCH} --title {TITLE}") for c in gh_calls(env)) + + +def test_open_pull_request_with_identical_content_is_left_alone(repo: Path, env: dict[str, str]) -> None: + before = push_branch_with(repo, "1.1\n") + env["OPEN_PR"] = "7" + (repo / "pin.txt").write_text("1.1\n") + result = propose(repo, env) + assert result.returncode == 0, result.stderr + assert "#7 already proposes this content" in result.stdout + assert remote_branch(repo).split()[0] == before, "no new commit, no force-push" + assert not any(c.startswith(("pr edit", "pr create")) for c in gh_calls(env)) + + +def test_open_pull_request_with_other_content_is_updated(repo: Path, env: dict[str, str]) -> None: + before = push_branch_with(repo, "1.1\n") + env["OPEN_PR"] = "7" + (repo / "pin.txt").write_text("1.2\n") + result = propose(repo, env) + assert result.returncode == 0, result.stderr + after = remote_branch(repo).split()[0] + assert after != before + assert git(repo, "show", f"{after}:pin.txt") == "1.2" + assert f"pr edit 7 --title {TITLE} --body-file {env['BODY']}" in gh_calls(env) + assert "Updated PR: https://github.com/o/r/pull/7" in result.stdout + + +def test_stale_branch_without_a_pull_request_is_replaced(repo: Path, env: dict[str, str]) -> None: + push_branch_with(repo, "1.1\n") + (repo / "pin.txt").write_text("1.1\n") + result = propose(repo, env) + assert result.returncode == 0, result.stderr + assert "Created PR" in result.stdout + head = remote_branch(repo).split()[0] + assert git(repo, "log", "-1", "--format=%s", head) == TITLE + + +@pytest.mark.parametrize("skip_closed", [True, False]) +def test_closed_title_is_only_respected_on_request(repo: Path, env: dict[str, str], skip_closed: bool) -> None: + env["CLOSED_TITLES"] = f"something else\n{TITLE}" + (repo / "pin.txt").write_text("1.1\n") + result = propose(repo, env, *(["--skip-closed-title"] if skip_closed else [])) + assert result.returncode == 0, result.stderr + if skip_closed: + assert "not reopening it" in result.stdout + assert remote_branch(repo) == "" + else: + assert "Created PR" in result.stdout + assert remote_branch(repo) != "" + + +def test_a_failed_query_stops_before_pushing(repo: Path, env: dict[str, str]) -> None: + env["GH_FAIL"] = "1" + (repo / "pin.txt").write_text("1.1\n") + result = propose(repo, env) + assert result.returncode != 0 + assert remote_branch(repo) == "" + + +def test_an_unreachable_remote_stops_before_querying(repo: Path, env: dict[str, str]) -> None: + git(repo, "remote", "set-url", "origin", str(repo.parent / "missing.git")) + (repo / "pin.txt").write_text("1.1\n") + result = propose(repo, env) + assert result.returncode != 0 + assert "cannot list" in result.stderr + assert gh_calls(env) == [] + + +@pytest.mark.parametrize("args", [[], ["--branch", BRANCH], ["--branch", BRANCH, "--title", TITLE]]) +def test_requires_branch_title_and_body(repo: Path, env: dict[str, str], args: list[str]) -> None: + result = subprocess.run(["bash", str(SCRIPT), *args, "--", "pin.txt"], cwd=repo, env=env, + capture_output=True, text=True) + assert result.returncode != 0 + assert gh_calls(env) == [] + + +def test_both_trackers_propose_through_the_script() -> None: + for name, extra in (("track-junctions.yml", ""), ("track-binaries.yml", "--skip-closed-title")): + text = (ROOT / ".github" / "workflows" / name).read_text() + assert "bash .github/scripts/propose-pr.sh" in text, name + assert extra in text + for inline in ("gh pr create", "gh pr edit", "git push", "git commit -"): + assert inline not in text, f"{name} still inlines {inline}" + + +def test_the_token_is_used_for_the_push_but_never_stored(repo: Path, env: dict[str, str]) -> None: + env["GH_TOKEN"] = "ghs_secret_value" + (repo / "pin.txt").write_text("1.1\n") + result = propose(repo, env) + assert result.returncode == 0, result.stderr + assert remote_branch(repo) != "" + assert "ghs_secret_value" not in (repo / ".git" / "config").read_text() + assert "ghs_secret_value" not in result.stdout + result.stderr diff --git a/tests/unit/test_release_version.py b/tests/unit/test_release_version.py index ee3c4a5c..46d9f499 100644 --- a/tests/unit/test_release_version.py +++ b/tests/unit/test_release_version.py @@ -198,6 +198,61 @@ def test_main_installer_drift_is_detected_across_minor_lines(checker): assert "installer-version drift" in str(excinfo.value) +# --- --print-fsdk / --fix --------------------------------------------------- + + +def test_print_fsdk_prints_only_the_pinned_point_release(checker, capsys): + _write(checker, installer_declared="25.08.0", fsdk_pinned="26.08.3") + checker.main(["--print-fsdk"]) + assert capsys.readouterr().out == "26.08.3\n" + + +def test_print_fsdk_fails_without_a_point_release(checker): + checker.FSDK_JUNCTION.write_text("junction:\n track: freedesktop-sdk-26.08*\n", encoding="utf-8") + with pytest.raises(SystemExit) as excinfo: + checker.main(["--print-fsdk"]) + assert "no 'freedesktop-sdk-X.Y.Z' point release" in str(excinfo.value) + + +@pytest.mark.parametrize("declared", ['"26.08.0"', "26.08.0", "'25.08.9'", '"garbage"', ""]) +def test_fix_syncs_installer_version_and_keeps_the_rest(checker, capsys, declared): + checker.PROJECT_CONF.write_text( + f"# installer-version: 1.2.3\nvariables:\n installer-version: {declared}\n other: x\n", + encoding="utf-8", + ) + checker.FSDK_JUNCTION.write_text(" ref: freedesktop-sdk-26.08.1-0-gdb97cce\n", encoding="utf-8") + checker.main(["--fix"]) + assert checker.PROJECT_CONF.read_text(encoding="utf-8") == ( + '# installer-version: 1.2.3\nvariables:\n installer-version: "26.08.1"\n other: x\n' + ) + assert "OK: installer-version 26.08.1" in capsys.readouterr().out + + +def test_fix_still_fails_when_installer_version_is_not_declared(checker): + checker.PROJECT_CONF.write_text("variables:\n other: 1\n", encoding="utf-8") + checker.FSDK_JUNCTION.write_text("ref: freedesktop-sdk-26.08.0\n", encoding="utf-8") + with pytest.raises(SystemExit) as excinfo: + checker.main(["--fix"]) + assert "does not declare an 'installer-version" in str(excinfo.value) + + +def test_fix_and_print_fsdk_are_exclusive(checker): + _write(checker) + with pytest.raises(SystemExit): + checker.main(["--fix", "--print-fsdk"]) + + +def test_callers_use_the_script_instead_of_parsing_the_junction(): + """One parser of the FSDK point release: the Justfile and track-junctions call it.""" + justfile = (REPO_ROOT / "Justfile").read_text(encoding="utf-8") + fsdk_version = next(line for line in justfile.splitlines() if line.startswith("export fsdk_version")) + assert "check-release-version.py --print-fsdk" in fsdk_version + tracker = (REPO_ROOT / ".github" / "workflows" / "track-junctions.yml").read_text(encoding="utf-8") + assert "check-release-version.py --fix" in tracker + for text in (justfile, tracker): + assert "freedesktop-sdk-[0-9]" not in text + + # --- live repository invariant ------------------------------------------- diff --git a/tests/unit/test_reproducibility_workflow.py b/tests/unit/test_reproducibility_workflow.py new file mode 100644 index 00000000..fb5b1d6b --- /dev/null +++ b/tests/unit/test_reproducibility_workflow.py @@ -0,0 +1,53 @@ +"""reproducibility.yml rebuilds everything that ships. + +Every element oci/bluefin-server-image.bst stages into the release set and +every oci/* target `just validate` resolves must be in FINAL_ASSEMBLY, or its +cached artifact is reused by the second build and never compared. +""" + +from __future__ import annotations + +import re +from pathlib import Path + +import yaml + +ROOT = Path(__file__).resolve().parents[2] +WORKFLOWS = ROOT / ".github" / "workflows" +IMAGE = ROOT / "elements" / "oci" / "bluefin-server-image.bst" + + +def final_assembly() -> set[str]: + job = yaml.safe_load((WORKFLOWS / "reproducibility.yml").read_text())["jobs"]["reproducibility"] + return set(job["env"]["FINAL_ASSEMBLY"].split()) + + +def staged_into_release_set() -> set[str]: + """Dependencies the image element stages at a location: its payload.""" + element = yaml.safe_load(IMAGE.read_text()) + deps = element.get("build-depends", []) + element.get("depends", []) + return {d["filename"] for d in deps if isinstance(d, dict) and "location" in d.get("config", {})} + + +def validate_targets() -> set[str]: + recipe = (ROOT / "Justfile").read_text().split("\nvalidate:", 1)[1].split("\n\n", 1)[0] + return set(re.findall(r"\boci/[\w.-]+\.bst\b", recipe)) + + +def test_shipped_set_is_derived_from_the_build() -> None: + staged, validated = staged_into_release_set(), validate_targets() + assert {"oci/bluefin-server-usr.bst", "oci/bluefin-server-sbom.bst", "oci/nvidia-open-595-sysext.bst"} <= staged + assert "oci/bluefin-server-image.bst" in validated + assert "oci/nvidia-container-toolkit-sysext.bst" in validated + + +def test_reproducibility_rebuilds_everything_that_ships() -> None: + missing = (staged_into_release_set() | validate_targets()) - final_assembly() + assert not missing, f"add to FINAL_ASSEMBLY in reproducibility.yml: {sorted(missing)}" + + +def test_final_assembly_names_real_elements_and_keeps_the_efi_keys() -> None: + for element in final_assembly(): + assert (ROOT / "elements" / element).is_file(), element + # sbvarsign stamps the current time into PK/KEK/db.auth; see the header. + assert "bluefin-server/keys/efi-keys.bst" not in final_assembly()