|
| 1 | +# This workflow will upload a Python Package using Twine when a release is created |
| 2 | +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries |
| 3 | + |
| 4 | +# This workflow uses actions that are not certified by GitHub. |
| 5 | +# They are provided by a third-party and are governed by |
| 6 | +# separate terms of service, privacy policy, and support |
| 7 | +# documentation. |
| 8 | + |
| 9 | +name: Publish This Package to PyPI |
| 10 | + |
| 11 | +on: |
| 12 | + push |
| 13 | + |
| 14 | +jobs: |
| 15 | + build: |
| 16 | + name: Build distribution |
| 17 | + runs-on: ubuntu-latest |
| 18 | + |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + persist-credentials: false |
| 23 | + - name: Set up Python |
| 24 | + uses: actions/setup-python@v5 |
| 25 | + with: |
| 26 | + python-version: "3.x" |
| 27 | + - name: Install pypa/build |
| 28 | + run: >- |
| 29 | + python3 -m |
| 30 | + pip install |
| 31 | + build |
| 32 | + --user |
| 33 | + - name: Build a binary wheel and a source tarball |
| 34 | + run: python3 -m build |
| 35 | + - name: Store the distribution packages |
| 36 | + uses: actions/upload-artifact@v4 |
| 37 | + with: |
| 38 | + name: python-package-distributions |
| 39 | + path: dist/ |
| 40 | + |
| 41 | + publish-to-pypi: |
| 42 | + name: >- |
| 43 | + Publish Python distribution to PyPI |
| 44 | + if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes |
| 45 | + needs: |
| 46 | + - build |
| 47 | + runs-on: ubuntu-latest |
| 48 | + environment: |
| 49 | + name: pypi |
| 50 | + url: https://pypi.org/p/sphinx-github-alerts |
| 51 | + permissions: |
| 52 | + id-token: write # IMPORTANT: mandatory for trusted publishing |
| 53 | + |
| 54 | + steps: |
| 55 | + - name: Download all the dists |
| 56 | + uses: actions/download-artifact@v4 |
| 57 | + with: |
| 58 | + name: python-package-distributions |
| 59 | + path: dist/ |
| 60 | + - name: Publish distribution to PyPI |
| 61 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 62 | + |
| 63 | + github-release: |
| 64 | + name: >- |
| 65 | + Sign the Python distribution with Sigstore |
| 66 | + and upload them to GitHub Release |
| 67 | + needs: |
| 68 | + - publish-to-pypi |
| 69 | + runs-on: ubuntu-latest |
| 70 | + |
| 71 | + permissions: |
| 72 | + contents: write # IMPORTANT: mandatory for making GitHub Releases |
| 73 | + id-token: write # IMPORTANT: mandatory for sigstore |
| 74 | + |
| 75 | + steps: |
| 76 | + - name: Download all the dists |
| 77 | + uses: actions/download-artifact@v4 |
| 78 | + with: |
| 79 | + name: python-package-distributions |
| 80 | + path: dist/ |
| 81 | + - name: Sign the dists with Sigstore |
| 82 | + |
| 83 | + with: |
| 84 | + inputs: >- |
| 85 | + ./dist/*.tar.gz |
| 86 | + ./dist/*.whl |
| 87 | +
|
| 88 | + - name: Determine Release Tag |
| 89 | + id: release_tag |
| 90 | + run: echo "GITHUB_REF_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV |
| 91 | + |
| 92 | + - name: Check if release exists |
| 93 | + id: check_release |
| 94 | + env: |
| 95 | + GITHUB_TOKEN: ${{ github.token }} |
| 96 | + run: | |
| 97 | + if gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY"; then |
| 98 | + echo "RELEASE_EXISTS=true" >> $GITHUB_ENV |
| 99 | + else |
| 100 | + echo "RELEASE_EXISTS=false" >> $GITHUB_ENV |
| 101 | + fi |
| 102 | +
|
| 103 | + - name: Create GitHub Release (if not exists) |
| 104 | + if: env.RELEASE_EXISTS == 'false' |
| 105 | + env: |
| 106 | + GITHUB_TOKEN: ${{ github.token }} |
| 107 | + run: >- |
| 108 | + gh release create |
| 109 | + "$GITHUB_REF_NAME" |
| 110 | + --repo "$GITHUB_REPOSITORY" |
| 111 | + --notes "Release $GITHUB_REF_NAME" |
| 112 | +
|
| 113 | + - name: Mark as Latest Release (if created) |
| 114 | + if: env.RELEASE_EXISTS == 'false' |
| 115 | + env: |
| 116 | + GITHUB_TOKEN: ${{ github.token }} |
| 117 | + run: >- |
| 118 | + gh release edit |
| 119 | + "$GITHUB_REF_NAME" |
| 120 | + --repo "$GITHUB_REPOSITORY" |
| 121 | + --latest |
| 122 | +
|
| 123 | + - name: Upload artifact signatures to GitHub Release |
| 124 | + env: |
| 125 | + GITHUB_TOKEN: ${{ github.token }} |
| 126 | + # Upload to GitHub Release using the `gh` CLI. |
| 127 | + # `dist/` contains the built packages, and the |
| 128 | + # sigstore-produced signatures and certificates. |
| 129 | + run: >- |
| 130 | + gh release upload |
| 131 | + "$GITHUB_REF_NAME" dist/** |
| 132 | + --repo "$GITHUB_REPOSITORY" |
0 commit comments