From ae603e12e1fd11521aba90e0c5369815620b6d5c Mon Sep 17 00:00:00 2001 From: Mengxin Zhu <843303+zxkane@users.noreply.github.com> Date: Wed, 9 Apr 2025 12:14:29 +0800 Subject: [PATCH 1/2] Add GitHub Actions workflow to publish package to PyPI --- .github/workflows/release.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..265cf96 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,35 @@ +name: Publish Python Package to PyPI + +on: + push: + tags: + - 'v*.*.*' # Trigger on version tags like v1.0.0 + workflow_dispatch: # Allow manual trigger + +jobs: + build-and-publish: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python 3.12 + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Upgrade pip + run: python -m pip install --upgrade pip + + - name: Install build tools + run: pip install build twine + + - name: Build the package + run: python -m build + + - name: Publish package to PyPI + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} + run: twine upload dist/* --non-interactive --skip-existing From aca48475ecaf1203cf17f4c666aea980d01b8a4d Mon Sep 17 00:00:00 2001 From: Mengxin Zhu <843303+zxkane@users.noreply.github.com> Date: Wed, 9 Apr 2025 12:17:34 +0800 Subject: [PATCH 2/2] Update release workflow to use PyPI Trusted Publisher with OIDC --- .github/workflows/release.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 265cf96..fb4e138 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,6 +9,9 @@ on: jobs: build-and-publish: runs-on: ubuntu-latest + # Enable OIDC token permissions for Trusted Publisher + permissions: + id-token: write steps: - name: Checkout repository @@ -23,13 +26,11 @@ jobs: run: python -m pip install --upgrade pip - name: Install build tools - run: pip install build twine + run: pip install build - name: Build the package run: python -m build - - name: Publish package to PyPI - env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} - run: twine upload dist/* --non-interactive --skip-existing + - name: Publish package distributions to PyPI using Trusted Publisher + # This action uses OIDC to authenticate without API tokens + uses: pypa/gh-action-pypi-publish@release/v1