Repository navigation
Workflow python package release
What it does. Builds the sdist and wheel, runs twine check --strict, reads the version off the sdist's own name and refuses a
tag that disagrees, runs your verify-command, installs the wheel into a fresh virtual environment and runs your
smoke-command, writes the release notes; then publishes to the GitHub release with a SHA256SUMS and build provenance. PyPI
(Trusted Publishing, PEP 740 attestations) is published from a job in your workflow (download the dist artifact, run the pypa action),
because PyPI cannot trust a reusable workflow as the publisher. No secret anywhere.
Why it exists. Four repositories had written build, check, tag-against-version and PyPI publish by hand, four slightly different ways. The checks that matter are the ones that catch a release that does not match its tag, or a wheel that does not install.
Publishing is an allow-list. The publish job, and each step in it that signs, attests or uploads, runs only for an event named in allowed-publish-events (default push; a caller triggered by release: published sets push,release) on a refs/tags/v<semver> (SemVer 2.0.0: no leading zeroes, no empty identifiers) ref. An existing release is only completed: every asset must be absent or already there with the identical sha256 digest. Nothing is replaced; a differing asset fails the run and names it, and that version is burned. The asset set is read again after the upload and must hold exactly this build's files with identical digests, or the run fails. Concurrent writers to the same release are unsupported. The release must hold exactly the files this build produced: an asset that is not part of the build (an extra asset) is treated like a differing one and fails the run, before and after the upload. All assets are read through the paginated asset listing, so a release with more than one page of assets is checked in full. The release is looked up by its HTTP status (a 404 means no release; any other failure stops the run). Every local file name must follow the asset naming policy, checked before any release call: ASCII letters, digits, ., _ and -, starting and ending with a letter or digit (an uploaded name that GitHub changed would break the exact comparison). This is a conservative repository naming policy, stricter than what GitHub documents: GitHub documents renaming for special characters and leading or trailing periods, and the policy also refuses names that start or end with _ or -. Existing callers whose build produces such a name (spaces, +, non-ASCII, a leading or trailing _ or -) must rename the file in their build-command before re-pinning; the run fails before any release call, so nothing is half-published. Every remote asset, extras included, must be in state uploaded, and no name may occur twice. Listing pages are validated as an array of arrays of objects before they are read, so a malformed listing stops the run. Behavior change: a new release created for a SemVer prerelease tag (for example v1.2.3-rc.1; build metadata alone, v1.2.3+build.1, is not a prerelease) is now marked as a prerelease with --prerelease, so it is not shown as the latest release; earlier versions of this workflow never set the flag. Hidden files (names beginning with .) in the staging directory are rejected by the naming policy rather than silently skipped. Names that differ only in letter case (for example A.whl and a.whl) are refused as well, as a conservative naming policy: GitHub's exact rule for case is not verified here, and a rejected second upload would leave a partial release. An existing release must also carry the prerelease flag the tag implies (a boolean; set for a SemVer prerelease tag, unset otherwise), or the run fails and the version is burned. A draft release for the tag is not completed automatically: the run fails and asks you to publish or delete the draft, or burn the version.
| Job | Holds | Notes |
|---|---|---|
build |
contents: read |
Everything that runs your code: the build, twine check, verify-command, the wheel smoke test, the release notes command |
pypi-unsupported |
contents: read |
Runs only when a caller still passes pypi: true: fails at once with the fix, instead of at PyPI with invalid-publisher
|
github-release |
contents: write, id-token: write, attestations: write
|
Checks nothing out. Records provenance for every file and attaches them with a SHA256SUMS; creates the release from the notes or uploads to one that exists |
SBOMs. The build job also runs syft (pinned by version and sha256, the syft-version
and syft-sha256 inputs) over the unpacked wheel and sdist and writes sbom.cdx.json (CycloneDX) and sbom.spdx.json (SPDX). They
are their own artifact, so PyPI never receives them; github-release adds them to the release, to SHA256SUMS and to the same
provenance step. sbom: true is the default, and a pull request writes them too, so a broken SBOM is a red check, not a surprise at
tag time. They list the package and its metadata, not a resolved dependency tree. artifact-release.yml does not write them: its
files are arbitrary (a .deb, a firmware blob) and syft would report nothing, which reads as assurance and is not.
A pull request builds and checks and never publishes, whatever publish says. The version is read off the sdist's own name, so a
static version =, a dynamic attribute and a VCS plugin all answer alike.
on:
release: { types: [published] }
pull_request: # builds and checks; never publishes
workflow_dispatch:
jobs:
package:
uses: ChiefGyk3D/git-your-ship-together/.github/workflows/python-package-release.yml@<sha> # vX.Y.Z
permissions:
contents: write # the GitHub release and its assets
id-token: write # build provenance
attestations: write # the provenance record
with:
publish: ${{ github.event_name == 'release' }} # the GitHub release step; pypi stays false
allowed-publish-events: push,release # publishing is an allow-list; the default is push only
verify-command: grep -q "^## \[$VERSION\]" CHANGELOG.md
smoke-command: my-cli --version
egress-policy: block
publish-pypi:
needs: package
if: github.event_name == 'release'
runs-on: ubuntu-latest
environment:
name: pypi # the name the Trusted Publisher on PyPI holds
url: https://pypi.org/p/<project>
permissions:
contents: read
id-token: write # PyPI Trusted Publishing; the OIDC token names THIS workflow
steps:
- uses: step-security/harden-runner@<sha> # vX.Y.Z
with:
egress-policy: block
allowed-endpoints: api.github.com:443 files.pythonhosted.org:443 fulcio.sigstore.dev:443 ghcr.io:443 github.com:443 pkg-containers.githubusercontent.com:443 productionresultssa12.blob.core.windows.net:443 pypi.org:443 rekor.sigstore.dev:443 release-assets.githubusercontent.com:443 timestamp.sigstore.dev:443 tuf-repo-cdn.sigstore.dev:443 upload.pypi.org:443 uploads.github.com:443
disable-sudo: true
disable-telemetry: true
- uses: actions/download-artifact@<sha> # vX.Y.Z
with:
name: dist
path: dist/
- uses: pypa/gh-action-pypi-publish@<sha> # vX.Y.Z
with:
attestations: trueWhy PyPI is published from your workflow. PyPI matches the OIDC token's job_workflow_ref. Inside a reusable workflow that is
the reusable file, so a Trusted Publisher registered for your workflow is answered invalid-publisher even when owner, repository,
workflow file and environment all match (warehouse#11096; hypeman v0.3.1 and v0.3.2). The publish-pypi job above lives in your file, needs the package job, downloads the dist artifact and runs
pypa/gh-action-pypi-publish with attestations, so the token names your workflow. The
package job keeps publish: on so the GitHub release step still runs, with pypi left false. The pypa action is a Docker
action, so the job's harden-runner list needs ghcr.io:443 and pkg-containers.githubusercontent.com:443 under block.
Warning: the pypa action must be a direct step of your job. pypa/gh-action-pypi-publish is a Docker action that derives its image from the repository of the action that contains it. Wrapped in a composite action or a reusable workflow it resolves to that repository's image: GYST v1.19.0 wrapped it in a composite, and hypeman's v0.3.3 release ran docker run ghcr.io/ChiefGyk3D/git-your-ship-together:<sha>, which does not exist, and failed with "Run 'docker run --help'" (run 37976560401). Keep both steps in your own job, as above.
PyPI setup, once per project. On the project's Publishing page add a Trusted Publisher naming this owner, the calling
repository, the file name of the workflow that holds the publish-pypi job and the environment pypi. That is the whole credential.
The workflow outputs version. SBOMs are not attached yet; see issue #99 on Releases and supply chain.
Inputs (23), read from python-package-release.yml:
| Input | Type | Default | Meaning |
|---|---|---|---|
python-version |
string | 3.13 |
Python used to build, check and smoke-test the package. |
package-directory |
string | . |
Directory holding pyproject.toml, relative to the repository root. |
build-install-command |
string | python -m pip install --upgrade pip build twine |
Shell that installs the build tooling. |
build-command |
string | python -m build |
Shell that writes the sdist and wheel to dist/. |
tag-prefix |
string | v |
What precedes the version in a release tag; v makes v1.2.3 the tag for version 1.2.3. |
verify-command |
string | empty | Shell run after the build with $VERSION set, to refuse a release whose tree disagrees with it, e.g. grep -q "^## \[$VERSION\]" CHANGELOG.md; empty runs nothing. |
smoke-command |
string | empty | Shell run with the built wheel installed in a fresh venv on PATH and $VERSION set, e.g. my-cli --version; empty skips the check. |
release-notes-command |
string | empty | Shell that prints the GitHub release notes to stdout with $VERSION set, e.g. a CHANGELOG section; empty lets GitHub generate them from the commits. |
publish |
boolean | false |
Publish to the GitHub release. False builds, checks and stops; a pull request never publishes whatever this says. |
allowed-publish-events |
string | push |
Comma-separated event names (no spaces) that may publish, when the ref is also a release tag (refs/tags/v<major>.<minor>.<patch>). Default push; a caller that publishes on release sets push,release. A pull request event is refused even if listed. |
pypi |
boolean | false |
Unsupported, kept so old callers still parse. PyPI Trusted Publishing cannot use a reusable workflow as the publisher (invalid-publisher, warehouse#11096), so true fails the run with the fix; publish from a job in the caller's workflow with the publish-pypi composite action instead. |
pypi-environment |
string | pypi |
Unused by this workflow; the environment belongs to the caller's publish job. Kept so existing callers still parse. |
github-release |
boolean | true |
Attach the distribution files, their SBOMs, their SHA256SUMS and build provenance to the GitHub release for the tag. |
release-title |
string | empty | Title of a GitHub release this workflow creates; empty uses the tag. |
sbom |
boolean | true |
Write a CycloneDX and an SPDX SBOM for the built wheel and sdist (syft, pinned) and attach them to the GitHub release with the rest, listed in SHA256SUMS and covered by the same build provenance. They are written whenever the package is built, so a pull request exercises them; they are only published with the release. |
syft-version |
string | 1.56.0 |
syft release to download (anchore/syft), without the v; the one syft pin in this repository. Changing it means changing syft-sha256. To bump - gh release download v<new> -R anchore/syft -p '*_linux_amd64.tar.gz', sha256sum it and compare the line in the release's own *_checksums.txt. |
syft-sha256 |
string | 1c2493cfcf52d3367d6cb25780d9190c111c2219c34c820574c43e8bae15c528 |
SHA-256 of the syft linux_amd64 tarball for that version. |
attest |
boolean | true |
Record SLSA build provenance for every distribution file through GitHub's attestation API. |
egress-policy |
string | audit |
harden-runner egress policy for every job - audit logs outbound connections, block allows only allowed-endpoints. Jobs that hold no secret follow egress-policy-secretless instead (EX-0001). |
egress-policy-secretless |
string | block |
harden-runner egress policy for the jobs that hold no stored secret, no OIDC token and no write-scoped or publish-capable token (read-only contents, a SARIF upload at most), and whose output no privileged job consumes - exactly audit or block. Defaults to block since security exception EX-0001 (GitHub-hosted runners in westus2 broke harden-runner block) was closed on 2026-11-02 after harden-runner v2.22.3 passed on westus2; see docs/security/exceptions/. Every job still has the default read-only job token. Set audit to opt out if the defect recurs. Any other job follows egress-policy. Any other value fails the job. |
allowed-endpoints |
string | api.github.com:443 files.pythonhosted.org:443 fulcio.sigstore.dev:443 github.com:443 pypi.org:443 rekor.sigstore.dev:443 release-assets.githubusercontent.com:443 timestamp.sigstore.dev:443 tuf-repo-cdn.sigstore.dev:443 upload.pypi.org:443 uploads.github.com:443 |
harden-runner allow-list for block, space-separated host:port entries. The build hosts were measured by running the build in block mode here; the release job's hosts are GitHub's and Sigstore's documented ones. Wildcards are not supported and a newline-separated list matches nothing. |
extra-allowed-endpoints |
string | empty | Appended to allowed-endpoints, for hosts only this repository reaches. Same format. |
timeout-minutes |
number | 20 |
Per-job timeout. |
Outputs a caller job can read:
| Output | Meaning |
|---|---|
version |
The version the sdist was built as. |
It never publishes from a pull request, never publishes a tag that disagrees with the packaged version, and never needs a stored credential.
Generated from docs/wiki/ at commit f3af2fa0bae3. Do not edit this wiki: the next push to main replaces every page. Corrections go to docs/wiki/ by pull request.
GYST
- Home
- Why GYST exists
- Getting started
- Design rules
- Secrets: Doppler and OIDC
- Security scanning explained
- The baseline and the weekly audit
- Releases and supply chain
- Keeping a project board current
- Adopting GYST in your own project
- Glossary
- Roadmap
Learn and contribute
- Learning path
- Which workflow do I need?
- Repository map
- Egress control
- Troubleshooting
- Lessons learned
- Testing and the contract
- Contributing and developing
- Maintaining this wiki
- Verify main
- FAQ
CI
Security
Release
- container-release
- python-docker-release
- python-package-release
- artifact-release
- verify-published
- base-image-digest
Docs and project
- docs-pages
- wiki-publish
- project-sync
- threat-model
- lory-audit
- agent-scan
- token-drift
- node-typecheck
- pr-title-lint
- vendored-drift
- upstream-sync
- repin
- pin-comments
Tools