From 9aaa7f5275105b7358b4e466e9a4513e481f2da0 Mon Sep 17 00:00:00 2001 From: Kevin Shenk Date: Tue, 24 Nov 2026 19:35:01 -0500 Subject: [PATCH] feat(conventions): allow an Avunu reusable workflow at its exact release tag A reusable workflow call to a workflow of an Avunu repository may now name its exact release tag (@vX.Y.Z), as well as the commit SHA with the version in a trailing comment. Reusable calls to any other owner, a composite action's steps and workflow steps keep their existing rules. A floating branch is never a pin. gh-actions-lock does not lock reusable workflows, so a tag names a release rather than a commit: the trade-off is accepted for Avunu's own workflows, which the same organisation publishes, and it is not extended to other owners. ci-pins now accepts that form for a reusable call to an Avunu repository and still rejects a branch, another owner's tag, and a tag on a composite action's step. The conventions test and the docs say the same. Co-Authored-By: Claude Haiku 5.5 Claude-Session: https://claude.ai/code/session_01AAw4Sw2knFZL7NYgFroq1Y --- checks/lib-conventions.nix | 30 ++++++++++++++++++++------ docs/conventions.md | 2 +- docs/library.md | 2 +- docs/releases.md | 2 +- lib/checks/repository.py | 44 +++++++++++++++++++++++++------------- standards/DESIGN.md | 2 +- 6 files changed, 56 insertions(+), 26 deletions(-) diff --git a/checks/lib-conventions.nix b/checks/lib-conventions.nix index 93b2e18..eba7773 100644 --- a/checks/lib-conventions.nix +++ b/checks/lib-conventions.nix @@ -324,9 +324,10 @@ mk.script "lib-conventions" { } '' ]} # With .github/workflows/actions.lock, a workflow step's exact release tag - # passes, and so does a SHA with its comment. A reusable workflow call, a - # composite action's step, a branch and a major-only tag do not; and without - # the lock, an exact tag does not pass either. + # passes, and so does a SHA with its comment. A reusable workflow call to an + # Avunu repository passes with its exact release tag. A reusable call to another + # owner, a composite action's step, a branch and a major-only tag do not; and + # without the lock, a step's exact tag does not pass either. echo "a SHA passes with a lock: ${pins (stub.variant "locked" "touch .github/workflows/actions.lock")}" echo "a release tag passes with a lock: ${pins ( stub.variant "tag-locked" '' @@ -343,15 +344,30 @@ mk.script "lib-conventions" { } '' "1 action(s) not pinned" ] } + echo "a release tag passes on an Avunu reusable workflow: ${pins ( + stub.variant "tag-reusable" '' + sed -i 's|dependabot-auto-merge.yml@51c31525e5a1f2ed0d3e4b8b8c0b9c9a2f0f3e11 # main (no release yet)|dependabot-auto-merge.yml@v1.6.0|' .github/workflows/check.yml + '' + )}" ${stub.expectFailure (pins ( - stub.variant "tag-reusable" '' - sed -i 's|dependabot-auto-merge.yml@51c31525e5a1f2ed0d3e4b8b8c0b9c9a2f0f3e11 # main (no release yet)|dependabot-auto-merge.yml@v1.6.0|' .github/workflows/check.yml - touch .github/workflows/actions.lock + stub.variant "tag-reusable-other-owner" '' + sed -i 's|Avunu/python-devops-nix/.github/workflows/dependabot-auto-merge.yml@51c31525e5a1f2ed0d3e4b8b8c0b9c9a2f0f3e11 # main (no release yet)|acme/tools/.github/workflows/dependabot-auto-merge.yml@v1.6.0|' .github/workflows/check.yml + '' + )) + [ + ".github/workflows/check.yml:10: acme/tools/.github/workflows/dependabot-auto-merge.yml@v1.6.0 is not pinned by a full commit SHA" + "1 action(s) not pinned" + ] + } + ${stub.expectFailure + (pins ( + stub.variant "branch-reusable" '' + sed -i 's|dependabot-auto-merge.yml@51c31525e5a1f2ed0d3e4b8b8c0b9c9a2f0f3e11 # main (no release yet)|dependabot-auto-merge.yml@main|' .github/workflows/check.yml '' )) [ - ".github/workflows/check.yml:10: Avunu/python-devops-nix/.github/workflows/dependabot-auto-merge.yml@v1.6.0 is not pinned by a full commit SHA" + ".github/workflows/check.yml:10: Avunu/python-devops-nix/.github/workflows/dependabot-auto-merge.yml@main is not pinned by a full commit SHA or exact release tag (vX.Y.Z)" "1 action(s) not pinned" ] } diff --git a/docs/conventions.md b/docs/conventions.md index 9d14215..b50b5d0 100644 --- a/docs/conventions.md +++ b/docs/conventions.md @@ -603,7 +603,7 @@ The pieces in the NixOS modules ([library](library.md#production)), adopted in f - **Convention:** an action is pinned by the rule for its kind of `uses:`, and a floating branch ref is never allowed: - **A workflow step's action**, which gh-actions-lock can pin: an exact release tag (`vX.Y.Z`). The repository needs its lock file, `.github/workflows/actions.lock`, for a tag. A full commit SHA with the version in a trailing comment is accepted there too, which is how the products and this repository pin today. - - **A reusable workflow call** (`uses: owner/repo/.github/workflows/x.yml@ref`): a full commit SHA with the version in a trailing comment, because gh-actions-lock does not cover reusable workflows. + - **A reusable workflow call** (`uses: owner/repo/.github/workflows/x.yml@ref`): a full commit SHA with the version in a trailing comment, because gh-actions-lock does not cover reusable workflows. A reusable workflow of an Avunu repository may instead name its exact release tag (`@vX.Y.Z`); the lock does not cover that either, so the tag stays a name rather than a commit. Any other owner's reusable workflow keeps the SHA. - **A composite action's steps** (`.github/actions/*/action.yml`) that call remote actions: a full commit SHA with the version in a trailing comment, because gh-actions-lock refuses to lock them without `--ignore-local-actions`. - **A floating branch ref** is never allowed, in any of these places. diff --git a/docs/library.md b/docs/library.md index d7a5ef9..3f4fb34 100644 --- a/docs/library.md +++ b/docs/library.md @@ -127,7 +127,7 @@ Conventions: [Images](conventions.md#images). | `lib.checks.commandFlags { pkgs, product, commands, exceptions ? [ ] }` | Each of `commands`, `{ restore, scaffolder }`, run with `--help`, lists the flags the conventions name for it, at the head of an option line. Two spaces or a tab end the flags, and a metavar is in upper case or in brackets. | | `lib.checks.optionPaths { pkgs, product, options, tenant, exceptions ? [ ] }` | An eval check that the options the conventions name are declared and visible under `.*` in `options.shell` and `services..*` in `options.nixos`, that `ports.*` are not read-only, and that nothing visible is left in `dev`. `tenant` is `{ shell, nixos }`, the default tenant's option in each. | | `lib.checks.configBlocks { pkgs, product, options, settings }` | An eval check that each `{ module, path, format, args ? { } }` in `settings` is a `settings` submodule whose `freeformType` is `pkgs.formats. args`'s type. | -| `.github/workflows/dependabot-auto-merge.yml` | A reusable workflow that auto-merges Dependabot pull requests by a policy the caller passes. A caller pins it by SHA. With a GitHub App, the App enables auto-merge, so the merge raises a `push`. Its jobs run on GitHub-hosted `ubuntu-latest`, and fetch-metadata runs apart from the job that holds the App's key, which runs only when both fetch-metadata's `policy` and a `diff` job that reads the pull request's diff with `gh` allow it. When either holds a head, a `hold` job turns off, with `GITHUB_TOKEN`, auto-merge an earlier head's run enabled. | +| `.github/workflows/dependabot-auto-merge.yml` | A reusable workflow that auto-merges Dependabot pull requests by a policy the caller passes. A caller pins it by SHA, or by its release tag. With a GitHub App, the App enables auto-merge, so the merge raises a `push`. Its jobs run on GitHub-hosted `ubuntu-latest`, and fetch-metadata runs apart from the job that holds the App's key, which runs only when both fetch-metadata's `policy` and a `diff` job that reads the pull request's diff with `gh` allow it. When either holds a head, a `hold` job turns off, with `GITHUB_TOKEN`, auto-merge an earlier head's run enabled. | | `.github/workflows/dependabot-update-branches.yml` | A reusable workflow that brings the Dependabot pull requests that are behind the default branch up to date through the update-branch API. A caller pins it by SHA and runs it on a push to the default branch and on a schedule. Its job holds the App's key, so it runs on GitHub-hosted `ubuntu-latest`. | | `.github/actions/pre-commit-autofix` | Runs the caller's fixers (`nix fmt`) and prek hooks over a pull request's branch, pushes what they rewrote, dispatches the workflows the push cannot start, and comments what it did. | | `.github/actions/nix-failures` | Markdown from the log of a failed `nix build` or `nix flake check`: each failed derivation with the end of its log, or the evaluation error. | diff --git a/docs/releases.md b/docs/releases.md index b218f42..87c8669 100644 --- a/docs/releases.md +++ b/docs/releases.md @@ -47,7 +47,7 @@ The release pull request is pushed with `GITHUB_TOKEN`, and a push made with it A product pins a release, never a commit of `main`: - The flake input at the release branch. `release` carries every release, so `github:Avunu/python-devops-nix/release` locks to the latest one. A product is kept safe by its pinned `flake.lock` and by CI, not by the branch name: Dependabot's nix entry moves the lock only when a release moves the branch, and the product's checks must pass before that pull request merges, a new major included. -- The reusable workflow and the actions at a tag's commit, with the version in a comment, as every other action is pinned: `@ # v1.0.0`. Dependabot's github-actions entry moves both. +- The reusable workflow and the actions at a tag's commit, with the version in a comment, as every other action is pinned: `@ # v1.0.0`. Dependabot's github-actions entry moves both. The reusable workflow may instead name the tag itself, `@v1.0.0`, which [CI](conventions.md#ci) allows for an Avunu reusable workflow. Both products pin a release's commit, with its version in the comment ([CI](conventions.md#ci)). diff --git a/lib/checks/repository.py b/lib/checks/repository.py index 3ae9f62..87be154 100644 --- a/lib/checks/repository.py +++ b/lib/checks/repository.py @@ -8,8 +8,9 @@ sha256 digest, with a trailing comment, which by convention names the version. A local `./` path is exempt. Where .github/workflows/actions.lock exists, an action a workflow step uses may instead be pinned by an exact release tag -(`vX.Y.Z`), which gh-actions-lock locks. A reusable workflow call and a -composite action's steps keep the SHA. +(`vX.Y.Z`), which gh-actions-lock locks. A reusable workflow call to an Avunu +repository may also be pinned by its exact release tag; any other reusable call +and a composite action's steps keep the SHA. A branch is never a pin. `dependabot` (docs/conventions.md, Dependabot): every ecosystem in .github/dependabot.yml has the commit prefix, the seven-day cooldown and one @@ -48,21 +49,27 @@ def sequence(node: yaml.Node | None) -> list[yaml.Node]: return node.value if isinstance(node, yaml.SequenceNode) else [] -def uses_nodes(root: yaml.Node) -> Iterator[tuple[yaml.Node, bool]]: - # Each `uses:` with whether it is a workflow step's action, the one kind a - # release tag may pin. A job's jobs..uses is a reusable workflow, and a - # composite action's runs.steps[].uses stays on the SHA. +def uses_nodes(root: yaml.Node) -> Iterator[tuple[yaml.Node, str]]: + # Each `uses:` with its kind. A workflow step's action is "step", the kind a + # lock may pin by release tag. A job's jobs..uses is "reusable", a + # reusable workflow call. A composite action's runs.steps[].uses is + # "composite", which stays on the SHA. top = mapping(root) for job_node in mapping(top.get("jobs")).values(): job = mapping(job_node) if "uses" in job: - yield job["uses"], False + yield job["uses"], "reusable" for step in sequence(job.get("steps")): if "uses" in mapping(step): - yield mapping(step)["uses"], True + yield mapping(step)["uses"], "step" for step in sequence(mapping(top.get("runs")).get("steps")): if "uses" in mapping(step): - yield mapping(step)["uses"], False + yield mapping(step)["uses"], "composite" + + +def avunu_release_tag(ref: str) -> bool: + """A reusable workflow of an Avunu repository, at an exact release tag.""" + return ref.startswith("Avunu/") and TAG.fullmatch(ref) is not None def pin_findings(path: Path, rel: str, lockable: bool) -> Iterator[str]: @@ -71,15 +78,22 @@ def pin_findings(path: Path, rel: str, lockable: bool) -> Iterator[str]: if root is None: return lines = text.splitlines() - for node, step in uses_nodes(root): + for node, kind in uses_nodes(root): where = f"{rel}:{node.start_mark.line + 1}" ref = node.value if isinstance(node, yaml.ScalarNode) else "" if ref.startswith("./"): continue - if lockable and step and TAG.fullmatch(ref): + if lockable and kind == "step" and TAG.fullmatch(ref): + continue + if kind == "reusable" and avunu_release_tag(ref): continue if not PIN.fullmatch(ref): - by = "sha256 digest" if ref.startswith("docker://") else "full commit SHA" + if ref.startswith("docker://"): + by = "sha256 digest" + elif kind == "reusable" and ref.startswith("Avunu/"): + by = "full commit SHA or exact release tag (vX.Y.Z)" + else: + by = "full commit SHA" yield f"{where}: {ref} is not pinned by a {by}" continue if not trailing_comment(lines, node): @@ -122,9 +136,9 @@ def pins(product_dir: Path) -> int: if findings: print( f"{len(findings)} action(s) not pinned. Pin each by its full commit SHA," - " with its version in a trailing comment, or, in a workflow step where" - " .github/workflows/actions.lock exists, by its exact release tag" - " (docs/conventions.md, CI)." + " with its version in a trailing comment, or by its exact release tag where" + " the convention allows one: a workflow step where .github/workflows/actions.lock" + " exists, or a reusable workflow of Avunu (docs/conventions.md, CI)." ) return 1 print(f"every action in {len(files)} file(s) is pinned") diff --git a/standards/DESIGN.md b/standards/DESIGN.md index 186295c..2e1351d 100644 --- a/standards/DESIGN.md +++ b/standards/DESIGN.md @@ -1768,7 +1768,7 @@ These are copied (ยง2.4). The update-branches bot rule: Every action: - is `runs: using: composite`; -- pins every `uses:` by SHA with a version comment (the `ci-pins` check); +- pins every `uses:` by SHA with a version comment, or a reusable workflow of Avunu by its release tag (the `ci-pins` check); - passes inputs through `env:`, never interpolated into scripts (the zizmor template-injection rule); - names the product CLI through the `cli` input, so no product name is hard-coded.