diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..cb7a441 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,95 @@ +name: Publish to PyPI + +on: + release: + types: [published] + workflow_dispatch: + +permissions: + contents: read + +jobs: + build: + name: Build distributions + if: github.event_name == 'workflow_dispatch' || startsWith(github.event.release.tag_name, 'v') + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v7.0.1 + with: + persist-credentials: false + + - name: Install uv + uses: astral-sh/setup-uv@v10.1.0 + with: + python-version: "3.11" + + - name: Check release tag matches project version + if: github.event_name == 'release' + env: + TAG: ${{ github.event.release.tag_name }} + run: | + version="$(uv version --short)" + if [ "$TAG" != "v$version" ]; then + echo "::error::Release tag '$TAG' does not match expected tag 'v$version'." + exit 1 + fi + + - name: Build sdist and wheel + run: uv build + + - name: Check distribution metadata + run: uvx twine check --strict dist/* + + - name: Upload distributions + uses: actions/upload-artifact@v4 + with: + name: dist + path: dist/ + if-no-files-found: error + + publish-testpypi: + name: Publish to TestPyPI + if: github.event_name == 'workflow_dispatch' + needs: build + runs-on: ubuntu-latest + timeout-minutes: 10 + environment: + name: testpypi + url: https://test.pypi.org/p/seriousdb + permissions: + # Required to request the OIDC token used for Trusted Publishing. + id-token: write + steps: + - name: Download distributions + uses: actions/download-artifact@v4 + with: + name: dist + path: dist/ + + - name: Publish to TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + + publish-pypi: + name: Publish to PyPI + if: github.event_name == 'release' + needs: build + runs-on: ubuntu-latest + timeout-minutes: 10 + environment: + name: pypi + url: https://pypi.org/p/seriousdb + permissions: + # Required to request the OIDC token used for Trusted Publishing. + id-token: write + steps: + - name: Download distributions + uses: actions/download-artifact@v4 + with: + name: dist + path: dist/ + + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1