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