Skip to content

Commit ab9c373

Browse files
committed
Switch PyPI publishing to Trusted Publishing with auto version bump
1 parent c84d10b commit ab9c373

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

.github/workflows/publish-pypi.yml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ on:
1515
- pypi
1616

1717
permissions:
18-
contents: read
18+
contents: write
19+
id-token: write
1920

2021
jobs:
2122
build-and-publish:
@@ -25,6 +26,14 @@ jobs:
2526
- name: Checkout
2627
uses: actions/checkout@v4
2728

29+
- name: Update version from release tag
30+
if: github.event_name == 'release'
31+
run: |
32+
VERSION="${{ github.ref_name }}"
33+
VERSION="${VERSION#v}"
34+
echo "Updating pyproject.toml version to $VERSION"
35+
sed -i "s/^version = \".*\"/version = \"$VERSION\"/" pyproject.toml
36+
2837
- name: Setup Node
2938
uses: actions/setup-node@v4
3039
with:
@@ -58,17 +67,13 @@ jobs:
5867

5968
- name: Publish to Test PyPI
6069
if: github.event_name == 'workflow_dispatch' && inputs.publish_to == 'testpypi'
61-
env:
62-
TWINE_USERNAME: __token__
63-
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }}
64-
run: twine upload --repository testpypi dist/*
70+
uses: pypa/gh-action-pypi-publish@release/v1
71+
with:
72+
repository-url: https://test.pypi.org/legacy/
6573

6674
- name: Publish to PyPI
6775
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.publish_to == 'pypi')
68-
env:
69-
TWINE_USERNAME: __token__
70-
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
71-
run: twine upload dist/*
76+
uses: pypa/gh-action-pypi-publish@release/v1
7277

7378
- name: Upload build artifacts
7479
uses: actions/upload-artifact@v4

0 commit comments

Comments
 (0)