Skip to content

About

Reusable GitHub Actions workflows for the Hegemony repositories: the plugin release pipeline (semantic-release, wheels, SHA256SUMS and provenance attestations).

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

hegemony-github-workflows

Reusable GitHub Actions workflows shared by the Hegemony repositories.

plugin-release.yml — release a plugin repository on merge to main

.github/workflows/plugin-release.yml is the release-on-merge pipeline of the four plugin repositories (hegemony-inventory-plugins, hegemony-notification-plugins, hegemony-secret-plugins, hegemony-step-plugins). It is the same approach the host platform uses in its own release.yml: semantic-release reads the Conventional Commits since the last tag, derives the next version, and only then bumps, builds, commits, tags and publishes. When nothing since the last tag is releasable the run ends without a release.

Calling it

name: Release

on:
  push:
    branches: [main]
  workflow_dispatch:

permissions: {}

jobs:
  release:
    name: Release
    if: "!contains(github.event.head_commit.message, '[skip ci]')"
    uses: hegemony-sh/hegemony-github-workflows/.github/workflows/plugin-release.yml@<commit-sha> # main
    permissions:
      contents: read
      id-token: write
      attestations: write
      artifact-metadata: write
    with:
      release-app-client-id: ${{ vars.RELEASE_APP_CLIENT_ID }}
    secrets:
      RELEASE_APP_PRIVATE_KEY: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}

The job's check runs show up as Release / Semantic Release and, on public repositories that released something, Release / Attest Release Assets.

Pinning

Callers reference this workflow by a full commit SHA, never by branch: the called code receives the release credential and the release job's write permission, so what runs must be exactly what was reviewed. The trailing # main comment says which branch the pin was taken from. A change merged here changes no caller: it reaches one only when that caller bumps the SHA in its release.yml, in a pull request reviewed there (the git ls-remote https://github.com/hegemony-sh/hegemony-github-workflows main line gives the current head). The release toolchain in release-tools/ is checked out at that same SHA, so a pin bump moves the workflow and its dependency lockfile together.

Inputs

Input Default Purpose
python-version "3.12" Handed to actions/setup-python.
uv-version "0.9.28" Handed to astral-sh/setup-uv. Keep it equal to the caller's ci.yml pin so the release refreshes uv.lock with the resolver CI validated.
node-version "24" Runs semantic-release. The release-tools lockfile needs 22.22.2 or later on the 22 line, or 24.15 or later.
release-app-client-id required Client ID of the organization's release GitHub App (hegemony-release). Each job that needs a release credential mints a short-lived installation token of the App, limited to the calling repository and to contents: write, and revoked when the job ends. Callers pass vars.RELEASE_APP_CLIENT_ID.

Secrets

Secret Required Purpose
RELEASE_APP_PRIVATE_KEY yes Private key of the release App. The App must be installed on the caller and be a bypass actor of every ruleset on the caller's main: the built-in GITHUB_TOKEN cannot bypass rulesets, even with contents: write, and a release commit or Release made with it would not trigger other workflows. semantic-release pushes the release commit and tag and creates the GitHub Release with the App's token, and the publish job publishes the Release with it.

The workflow fails fast, with a message that says what to add, when the client ID or the key arrives empty (GitHub passes an empty string for a variable or secret the caller does not have). release-tools/ is fetched from this repository with the job's own GITHUB_TOKEN, which can read it because the repository is public; the release credential never reaches this repository.

Permissions

The workflow declares permissions: {} and each job asks for what it needs: contents: read for the release job, which only checks out the caller (the release commit, tag and Release are made with the App token); id-token: write, attestations: write and artifact-metadata: write (the storage record actions/attest v4 creates) for the attest job only. The publish job asks for nothing: it works with the release credential. A called workflow can only narrow what its caller grants, so the caller's uses: job must grant the union shown above.

What the caller must contain

