name: Publish Release permissions: contents: read concurrency: # stop previous release runs if tag is recreated group: release-${{ github.ref }} cancel-in-progress: true on: push: tags: - "v[0-9]*.[0-9]*.[0-9]*" # only publish on version tags (e.g. v1.0.0) jobs: lint: permissions: contents: read uses: ./.github/workflows/lint.yml test: permissions: contents: read id-token: write # to allow codecov oidc upload uses: ./.github/workflows/test.yml build: name: Build Package runs-on: ubuntu-latest permissions: contents: read outputs: PACKAGE_NAME: ${{ steps.set-package.outputs.package_name }} RELEASE_VERSION: ${{ steps.set-package.outputs.release_version }} steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 with: persist-credentials: false - name: Set up Python uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 with: python-version: "3.14" # for tomlib - name: Install uv uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 with: enable-cache: false restore-cache: false save-cache: false - name: Setup Just uses: extractions/setup-just@53165ef7e734c5c07cb06b3c8e7b647c5aa16db3 - name: Verify Tag run: | TAG_NAME=${GITHUB_REF#refs/tags/} echo "Verifying tag $TAG_NAME..." # if a tag was deleted and recreated we may have the old one cached # be sure that we're publishing the current tag! git fetch --force origin refs/tags/$TAG_NAME:refs/tags/$TAG_NAME # verify signature curl -sL "https://github.com/${GITHUB_ACTOR}.gpg" | gpg --import git tag -v "$TAG_NAME" # verify version RELEASE_VERSION=$(just validate_version $TAG_NAME) # export the release version echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV - name: Install gettext run: sudo apt-get install -y gettext - name: Build the binary wheel and a source tarball run: just build - name: Store the distribution packages uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a with: name: python-package-distributions path: dist/ - name: Set Package Name id: set-package run: PACKAGE_NAME=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['name'])") echo "PACKAGE_NAME=${PACKAGE_NAME}" >> $GITHUB_ENV publish-to-pypi: name: Publish to PyPI needs: - lint - test - build runs-on: ubuntu-latest environment: name: pypi url: https://pypi.org/p/${{ needs.build.outputs.PACKAGE_NAME }} permissions: id-token: write # IMPORTANT: mandatory for trusted publishing steps: - name: Download all the dists uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c with: name: python-package-distributions path: dist/ - name: Publish distribution 📦 to PyPI uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b github-release: name: Publish GitHub Release runs-on: ubuntu-latest needs: - lint - test - build permissions: contents: write # IMPORTANT: mandatory for making GitHub Releases id-token: write # IMPORTANT: mandatory for sigstore steps: - name: Download all the dists uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c with: name: python-package-distributions path: dist/ - name: Sign the dists with Sigstore uses: sigstore/gh-action-sigstore-python@5b79a39c381910c090341a2c9b0bf022c8b387e1 with: inputs: >- ./dist/*.tar.gz ./dist/*.whl - name: Create GitHub Release env: GITHUB_TOKEN: ${{ github.token }} GITHUB_REF_NAME: ${{ github.ref_name }} GITHUB_REPOSITORY: ${{ github.repository }} run: >- gh release create "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" --generate-notes - name: Upload artifact signatures to GitHub Release env: GITHUB_TOKEN: ${{ github.token }} GITHUB_REF_NAME: ${{ github.ref_name }} GITHUB_REPOSITORY: ${{ github.repository }} # Upload to GitHub Release using the `gh` CLI. # `dist/` contains the built packages, and the # sigstore-produced signatures and certificates. run: >- gh release upload "$GITHUB_REF_NAME" dist/** --repo "$GITHUB_REPOSITORY" # chrisglass owns this: https://test.pypi.org/project/django-polymorphic/ # publish-to-testpypi: # name: Publish to TestPyPI # needs: # - build # runs-on: ubuntu-latest # environment: # name: testpypi # url: https://test.pypi.org/project/${{ needs.build.outputs.PACKAGE_NAME }} # permissions: # id-token: write # IMPORTANT: mandatory for trusted publishing # steps: # - name: Download all the dists # uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # with: # name: python-package-distributions # path: dist/ # - name: Publish distribution 📦 to TestPyPI # uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # with: # repository-url: https://test.pypi.org/legacy/ # skip-existing: true