|
| 1 | +name: Publish to PyPI |
| 2 | +on: |
| 3 | + release: |
| 4 | + types: [published] |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | +jobs: |
| 9 | + # setup build separate from publish |
| 10 | + # See https://github.com/pypa/gh-action-pypi-publish/issues/217#issuecomment-1965727093 |
| 11 | + build: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + # This ensures that the publish action only runs in the main repository |
| 14 | + # rather than forks |
| 15 | + # Environment is encouraged so adding |
| 16 | + environment: build |
| 17 | + steps: |
| 18 | + - name: Checkout |
| 19 | + uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + # This fetch element is only important if you are use SCM based |
| 22 | + # versioning (that looks at git tags to gather the version) |
| 23 | + fetch-depth: 100 |
| 24 | + |
| 25 | + # Need the tags so that setuptools-scm can form a valid version number |
| 26 | + - name: Fetch git tags |
| 27 | + run: git fetch origin 'refs/tags/*:refs/tags/*' |
| 28 | + |
| 29 | + - name: Setup Python |
| 30 | + uses: actions/setup-python@v5 |
| 31 | + with: |
| 32 | + python-version: "3.10" |
| 33 | + - name: Install Hatch |
| 34 | + run: | |
| 35 | + pipx install hatch |
| 36 | + pip list |
| 37 | +
|
| 38 | + - name: Build package using Hatch |
| 39 | + run: | |
| 40 | + hatch build |
| 41 | + echo "" |
| 42 | + echo "Generated files:" |
| 43 | + ls -lh dist/ |
| 44 | + # Store an artifact of the build to use in the publish step below |
| 45 | + - name: Store the distribution packages |
| 46 | + uses: actions/upload-artifact@v4 |
| 47 | + with: |
| 48 | + name: python-package-distributions |
| 49 | + path: dist/ |
| 50 | + publish: |
| 51 | + name: >- |
| 52 | + Publish Python 🐍 distribution 📦 to PyPI |
| 53 | + if: github.repository_owner == 'pyopensci' |
| 54 | + needs: |
| 55 | + - build |
| 56 | + runs-on: ubuntu-latest |
| 57 | + environment: |
| 58 | + name: pypi |
| 59 | + url: https://pypi.org/p/pyos-sphinx-theme |
| 60 | + permissions: |
| 61 | + id-token: write # this permission is mandatory for pypi publishing |
| 62 | + steps: |
| 63 | + # Version 4 doesn't support github enterprise yet |
| 64 | + - name: Download all the dists |
| 65 | + uses: actions/download-artifact@v4 |
| 66 | + with: |
| 67 | + name: python-package-distributions |
| 68 | + path: dist/ |
| 69 | + - name: Publish package to PyPI |
| 70 | + # Only publish to real PyPI on release |
| 71 | + if: github.event_name == 'release' |
| 72 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 73 | + sign-files: |
| 74 | + name: >- |
| 75 | + Sign the Python 🐍 distribution 📦 with Sigstore |
| 76 | + and upload them to GitHub Release |
| 77 | + # Only sign on release |
| 78 | + if: github.repository_owner == 'pyopensci' && github.event_name == 'release' |
| 79 | + needs: |
| 80 | + - publish |
| 81 | + runs-on: ubuntu-latest |
| 82 | + permissions: |
| 83 | + contents: write # this permission is mandatory for modifying GitHub Releases |
| 84 | + id-token: write # this permission is mandatory for sigstore |
| 85 | + steps: |
| 86 | + - name: Download all the dists |
| 87 | + uses: actions/download-artifact@v4 |
| 88 | + with: |
| 89 | + name: python-package-distributions |
| 90 | + path: dist/ |
| 91 | + - name: Sign the dists with Sigstore |
| 92 | + |
| 93 | + with: |
| 94 | + inputs: >- |
| 95 | + ./dist/*.tar.gz |
| 96 | + ./dist/*.whl |
| 97 | + - name: Upload artifact signatures to GitHub Release |
| 98 | + env: |
| 99 | + GITHUB_TOKEN: ${{ github.token }} |
| 100 | + # Upload to GitHub Release using the `gh` CLI. |
| 101 | + # `dist/` contains the built packages, and the |
| 102 | + # sigstore-produced signatures and certificates. |
| 103 | + run: >- |
| 104 | + gh release upload |
| 105 | + '${{ github.ref_name }}' dist/** |
| 106 | + --repo '${{ github.repository }}' |
0 commit comments