diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..f7caba8 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,72 @@ +name: Release to PyPI + +on: + release: + types: [published] + +permissions: + contents: read + +jobs: + build: + name: Build distribution packages + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install uv + uses: astral-sh/setup-uv@v5 + + - name: Build package + run: uv build + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: dist-${{ github.run_id }} + path: dist/ + + publish: + name: Publish to PyPI + needs: build + runs-on: ubuntu-latest + if: "!github.event.release.prerelease" + permissions: + contents: read + id-token: write + steps: + - name: Download build artifacts + uses: actions/download-artifact@v4 + with: + name: dist-${{ github.run_id }} + path: dist/ + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install uv + uses: astral-sh/setup-uv@v5 + + - name: Check release tag + id: stable_tag + env: + TAG: ${{ github.event.release.tag_name }} + run: | + if [[ "$TAG" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "publish=true" >>"$GITHUB_OUTPUT" + exit 0 + fi + echo "::notice::Skipping publish for non-stable tag: $TAG" + echo "publish=false" >>"$GITHUB_OUTPUT" + + - name: Publish to PyPI with uv + if: steps.stable_tag.outputs.publish == 'true' + run: uv publish --trusted-publishing always --check-url https://pypi.org/simple