Skip to content

Commit 71f4632

Browse files
jeremyederclaude
andauthored
feat: automate PyPI publishing with trusted publishing (OIDC) (#154)
- Add id-token: write permission for OIDC authentication - Use pypa/gh-action-pypi-publish action (no tokens required) - Detect new releases by comparing version before/after semantic-release - Publish to Test PyPI first, then production PyPI - Only publish when semantic-release creates new version This replaces the manual publish-pypi.yml workflow with fully automated publishing as part of the release process. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent 850817c commit 71f4632

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

.github/workflows/release.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ permissions:
1010
contents: write
1111
issues: write
1212
pull-requests: write
13+
id-token: write # Required for trusted publishing to PyPI
1314

1415
jobs:
1516
release:
@@ -31,7 +32,54 @@ jobs:
3132
run: |
3233
npm install -g semantic-release @semantic-release/changelog @semantic-release/git @semantic-release/github @semantic-release/exec
3334
35+
- name: Get version before release
36+
id: version_before
37+
run: echo "version=$(grep '^version = ' pyproject.toml | cut -d'"' -f2)" >> $GITHUB_OUTPUT
38+
3439
- name: Run semantic-release
3540
env:
3641
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3742
run: npx semantic-release
43+
44+
- name: Get version after release
45+
id: version_after
46+
run: echo "version=$(grep '^version = ' pyproject.toml | cut -d'"' -f2)" >> $GITHUB_OUTPUT
47+
48+
- name: Check if new release
49+
id: check_release
50+
run: |
51+
if [ "${{ steps.version_before.outputs.version }}" != "${{ steps.version_after.outputs.version }}" ]; then
52+
echo "new_release=true" >> $GITHUB_OUTPUT
53+
echo "version=${{ steps.version_after.outputs.version }}" >> $GITHUB_OUTPUT
54+
else
55+
echo "new_release=false" >> $GITHUB_OUTPUT
56+
fi
57+
58+
- name: Set up Python
59+
if: steps.check_release.outputs.new_release == 'true'
60+
uses: actions/setup-python@v5
61+
with:
62+
python-version: '3.12'
63+
64+
- name: Install build dependencies
65+
if: steps.check_release.outputs.new_release == 'true'
66+
run: |
67+
python -m pip install --upgrade pip
68+
pip install build
69+
70+
- name: Build package
71+
if: steps.check_release.outputs.new_release == 'true'
72+
run: |
73+
python -m build
74+
echo "📦 Built distribution files:"
75+
ls -lh dist/
76+
77+
- name: Publish to Test PyPI
78+
if: steps.check_release.outputs.new_release == 'true'
79+
uses: pypa/gh-action-pypi-publish@release/v1
80+
with:
81+
repository-url: https://test.pypi.org/legacy/
82+
83+
- name: Publish to PyPI
84+
if: steps.check_release.outputs.new_release == 'true'
85+
uses: pypa/gh-action-pypi-publish@release/v1

0 commit comments

Comments
 (0)