ci: add manual PyPI trusted publishing - #7
Conversation
- add a workflow_dispatch-only PyPI publish workflow - document Trusted Publishing setup and release use - guard the distribution policy with tests Tests: ruff check src/ tests/; python3 -m pytest tests/test_distribution_policy.py tests/test_versioning.py -q -p no:cacheprovider; python3 -m pytest -q -p no:cacheprovider; parsed .github/workflows/*.yml
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a1b54756e0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| steps: | ||
| - name: Validate release ref | ||
| run: | | ||
| case "${{ inputs.ref }}" in |
There was a problem hiding this comment.
Avoid interpolating dispatch input into the shell
When someone who can manually run this workflow enters a ref such as v$(...), GitHub substitutes the raw workflow_dispatch input into this run script and the shell evaluates the command substitution before the case match. That lets the dispatch input execute arbitrary commands in the build job before checkout; pass the input through an environment variable and validate the variable value instead.
Useful? React with 👍 / 👎.
| case "${{ inputs.ref }}" in | ||
| v*) ;; | ||
| *) echo "PyPI publishes must use a PEP 440-compatible v* release tag."; exit 1 ;; |
There was a problem hiding this comment.
Reject non-tag refs before publishing
This check only verifies that the input starts with v, so a mutable branch named vnext or v0.1.2-fix can be selected and then built/published even though the workflow and release docs say PyPI publishes must come from release tags. Validate that the input resolves to refs/tags/<ref> before building so the protected publish job cannot publish an untagged branch by mistake.
Useful? React with 👍 / 👎.
What
Publish to PyPIworkflow that builds a selectedv*release tag and publishes with PyPI Trusted Publishing.pypienvironment expectation.Why
How
workflow_dispatchonly, validates av*tag input, builds wheel/sdist, runstwine check, uploads distributions, then publishes from a separatepypienvironment job withid-token: write.Testing
.github/workflows/*.ymlwith PyYAMLPerformance Impact
Risk / Notes
saagpatel, repositoryGithubRepoAuditor, workflowpypi.yml, environmentpypi, plus an intentional manual run.