|
1 | | -name: Release |
| 1 | +name: Publish Release |
| 2 | + |
| 3 | +permissions: read-all |
| 4 | + |
| 5 | +concurrency: |
| 6 | + # stop previous release runs if tag is recreated |
| 7 | + group: release-${{ github.ref }} |
| 8 | + cancel-in-progress: true |
| 9 | + |
2 | 10 | on: |
3 | 11 | push: |
4 | | - branches: |
5 | | - - master |
6 | 12 | tags: |
7 | | - - '*' |
| 13 | + - 'v*' # only publish on version tags (e.g. v1.0.0) |
8 | 14 |
|
9 | 15 | jobs: |
10 | | - Build: |
11 | | - runs-on: ubuntu-22.04 |
| 16 | + |
| 17 | + lint: |
| 18 | + if: github.repository == 'jazzband/django-polymorphic' |
| 19 | + permissions: |
| 20 | + contents: read |
| 21 | + actions: write |
| 22 | + uses: ./.github/workflows/lint.yml |
| 23 | + secrets: inherit |
| 24 | + |
| 25 | + test: |
| 26 | + if: github.repository == 'jazzband/django-polymorphic' |
| 27 | + permissions: |
| 28 | + contents: read |
| 29 | + actions: write |
| 30 | + uses: ./.github/workflows/test.yml |
| 31 | + secrets: inherit |
| 32 | + |
| 33 | + build: |
| 34 | + if: github.repository == 'jazzband/django-polymorphic' |
| 35 | + name: Build Package |
| 36 | + runs-on: ubuntu-latest |
| 37 | + permissions: |
| 38 | + contents: read |
| 39 | + actions: write |
| 40 | + outputs: |
| 41 | + PACKAGE_NAME: ${{ steps.set-package.outputs.package_name }} |
| 42 | + RELEASE_VERSION: ${{ steps.set-package.outputs.release_version }} |
| 43 | + steps: |
| 44 | + - uses: actions/checkout@v6 |
| 45 | + - name: Set up Python |
| 46 | + uses: actions/setup-python@v6 |
| 47 | + id: sp |
| 48 | + with: |
| 49 | + python-version: "3.13" # for tomlib |
| 50 | + - name: Install uv |
| 51 | + uses: astral-sh/setup-uv@v7 |
| 52 | + with: |
| 53 | + enable-cache: true |
| 54 | + - name: Setup Just |
| 55 | + uses: extractions/setup-just@v3 |
| 56 | + - name: Install Dependencies |
| 57 | + run: | |
| 58 | + just setup ${{ steps.sp.outputs.python-path }} |
| 59 | + - name: Verify Tag |
| 60 | + run: | |
| 61 | + TAG_NAME=${GITHUB_REF#refs/tags/} |
| 62 | + echo "Verifying tag $TAG_NAME..." |
| 63 | + # if a tag was deleted and recreated we may have the old one cached |
| 64 | + # be sure that we're publishing the current tag! |
| 65 | + git fetch --force origin refs/tags/$TAG_NAME:refs/tags/$TAG_NAME |
| 66 | +
|
| 67 | + # verify signature |
| 68 | + curl -sL https://github.com/${{ github.actor }}.gpg | gpg --import |
| 69 | + git tag -v "$TAG_NAME" |
| 70 | +
|
| 71 | + # verify version |
| 72 | + RELEASE_VERSION=$(just validate_version $TAG_NAME) |
| 73 | +
|
| 74 | + # export the release version |
| 75 | + echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV |
| 76 | + - name: Build the binary wheel and a source tarball |
| 77 | + run: just build |
| 78 | + - name: Store the distribution packages |
| 79 | + uses: actions/upload-artifact@v5 |
| 80 | + with: |
| 81 | + name: python-package-distributions |
| 82 | + path: dist/ |
| 83 | + - name: Set Package Name |
| 84 | + id: set-package |
| 85 | + run: |
| 86 | + PACKAGE_NAME=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['name'])") |
| 87 | + echo "PACKAGE_NAME=${PACKAGE_NAME}" >> $GITHUB_ENV |
| 88 | + |
| 89 | + publish-to-pypi: |
| 90 | + name: Publish to PyPI |
| 91 | + needs: |
| 92 | + - lint |
| 93 | + - test |
| 94 | + - build |
| 95 | + runs-on: ubuntu-latest |
| 96 | + steps: |
| 97 | + - name: Download all the dists |
| 98 | + uses: actions/download-artifact@v6 |
| 99 | + with: |
| 100 | + name: python-package-distributions |
| 101 | + path: dist/ |
| 102 | + - name: Upload Package to Jazzband |
| 103 | + uses: pypa/gh-action-pypi-publish@release/v1.13 |
| 104 | + with: |
| 105 | + user: jazzband |
| 106 | + password: ${{ secrets.JAZZBAND_RELEASE_KEY }} |
| 107 | + repository-url: https://jazzband.co/projects/django-polymorphic/upload |
| 108 | + |
| 109 | + github-release: |
| 110 | + name: Publish GitHub Release |
| 111 | + runs-on: ubuntu-latest |
| 112 | + needs: |
| 113 | + - lint |
| 114 | + - test |
| 115 | + - build |
| 116 | + permissions: |
| 117 | + contents: write # IMPORTANT: mandatory for making GitHub Releases |
| 118 | + id-token: write # IMPORTANT: mandatory for sigstore |
| 119 | + |
12 | 120 | steps: |
13 | | - - uses: actions/checkout@v4 |
14 | | - - uses: actions/setup-python@v5 |
15 | | - with: |
16 | | - python-version: "3" |
17 | | - cache: pip |
18 | | - cache-dependency-path: setup.cfg |
19 | | - - name: Install uv |
20 | | - uses: astral-sh/setup-uv@v6 |
21 | | - with: |
22 | | - enable-cache: true |
23 | | - - name: Setup Just |
24 | | - uses: extractions/setup-just@v3 |
25 | | - - run: sudo apt-get update && sudo apt-get install -y --no-install-recommends gettext |
26 | | - - run: just build |
27 | | - - uses: actions/upload-artifact@v4 |
28 | | - with: |
29 | | - name: dist |
30 | | - path: dist/ |
| 121 | + - name: Download all the dists |
| 122 | + uses: actions/download-artifact@v6 |
| 123 | + with: |
| 124 | + name: python-package-distributions |
| 125 | + path: dist/ |
| 126 | + - name: Sign the dists with Sigstore |
| 127 | + uses: sigstore/gh-action-sigstore-python@v3.1.0 |
| 128 | + with: |
| 129 | + inputs: >- |
| 130 | + ./dist/*.tar.gz |
| 131 | + ./dist/*.whl |
| 132 | + - name: Create GitHub Release |
| 133 | + env: |
| 134 | + GITHUB_TOKEN: ${{ github.token }} |
| 135 | + run: >- |
| 136 | + gh release create |
| 137 | + '${{ github.ref_name }}' |
| 138 | + --repo '${{ github.repository }}' |
| 139 | + --generate-notes |
| 140 | + --prerelease |
| 141 | + - name: Upload artifact signatures to GitHub Release |
| 142 | + env: |
| 143 | + GITHUB_TOKEN: ${{ github.token }} |
| 144 | + # Upload to GitHub Release using the `gh` CLI. |
| 145 | + # `dist/` contains the built packages, and the |
| 146 | + # sigstore-produced signatures and certificates. |
| 147 | + run: >- |
| 148 | + gh release upload |
| 149 | + '${{ github.ref_name }}' dist/** |
| 150 | + --repo '${{ github.repository }}' |
0 commit comments