Path Role
.releaserc.json The semantic-release configuration. It is what runs the scripts below (through @semantic-release/exec), lists the files the release commit carries (@semantic-release/git) and the assets the GitHub Release gets (@semantic-release/github).
scripts/set_version.py X.Y.Z Sets one version across every package pyproject.toml, the SDK pins and the SDK _version.py.
scripts/verify_release_version.py vX.Y.Z Fails when any package disagrees with the version about to be released.
scripts/build_wheels.py Builds every workspace wheel into dist/.
scripts/smoke_install_wheels.py Optional; installs the wheels into a clean venv and imports them.
uv.lock Refreshed by uv lock inside the release and committed with the bump.
CHANGELOG.md Prepended on every release by @semantic-release/changelog.

The steps the workflow runs before semantic-release are, in order: checkout of the caller with full history and no persisted credentials; Python, uv and uv sync --frozen --all-packages; Node.js; a sparse checkout of this repository's release-tools/ at the workflow's own commit; npm ci --ignore-scripts in it, which installs exactly package-lock.json (the semantic-release core, the commit-analyzer, release-notes-generator, changelog, exec, git and github plugins, and the conventional-changelog-conventionalcommits preset, which is what makes a bare feat!: / fix!: count as a breaking change; the default angular preset does not parse the marker); and only then origin re-pointed at an x-access-token URL built from the release credential. Nothing installed can read the token: it is written after every install, and package lifecycle scripts never run. A .releaserc.json may only name plugins and presets from that lockfile.

semantic-release runs with --extends release-tools/release-notes.mjs, a shareable config layered under the caller's .releaserc.json (the caller's options win). It sets only writerOpts.finalizeContext, which removes commit trailer lines (Signed-off-by:, Co-authored-by:, Claude-Session:, in any case) from the breaking-change notes: the conventional-commits parser reads everything after a BREAKING CHANGE: footer as note text, so without it the trailers reach CHANGELOG.md, the release commit and the GitHub Release. A caller that sets its own top-level writerOpts replaces it, and a caller's extends is overridden by the command-line one.

The plugin repositories' .releaserc.json chain, in prepareCmd: set_version.py → uv lock → verify_release_version.py → build_wheels.py → smoke_install_wheels.py → sha256sum *.whl *.tar.gz > SHA256SUMS inside dist/ (*.tar.gz once the caller builds sdists); and in verifyReleaseCmd they refuse to continue when a GitHub Release for the next tag already exists, so a release is never overwritten. Their successCmd writes NEW_RELEASE=true and NEW_RELEASE_VERSION to GITHUB_ENV, which is how this workflow learns a release happened.

Provenance

