diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index 22bb4a48..72d4fddd 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -7,6 +7,7 @@ on: paths: &paths - "action.yml" - ".github/workflows/action.yml" + - "mise-tasks/action/**" - "tests/action/**" pull_request: paths: *paths @@ -29,22 +30,21 @@ jobs: - uses: actions/checkout@v7.0.1 with: persist-credentials: false + # Only the task's tools, enabled per step: the action's own mise exec + # must not inherit the list. - uses: jdx/mise-action@v5.2.4 with: - install: false cache: false + env: + MISE_ENABLE_TOOLS: nu,gh # The action runs the latest release, which can predate this checkout's # schema. Pin that release here and write its own schema beside the # stand-in config, so the two always match. - id: release env: + MISE_ENABLE_TOOLS: nu,gh GH_TOKEN: ${{ github.token }} - run: | - version=$(gh release view --repo "$GITHUB_REPOSITORY" --json tagName --jq '.tagName | ltrimstr("v")') - schema=$(cd "$RUNNER_TEMP" && MISE_MINIMUM_RELEASE_AGE=0 mise exec "packslip:sweepies/count-patchula@$version" -- patchula config schema) - rm -f tests/action/PatchulaConfig.pkl - printf '%s\n' "$schema" > tests/action/PatchulaConfig.pkl - echo "version=$version" >> "$GITHUB_OUTPUT" + run: mise run action:pin-release # A GitHub Actions-only config stands in for this repository's own, so # the dry run plans real updates without lockfile tools. - uses: $/ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e4b1bd0d..9907ec78 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,8 +3,9 @@ name: Release # Pushing a v* tag builds static archives, checks each one runs on its own # platform, builds and pushes the server image from the Linux archives, # publishes the GitHub release with a signed packslip manifest, then lets -# communique rewrite the notes. Only tags run it: pull requests don't build the -# release archives or the image. +# communique rewrite the notes. A pull request that changes the image or this +# workflow builds and checks the Linux archives and the image, with read-only +# permissions, and publishes nothing. on: push: tags: ["v*"] @@ -12,6 +13,7 @@ on: paths: - image/** - mise-tasks/image/** + - mise-tasks/release/smoke - .github/workflows/release.yml permissions: @@ -67,15 +69,7 @@ jobs: cache: false - name: Check the tag matches the crate version if: github.event_name == 'push' - run: | - # `path+file:///…/crates/cli#patchula-cli@0.7.0`: the version is the - # last field. - id=$(cargo pkgid --locked -p patchula-cli) - version=${id##*[@#]} - if [ "$GITHUB_REF_NAME" != "v$version" ]; then - echo "Tag $GITHUB_REF_NAME does not match patchula-cli $version" >&2 - exit 1 - fi + run: mise run release:check-tag "$GITHUB_REF_NAME" - name: Package env: TARGET: ${{ matrix.target }} @@ -95,24 +89,31 @@ jobs: runs-on: >- ${{ fromJSON('{"linux-x64-musl": "ubuntu-latest", "linux-arm64-musl": "ubuntu-24.04-arm", "darwin-arm64": "macos-26"}')[matrix.platform] }} timeout-minutes: 10 + env: + # Only the task runner, not the workspace toolchains. + MISE_ENABLE_TOOLS: nu steps: + - uses: actions/checkout@v7.0.1 + with: + persist-credentials: false - uses: actions/download-artifact@v8.0.2 with: + pattern: dist-* path: dist merge-multiple: true + - uses: jdx/mise-action@v5.2.4 + with: + cache: false - name: Run the binary env: PLATFORM: ${{ matrix.platform }} - run: | - mkdir smoke - tar -xzf dist/patchula-v*-"$PLATFORM".tar.gz -C smoke - smoke/bin/patchula --version | grep -E '^patchula [0-9]+\.[0-9]+\.[0-9]+' - smoke/bin/patchula config check --help > /dev/null + run: mise run release:smoke "$PLATFORM" # Both platforms are built and smoke-tested before anything is pushed, and # the push must publish the very index that ran. Nothing runs under # emulation except melange's two copy steps and the arm64 image's quick - # checks. + # checks. This job runs a pull request's code, so it holds no write + # permissions; image-publish, which only tags run, pushes what it built. image: name: Container image needs: smoke @@ -120,11 +121,6 @@ jobs: timeout-minutes: 30 permissions: contents: read - # Logs in to GHCR and pushes the image. - packages: write - # Signs and stores the image's provenance attestation. - id-token: write - attestations: write env: # Only nu and the image tools, not the workspace toolchains. MISE_ENABLE_TOOLS: nu,melange,apko @@ -157,31 +153,71 @@ jobs: GITHUB_TOKEN: ${{ github.token }} run: mise run image:smoke - run: mise run image:smoke --arch arm64 + # What image:push needs to publish this exact index again: the index + # the smoke test ran, the package cache and local packages it rebuilds + # from, and apko's SBOMs. - if: github.event_name == 'push' - uses: docker/login-action@v4.7.0 + uses: actions/upload-artifact@v7.0.2 + with: + name: image + path: | + target/image/image.tar + target/image/apk-cache + target/image/packages + target/image/sbom + if-no-files-found: error + retention-days: 1 + + image-publish: + name: Publish the container image + needs: image + if: github.event_name == 'push' + runs-on: ubuntu-latest + timeout-minutes: 20 + permissions: + contents: read + # Logs in to GHCR and pushes the image. + packages: write + # Signs and stores the image's provenance attestation. + id-token: write + attestations: write + env: + # Only nu and apko, not the workspace toolchains. + MISE_ENABLE_TOOLS: nu,apko + MISE_LOCKED: "1" + steps: + - uses: actions/checkout@v7.0.1 + with: + persist-credentials: false + - uses: actions/download-artifact@v8.0.2 + with: + name: image + path: target/image + - uses: jdx/mise-action@v5.2.4 + with: + # A release never restores a cache, so nothing cached reaches the image. + cache: false + install_args: nu + - uses: docker/login-action@v4.7.0 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ github.token }} - id: push - if: github.event_name == 'push' run: mise run image:push - - if: github.event_name == 'push' - uses: actions/attest-build-provenance@v4.2.2 + - uses: actions/attest-build-provenance@v4.2.2 with: subject-name: ghcr.io/sweepies/count-patchula subject-digest: ${{ steps.push.outputs.digest }} push-to-registry: true # apko's SBOM for each platform, attested to that platform's image. - - if: github.event_name == 'push' - uses: actions/attest-sbom@v4.1.0 + - uses: actions/attest-sbom@v4.1.0 with: subject-name: ghcr.io/sweepies/count-patchula subject-digest: ${{ steps.push.outputs.amd64 }} sbom-path: target/image/sbom/sbom-x86_64.spdx.json push-to-registry: true - - if: github.event_name == 'push' - uses: actions/attest-sbom@v4.1.0 + - uses: actions/attest-sbom@v4.1.0 with: subject-name: ghcr.io/sweepies/count-patchula subject-digest: ${{ steps.push.outputs.arm64 }} @@ -190,7 +226,7 @@ jobs: release: name: Publish - needs: [smoke, image] + needs: [smoke, image-publish] if: github.event_name == 'push' runs-on: ubuntu-latest timeout-minutes: 20 @@ -203,8 +239,10 @@ jobs: with: fetch-depth: 0 persist-credentials: false + # The archives only: the image artifact is not a release asset. - uses: actions/download-artifact@v8.0.2 with: + pattern: dist-* path: dist merge-multiple: true - name: Create a draft release diff --git a/action.yml b/action.yml index 3412ed8a..85c366a2 100644 --- a/action.yml +++ b/action.yml @@ -21,10 +21,10 @@ inputs: description: Print the planned branches and diffs without writing to GitHub. default: "false" version: - description: Count Patchula version to run. Empty means the version of this action, or the latest release when the action is not used at a release tag. + description: Count Patchula version to run, 0.9.0 or later. Empty means the version of this action, or the latest release when the action is not used at a release tag. default: "" binary: - description: The path to a patchula binary to run instead of installing a release, such as one built from source. Overrides version. + description: The path to a patchula binary to run instead of installing a release, such as one built from source, 0.9.0 or later. Overrides version. default: "" settings: description: Path to an operator settings file (amending PatchulaSettings.pkl) for HTTP limits and other operator settings. The action does not check out the repository, so check it out first when the file lives there. Empty falls back to PATCHULA_SETTINGS, then ~/.config/patchula/settings.pkl, then the defaults. @@ -46,8 +46,8 @@ runs: working_directory: ${{ runner.temp }} # Installs the binary first, so the cache below can be keyed by the cache # schema it reads. A binary refuses a cache from a newer schema, so each - # schema keeps its own lineage. Older releases, without - # `patchula cache schema`, key by their version instead. + # schema keeps its own lineage. The action runs 0.9.0 and later, the + # releases with `patchula cache schema`, and refuses an older binary. - name: Install Count Patchula id: patchula shell: bash @@ -78,16 +78,12 @@ runs: fi bin=$(cd "$RUNNER_TEMP" && MISE_MINIMUM_RELEASE_AGE=0 mise exec "packslip:sweepies/count-patchula@$version" -- sh -c 'command -v patchula') fi - if schema=$("$bin" cache schema 2>/dev/null) && [[ "$schema" =~ ^[0-9]+$ ]]; then - lineage="s$schema" - elif [[ "$("$bin" --version)" =~ ([0-9]+\.[0-9]+\.[0-9]+) ]]; then - lineage="v${BASH_REMATCH[1]}" - else - echo "::error::cannot tell which cache $bin reads" >&2 + if ! schema=$("$bin" cache schema) || ! [[ "$schema" =~ ^[0-9]+$ ]]; then + echo "::error::$bin has no 'patchula cache schema', so it predates 0.9.0, the oldest release this action runs. Set version (or binary) to 0.9.0 or later." >&2 exit 1 fi echo "bin=$bin" >> "$GITHUB_OUTPUT" - echo "lineage=$lineage" >> "$GITHUB_OUTPUT" + echo "lineage=s$schema" >> "$GITHUB_OUTPUT" # The cache holds HTTP validators, write receipts and the lockfile tool # store. Each run saves a new entry and restores the newest one. - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 @@ -128,12 +124,5 @@ runs: args+=("${extra[@]}") fi mkdir -p "$CACHE_DIR" - # The version input can install any release. Releases up to 0.4.0 take - # --cache as the SQLite file; later ones take the directory holding it. - help=$("$PATCHULA_BIN" run --help) - if [[ "$help" == *'--cache '* ]]; then - args+=(--cache "$CACHE_DIR") - else - args+=(--cache "$CACHE_DIR/cache.sqlite") - fi + args+=(--cache "$CACHE_DIR") "$PATCHULA_BIN" "${args[@]}" diff --git a/docs/src/content/docs/guide/github-actions.md b/docs/src/content/docs/guide/github-actions.md index 0bda16e0..b7b491df 100644 --- a/docs/src/content/docs/guide/github-actions.md +++ b/docs/src/content/docs/guide/github-actions.md @@ -123,8 +123,8 @@ build these files on one organization module. | `repositories` | this repository | `owner/repo` names, separated by spaces or newlines | | `all-repos` | `false` | Every repository the token can reach | | `dry-run` | `false` | Print planned branches and diffs without writing | -| `version` | the action's version, or the latest release when the action is not used at a release tag | The Count version to install, such as `@@version@@` | -| `binary` | | The path to a `patchula` binary to run instead of installing a release, such as one built from source to try unreleased changes. Overrides `version` | +| `version` | the action's version, or the latest release when the action is not used at a release tag | The Count version to install, such as `@@version@@`; 0.9.0 or later | +| `binary` | | The path to a `patchula` binary to run instead of installing a release, such as one built from source to try unreleased changes; 0.9.0 or later. Overrides `version` | | `settings` | | The path to an operator [settings](/reference/settings/) file, for HTTP limits and other operator settings. The action does not check out your repository, so add `actions/checkout` before it when the file lives there. Empty falls back to `PATCHULA_SETTINGS`, then `~/.config/patchula/settings.pkl`, then the defaults | | `args` | | Extra `patchula run` arguments, such as `--config-dir policy` | @@ -133,7 +133,13 @@ saved after every run and restored on the next, so later runs are much faster than the first. Entries are keyed by the cache schema the binary reads (`patchula cache schema`), so moving to a release with a new schema, or back to an older one, starts from a cold cache instead of failing on a database it -cannot read. Releases older than the command key by their version. Where a repository keeps +cannot read. + +The action runs Count Patchula 0.9.0 or later, the first release with +`patchula cache schema`. Given an older `version` or `binary`, it fails the +step with an error naming the binary rather than running it. + +Where a repository keeps [`.github/workflows/actions.lock`](/guide/managers/#actions-lock), the lockfile tool authenticates with the token the run was given — the `token` input's token — scoped to the repository when the App can mint one. diff --git a/mise-tasks/action/pin-release b/mise-tasks/action/pin-release new file mode 100755 index 00000000..b9eefae1 --- /dev/null +++ b/mise-tasks/action/pin-release @@ -0,0 +1,27 @@ +#!/usr/bin/env nu +#MISE description="In the Action workflow: pin the latest release for the dry run, write that release's config schema beside the stand-in config, and hand its version to the action step through GITHUB_OUTPUT" +#MISE tools={gh="2.103.3"} + +# The action runs a released Count, which can predate this checkout's schema, +# so the stand-in config must amend the release's own schema. +def main [] { + let version = ^gh release view --repo $env.GITHUB_REPOSITORY --json tagName | from json | get tagName | str replace --regex '^v' '' + let target = "tests/action/PatchulaConfig.pkl" | path expand --no-symlink + let schema = release-schema $version + # The checkout's file links to the repository's schema: replace the link, + # not the file it points to. + rm --force $target + $schema | save $target + $"version=($version)\n" | save --append $env.GITHUB_OUTPUT + print $"pinned ($version) and wrote its schema" +} + +# mise runs outside the checkout, so none of its config applies, and it +# installs the release whatever tools the workflow step enabled. +def release-schema [version: string]: nothing -> string { + cd $env.RUNNER_TEMP + hide-env --ignore-errors MISE_ENABLE_TOOLS + with-env {MISE_MINIMUM_RELEASE_AGE: "0"} { + ^mise exec $"packslip:sweepies/count-patchula@($version)" -- patchula config schema + } +} diff --git a/mise-tasks/release/check-tag b/mise-tasks/release/check-tag new file mode 100755 index 00000000..8d24bd30 --- /dev/null +++ b/mise-tasks/release/check-tag @@ -0,0 +1,11 @@ +#!/usr/bin/env nu +#MISE description="In the release workflow: check that the pushed tag is v of patchula-cli, so a tag never releases another version" +#USAGE arg "" help="The pushed tag, such as v1.2.3" + +def main [tag: string] { + let version = ^cargo metadata --format-version 1 --no-deps --locked | from json | get packages | where name == "patchula-cli" | first | get version + if $tag != $"v($version)" { + error make --unspanned {msg: $"tag ($tag) does not match patchula-cli ($version)"} + } + print $"($tag) matches patchula-cli ($version)" +} diff --git a/mise-tasks/release/smoke b/mise-tasks/release/smoke new file mode 100755 index 00000000..201cef35 --- /dev/null +++ b/mise-tasks/release/smoke @@ -0,0 +1,24 @@ +#!/usr/bin/env nu +#MISE description="In the release workflow: unpack one platform's archive from dist and check that its patchula runs and reports the archive's version" +#USAGE arg "" help="The archive's platform, such as linux-x64-musl" + +def main [platform: string] { + let archives = glob $"dist/patchula-v*-($platform).tar.gz" + if ($archives | length) != 1 { + error make --unspanned {msg: $"expected one ($platform) archive in dist, found ($archives | length)"} + } + let archive = $archives | first + let name = $archive | path basename + let version = $name | parse $"patchula-v{version}-($platform).tar.gz" | first | get version + let out = mktemp --directory --tmpdir patchula-smoke.XXXXXX + ^tar --extract --gzip --file $archive --directory $out + let patchula = $out | path join bin patchula + let reported = ^$patchula --version | str trim + if $reported != $"patchula ($version)" { + error make --unspanned {msg: $"($name) reports '($reported)', not patchula ($version)"} + } + if (^$patchula config check --help | complete).exit_code != 0 { + error make --unspanned {msg: $"($name): patchula config check --help failed"} + } + print $"ok ($name): ($reported)" +}