Skip to content

ci: add manual PyPI trusted publishing - #7

Merged
saagpatel merged 1 commit into
mainfrom
codex/pypi-trusted-publishing
May 18, 2026
Merged

ci: add manual PyPI trusted publishing#7
saagpatel merged 1 commit into
mainfrom
codex/pypi-trusted-publishing

Conversation

@saagpatel

Copy link
Copy Markdown
Owner

What

  • Adds a manual Publish to PyPI workflow that builds a selected v* release tag and publishes with PyPI Trusted Publishing.
  • Documents the required PyPI Trusted Publisher settings and protected pypi environment expectation.
  • Extends distribution-policy tests to guard the manual-only workflow and OIDC publish permissions.

Why

  • The public repo is release-ready on GitHub Releases, but PyPI should have a safe activation path before the first registry publish.
  • Trusted Publishing avoids long-lived PyPI tokens and keeps publishing behind an intentional manual workflow.

How

  • Uses workflow_dispatch only, validates a v* tag input, builds wheel/sdist, runs twine check, uploads distributions, then publishes from a separate pypi environment job with id-token: write.

Testing

  • 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 with PyYAML

Performance Impact

  • None expected; workflow/docs/test-only change.

Risk / Notes

  • This does not publish to PyPI by itself. PyPI still requires Trusted Publisher configuration for owner saagpatel, repository GithubRepoAuditor, workflow pypi.yml, environment pypi, plus an intentional manual run.

- 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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +20 to +22
case "${{ inputs.ref }}" in
v*) ;;
*) echo "PyPI publishes must use a PEP 440-compatible v* release tag."; exit 1 ;;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@saagpatel
saagpatel merged commit 182a821 into main May 18, 2026
1 check passed
@saagpatel
saagpatel deleted the codex/pypi-trusted-publishing branch May 18, 2026 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant