|
| 1 | +# This workflow is adapted from: |
| 2 | +# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ |
| 3 | + |
| 4 | +name: release |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + tags: |
| 10 | + - 'v*' |
| 11 | + |
| 12 | +env: |
| 13 | + # This is not critical |
| 14 | + # It is used only for showing URLs in GitHub Actions web interface. |
| 15 | + PYPI_NAME: soapboxslide |
| 16 | + TITLE: Soap Box Slide |
| 17 | + |
| 18 | +jobs: |
| 19 | + build: |
| 20 | + name: Build distribution |
| 21 | + runs-on: ubuntu-latest |
| 22 | + |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + - name: Set up Python |
| 28 | + uses: actions/setup-python@v5 |
| 29 | + with: |
| 30 | + python-version: '3.11' |
| 31 | + - name: Install pypa/build |
| 32 | + run: >- |
| 33 | + python -m pip install build |
| 34 | + - name: Build package |
| 35 | + run: >- |
| 36 | + python -m build |
| 37 | + - name: Store the distribution packages |
| 38 | + uses: actions/upload-artifact@v4 |
| 39 | + with: |
| 40 | + name: python-package-distributions |
| 41 | + path: dist/ |
| 42 | + - name: Run release notes script |
| 43 | + run: >- |
| 44 | + .github/scripts/extract-notes.sh |
| 45 | + '${{ github.repository }}' |
| 46 | + '${{ github.ref }}' |
| 47 | + - name: Store the release notes |
| 48 | + uses: actions/upload-artifact@v4 |
| 49 | + with: |
| 50 | + name: release-notes |
| 51 | + path: notes.md |
| 52 | + |
| 53 | + publish-to-pypi: |
| 54 | + name: Publish Python distribution to PyPI |
| 55 | + if: startsWith(github.ref, 'refs/tags/v') # only publish to PyPI on tag pushes |
| 56 | + needs: |
| 57 | + - build |
| 58 | + runs-on: ubuntu-latest |
| 59 | + environment: |
| 60 | + name: pypi |
| 61 | + url: https://pypi.org/p/${{ env.PYPI_NAME }} |
| 62 | + permissions: |
| 63 | + id-token: write |
| 64 | + |
| 65 | + steps: |
| 66 | + - name: Download all the dists |
| 67 | + uses: actions/download-artifact@v4 |
| 68 | + with: |
| 69 | + name: python-package-distributions |
| 70 | + path: dist/ |
| 71 | + - name: Publish distribution to PyPI |
| 72 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 73 | + |
| 74 | + github-release: |
| 75 | + name: >- |
| 76 | + Sign the Python distribution with Sigstore |
| 77 | + and upload them to GitHub Release |
| 78 | + needs: |
| 79 | + - publish-to-pypi |
| 80 | + runs-on: ubuntu-latest |
| 81 | + |
| 82 | + permissions: |
| 83 | + contents: write |
| 84 | + id-token: write |
| 85 | + |
| 86 | + steps: |
| 87 | + - name: Download all the dists |
| 88 | + uses: actions/download-artifact@v4 |
| 89 | + with: |
| 90 | + name: python-package-distributions |
| 91 | + path: dist/ |
| 92 | + - name: Download the release notes |
| 93 | + uses: actions/download-artifact@v4 |
| 94 | + with: |
| 95 | + name: release-notes |
| 96 | + - name: Sign the dists with Sigstore |
| 97 | + uses: sigstore/gh-action-sigstore-python@v3.0.0 |
| 98 | + with: |
| 99 | + inputs: >- |
| 100 | + ./dist/*.tar.gz |
| 101 | + ./dist/*.whl |
| 102 | + - name: Create GitHub Release |
| 103 | + env: |
| 104 | + GITHUB_TOKEN: ${{ github.token }} |
| 105 | + run: >- |
| 106 | + gh release create '${{ github.ref_name }}' |
| 107 | + --repo '${{ github.repository }}' |
| 108 | + --title '${{ env.TITLE }} ${{ github.ref_name }}' |
| 109 | + --notes-file notes.md |
| 110 | + - name: Upload artifact signatures to GitHub Release |
| 111 | + env: |
| 112 | + GITHUB_TOKEN: ${{ github.token }} |
| 113 | + # Upload to GitHub Release using the `gh` CLI. |
| 114 | + # `dist/` contains the built packages, and the |
| 115 | + # sigstore-produced signatures and certificates. |
| 116 | + run: >- |
| 117 | + gh release upload |
| 118 | + '${{ github.ref_name }}' |
| 119 | + dist/** |
| 120 | + --repo '${{ github.repository }}' |
| 121 | +
|
| 122 | + publish-to-testpypi: |
| 123 | + name: Publish Python distribution to TestPyPI |
| 124 | + if: ${{ github.ref == 'refs/heads/main' && github.repository_owner == 'reproducible-reporting'}} |
| 125 | + needs: |
| 126 | + - build |
| 127 | + runs-on: ubuntu-latest |
| 128 | + |
| 129 | + environment: |
| 130 | + name: testpypi |
| 131 | + url: https://test.pypi.org/p/${{ env.PYPI_NAME }} |
| 132 | + |
| 133 | + permissions: |
| 134 | + id-token: write |
| 135 | + |
| 136 | + steps: |
| 137 | + - name: Download all the dists |
| 138 | + uses: actions/download-artifact@v4 |
| 139 | + with: |
| 140 | + name: python-package-distributions |
| 141 | + path: dist/ |
| 142 | + - name: Publish distribution to TestPyPI |
| 143 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 144 | + with: |
| 145 | + repository-url: https://test.pypi.org/legacy/ |
0 commit comments