When a release happened and the calling repository is public, a second job downloads the assets from the run and attests dist/*.whl and dist/SHA256SUMS with actions/attest. Private repositories cannot attest, so the job is skipped there and runs by itself once the caller is public.

The attestation lives in GitHub's attestation store, but tools that check a release, OpenSSF Scorecard's Signed-Releases among them, look only at its assets. So semantic-release creates the GitHub Release as a draft (draftRelease: true in release-tools/release-notes.mjs), and the publish job attaches the same Sigstore bundle as <repo>-<version>.intoto.jsonl and only then publishes the Release, with the release credential so that the caller's release: published workflows run. The order matters: the plugin repositories use immutable releases, and an immutable release takes no new assets once it is published. On a private caller the publish job publishes the draft without a bundle. On a public caller it publishes only after the release job and the attest job both succeeded; if either failed or the attest job was skipped, the publish job does not run and the Release stays a draft.

Verify a wheel online with

gh attestation verify <wheel> --repo hegemony-sh/<repo> \
  --signer-workflow hegemony-sh/hegemony-github-workflows/.github/workflows/plugin-release.yml

or offline, against the attached bundle and a trusted root fetched earlier on a connected machine with gh attestation trusted-root > trusted_root.jsonl, by adding --bundle <repo>-<version>.intoto.jsonl --custom-trusted-root trusted_root.jsonl.

When a run created a draft Release but did not publish it, there are two cases. If the release job succeeded and the attest or publish job failed, re-run the failed jobs: the publish job attaches the bundle and publishes, and a re-run that finds the Release already published does nothing. If the release job itself failed after creating the draft (the upload of the assets for the attest job, say), re-running it does not help, because semantic-release now sees the tag and finds nothing to release. The draft then has its wheels but no bundle, and a bundle can only be made by actions/attest inside a workflow run (it signs with the run's OIDC identity), so this workflow has no way to finish it today. Leave the draft unpublished and decide by hand: delete the draft and release the next version, or, knowingly, publish it without provenance with gh release edit vX.Y.Z --draft=false. A run with nothing to release creates no draft, and nothing needs recovering.

Outputs

Output Meaning
released "true" when the run cut a release, else "false".
version The released version without the leading v; empty when nothing was released.
published "true" once the GitHub Release is published, also on a re-run that found it already published.

The wheels, the sdists (when the caller builds them) and SHA256SUMS stay in the run's release-assets artifact for one day. The attest job signs all of them.

PyPI

Trusted publishing does not work from inside a reusable workflow (pypa/gh-action-pypi-publish documents this as unsupported; the token exchange fails with invalid-publisher). So this workflow does not upload to PyPI itself. A caller that publishes to PyPI adds its own job to its release.yml, after the release job. It downloads the files from the published GitHub Release rather than from the run's one-day artifact, so an approval by a required reviewer, or a re-run, still works days later:

  pypi:
    name: Publish to PyPI
    needs: release
    # Only after the GitHub Release is published: an upload to PyPI cannot
    # be undone, only yanked.
    if: needs.release.outputs.published == 'true'
    runs-on: ubuntu-latest
    timeout-minutes: 15
    environment:
      name: pypi
    permissions:
      contents: read # download the published Release's assets
      attestations: read # verify their provenance attestations
      id-token: write # trusted publishing and the PyPI (PEP 740) attestations
    steps:
      # The files come from the published GitHub Release, not from a run
      # artifact: a Release is immutable and stays, so the job still works
      # when the required reviewer approves it days later or it is re-run.
      - name: Download the published Release
        env:
          GH_TOKEN: ${{ github.token }}
          REPOSITORY: ${{ github.repository }}
          VERSION: ${{ needs.release.outputs.version }}
        run: |
          gh release download "v${VERSION}" --repo "$REPOSITORY" --dir dist \
            --pattern '*.whl' --pattern '*.tar.gz' --pattern SHA256SUMS
      # Upload exactly the files the release workflow built and attested:
      # every wheel and sdist must be in SHA256SUMS with a matching hash,
      # carry the released version and have a provenance attestation from
      # the shared release workflow. PyPI refuses SHA256SUMS itself as an
      # unknown file type, so it goes once checked.
      - name: Check the files against the release
        working-directory: dist
        env:
          GH_TOKEN: ${{ github.token }}
          REPOSITORY: ${{ github.repository }}
          VERSION: ${{ needs.release.outputs.version }}
        run: |
          sha256sum --check --strict SHA256SUMS
          shopt -s nullglob
          files=(*.whl *.tar.gz)
          [ "${#files[@]}" -gt 0 ] || { echo "::error::no wheels or sdists in the Release"; exit 1; }
          for file in "${files[@]}"; do
            awk -v f="$file" '$2 == f {found = 1} END {exit !found}' SHA256SUMS || { echo "::error::${file} is not in SHA256SUMS"; exit 1; }
            case "$file" in
              *-"${VERSION}"-py3-none-any.whl | *-"${VERSION}".tar.gz) ;;
              *) echo "::error::${file} is not a ${VERSION} file"; exit 1 ;;
            esac
            gh attestation verify "$file" --repo "$REPOSITORY" \
              --signer-workflow hegemony-sh/hegemony-github-workflows/.github/workflows/plugin-release.yml \
              > /dev/null
          done
          rm SHA256SUMS
      - uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
        with:
          packages-dir: dist/
          attestations: true # PEP 740 attestations, shown on PyPI
          print-hash: true
          skip-existing: true

This job is for public callers only. The attest job runs only for public repositories, so a private caller's Release has no attestations, and gh attestation verify fails before anything is uploaded. That is on purpose: the job fails closed rather than publish files it cannot trace to this workflow. A Release cut while the repository was private can still go to PyPI by hand; each plugin repository's CONTRIBUTING.md gives the checked upload steps.

The uses: job must still grant id-token: write for the attest job; the pypi job asks for its own. PyPI checks the run's OIDC token against a trusted publisher configured for each package, which must name

Field Value
Owner hegemony-sh
Repository the caller, e.g. hegemony-step-plugins
Workflow release.yml
Environment pypi

Before the first release with the job, give every package the caller builds a trusted publisher on PyPI, and create the pypi environment in the caller with a deployment rule that admits only main. A package without a matching publisher fails the job after the GitHub Release is out; fix the publisher and re-run the failed job: skip-existing skips the files PyPI already holds. A pending publisher does not reserve the name: until the first upload creates the project, anyone can register it and the pending publisher is dropped.

Packages that are new to PyPI need care. An account may hold only 3 pending publishers at a time, and PyPI lets an account create only a few new projects per day (4 per 24 hours at the time of writing). The job uploads every package in one run, so a first release with more new packages than that fails part way. For a repository with many new packages, create the projects first: upload the current release's wheels by hand with an account-scoped API token, a few per day, and delete the token after each run. Then give each existing project a normal (not pending) trusted publisher before the first release with the job.

For a manual gate, add a required reviewer to the caller's pypi environment (Settings → Environments → pypi → Required reviewers). The GitHub Release still goes out on its own, and the pypi job waits until a reviewer approves it. Leave "Prevent self-review" off when the person who merges is also the only reviewer.

Recovering a tag without a Release

semantic-release pushes the release commit and the vX.Y.Z tag before it publishes the GitHub Release. If publication fails after that push (an API outage, a bad token), the tag exists and the Release does not, and a re-run will not repair it: semantic-release reads the tag as the last release and finds nothing new. The fix is to publish that tag's assets by hand, from a checkout of the tag:

git fetch --tags origin && git checkout vX.Y.Z
uv sync --frozen --all-packages
uv run --no-sync python scripts/build_wheels.py
(cd dist && shopt -s nullglob && sha256sum *.whl *.tar.gz > SHA256SUMS)
gh release create vX.Y.Z --verify-tag --title vX.Y.Z \
  --notes "$(awk '/^## /{n++} n==1' CHANGELOG.md)" dist/*.whl $(ls dist/*.tar.gz 2>/dev/null) dist/SHA256SUMS

--verify-tag refuses to create a tag that is not already on the remote, so the command cannot mint a version by accident; the notes are the newest CHANGELOG.md section, which the failed run already committed. The verifyReleaseCmd immutability guard in the callers' .releaserc.json keeps the next automatic run from touching that version again.

A recovered version does not reach PyPI on its own. The caller's pypi job runs only when the release job reports published, which a hand-made Release never does. Its files also carry no attestation from this workflow, so the job would refuse them anyway. Upload them by hand with the steps in the caller's CONTRIBUTING.md, which apply these checks before twine runs:

  • sha256sum --check --strict SHA256SUMS passes;
  • every *.whl and *.tar.gz is listed in SHA256SUMS by its exact name;
  • the upload stops at the first failed step.

gh attestation verify cannot apply here, because these files have no attestations. A hand upload also carries no PEP 740 attestations on PyPI.

Concurrency

concurrency: release-${{ github.repository }} with cancel-in-progress: false: a second merge queues behind a running release rather than racing it or cancelling it.

Checks

CI runs on every pull request and every push to main: a Conventional Commits lint of the pull request's commits, a secret scan (gitleaks) and a workflow scan (zizmor), REUSE licence lint, and a release toolchain check. That check installs release-tools/ with npm ci --ignore-scripts --engine-strict on the node-version default, then dry-runs a release in a throwaway repository, so a lockfile that no longer installs, no longer runs on that Node.js, or no longer renders release notes fails the pull request rather than a plugin release. CONTRIBUTING.md shows how to run them locally, and SECURITY.md how to report a vulnerability.

Licence

AGPL-3.0-or-later; see LICENSE. The repository follows the REUSE specification: each file carries an SPDX header, or an entry in REUSE.toml where it cannot.

About

Reusable GitHub Actions workflows for the Hegemony repositories: the plugin release pipeline (semantic-release, wheels, SHA256SUMS and provenance attestations).

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Used by

Contributors

Languages