Skip to content
Merged
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
26 changes: 9 additions & 17 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,9 @@ name: publish
on:
push:
tags: ["v*"]
# Manual run: checks the trusted-publisher token exchange for this workflow
# without uploading anything (see the publisher-check job).
# Manual run: checks the PyPI trusted-publisher token exchange for this
# workflow without uploading anything (see the publisher-check job).
workflow_dispatch:
inputs:
index:
description: Index to check against
type: choice
options: [testpypi, pypi]
default: testpypi

permissions: {}

Expand Down Expand Up @@ -146,22 +140,20 @@ jobs:
echo "::error::sdo-client==${SDO_EXPECTED_VERSION} never became installable"
exit 1

# `workflow_dispatch` only: asks the chosen index to exchange this job's OIDC
# token for an upload token, the same exchange the publish action performs,
# and prints the claims the index matches against and its answer. Nothing is
# uploaded and a minted token is never printed (it expires on its own). On
# an index with a pending publisher, a successful exchange creates the empty
# project, as the first upload would.
# `workflow_dispatch` only: asks PyPI to exchange this job's OIDC token for an
# upload token, the same exchange the publish action performs, and prints the
# claims PyPI matches against and its answer. Nothing is uploaded and a
# minted token is never printed (it expires on its own).
publisher-check:
if: github.repository_owner == 'scrape-do' && github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
environment: ${{ inputs.index == 'pypi' && 'release' || 'prerelease' }}
environment: release
permissions:
id-token: write
steps:
- name: Exchange the GitHub OIDC token with the index
- name: Exchange the GitHub OIDC token with PyPI
env:
INDEX_HOST: ${{ inputs.index == 'pypi' && 'pypi.org' || 'test.pypi.org' }}
INDEX_HOST: pypi.org
run: |
set -euo pipefail
audience="$(curl -sSf "https://${INDEX_HOST}/_/oidc/audience" \
Expand Down
17 changes: 9 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ This repository is public. Practically, for you as a contributor, this means: ke
| `ci.yml` | every push to `main` and every pull request | `ruff` lint and format check; `mypy --strict`; the test suite with the 99% line + branch coverage floor on Python 3.11–3.14 (Linux), plus macOS and Windows on 3.13, including the cross-language conformance suite and its integrity check; the public-API snapshot (`api-surface.txt`) must be up to date; CodeQL code scanning. |
| `commits.yml` | every pull request: opened, updated, reopened, or its title or description edited | the `commits` job checks every commit's subject and sign-off and the pull request title, which becomes the squash commit's subject. A workflow of its own, so editing a pull request re-runs only this check. |
| `security.yml` | push to `main`, pull requests, and weekly | secret scanning over the full git history (gitleaks), OSV-Scanner over the pinned requirement files, `pip-audit`, and an SBOM uploaded as a build artifact. OpenSSF Scorecard runs on pushes to `main` and weekly, with results in code scanning. |
| `publish.yml` | a version tag, or a manual run | A tag `vX.Y.Z-rc.N` publishes a release candidate to **TestPyPI**; a tag `vX.Y.Z` publishes to **PyPI**. The tag must be on `main` and match `src/sdo/_version.py` (`X.Y.ZrcN` for a candidate). The package is built once with hash-pinned tooling, checked with `twine check`, published by trusted publishing (no stored token) after approval in the `prerelease` or `release` environment, and then installed from the index as a smoke test. A manual run (Actions → publish → Run workflow, index `testpypi` or `pypi`) uploads nothing: its `publisher-check` job only confirms that the index accepts this workflow's OIDC token, after approval in the matching environment. |
| `publish.yml` | a version tag, or a manual run | A tag `vX.Y.Z-rc.N` publishes a release candidate to **TestPyPI**; a tag `vX.Y.Z` publishes to **PyPI**. The tag must be on `main` and match `src/sdo/_version.py` (`X.Y.ZrcN` for a candidate). The package is built once with hash-pinned tooling, checked with `twine check`, published by trusted publishing (no stored token) after approval in the `prerelease` or `release` environment, and then installed from the index as a smoke test. A manual run (Actions → publish → Run workflow) uploads nothing: its `publisher-check` job only confirms that PyPI accepts this workflow's OIDC token, after approval in the `release` environment. |
| Dependabot | weekly | update pull requests for the GitHub Actions, taken only after a 7-day cooldown, and security-advisory pull requests for the pinned Python requirements, which the cooldown does not delay (version bumps of those are recompiled by hand with uv, see [Dev setup](#dev-setup)); each one runs the checks above. |

Every job runs on GitHub-hosted runners except CodeQL and Scorecard, which run on the organisation's self-hosted runners: their uploads are GitHub API calls that the organisation's IP allow list only accepts from there. CodeQL runs there for same-repository events only, so a pull request from a fork is analysed once merged; Scorecard never runs on a pull request. Every action is pinned to a full commit SHA and every job declares least-privilege `permissions:`. Publishing never happens outside the `scrape-do` organisation, never from a commit that is not on `main`, and never without a maintainer's approval.
Expand Down Expand Up @@ -260,21 +260,22 @@ so it accepts it (unlike npm, see `sdo-sdk-js`), and no token fallback is needed

### Checking a publisher without uploading

A manual run of `publish.yml` performs only the token exchange (the
`publisher-check` job) and prints the claims the index matched and its answer.
The environments accept only `v*` tags, so allow `main` for the duration of the
run and remove the rule afterwards:
A manual run of `publish.yml` performs only the PyPI token exchange (the
`publisher-check` job) and prints the claims PyPI matched and its answer. There
is no such check for TestPyPI. The `release` environment accepts only `v*`
tags, so allow `main` for the duration of the run and remove the rule
afterwards:

```sh
env=prerelease # or release, for index=pypi
env=release
id=$(gh api -X POST "repos/scrape-do/sdo-sdk-python/environments/$env/deployment-branch-policies" \
-f name=main -f type=branch --jq .id)
gh workflow run publish.yml --repo scrape-do/sdo-sdk-python --ref main -f index=testpypi # or pypi
gh workflow run publish.yml --repo scrape-do/sdo-sdk-python --ref main
# approve the run in the environment, wait for it to finish, then:
gh api -X DELETE "repos/scrape-do/sdo-sdk-python/environments/$env/deployment-branch-policies/$id"
```

`HTTP 200` means the index accepts the workflow. `invalid-publisher` means no
`HTTP 200` means PyPI accepts the workflow. `invalid-publisher` means no
publisher matches the claims: compare the printed `repository`, `environment`
and `job_workflow_ref` with the table above.

Expand Down
Loading