Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
paths: &paths
- "action.yml"
- ".github/workflows/action.yml"
- "mise-tasks/action/**"
- "tests/action/**"
pull_request:
paths: *paths
Expand All @@ -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: $/
Expand Down
100 changes: 69 additions & 31 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ 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*"]
pull_request:
paths:
- image/**
- mise-tasks/image/**
- mise-tasks/release/smoke
- .github/workflows/release.yml

permissions:
Expand Down Expand Up @@ -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 }}
Expand All @@ -95,36 +89,38 @@ 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
runs-on: ubuntu-latest
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
Expand Down Expand Up @@ -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 }}
Expand All @@ -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
Expand All @@ -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
Expand Down
27 changes: 8 additions & 19 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 <DIR>'* ]]; then
args+=(--cache "$CACHE_DIR")
else
args+=(--cache "$CACHE_DIR/cache.sqlite")
fi
args+=(--cache "$CACHE_DIR")
"$PATCHULA_BIN" "${args[@]}"
12 changes: 9 additions & 3 deletions docs/src/content/docs/guide/github-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |

Expand All @@ -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.
Expand Down
27 changes: 27 additions & 0 deletions mise-tasks/action/pin-release
Original file line number Diff line number Diff line change
@@ -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
}
}
11 changes: 11 additions & 0 deletions mise-tasks/release/check-tag
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env nu
#MISE description="In the release workflow: check that the pushed tag is v<version> of patchula-cli, so a tag never releases another version"
#USAGE arg "<tag>" 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)"
}
24 changes: 24 additions & 0 deletions mise-tasks/release/smoke
Original file line number Diff line number Diff line change
@@ -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 "<platform>" 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)"
}
Loading