|
| 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 on any forks of your repo. You only should publish from the |
| 15 | + # main repository |
| 16 | + # Environment is encouraged but not required. The build step of this action |
| 17 | + # Only builds your package's sdist and wheel |
| 18 | + environment: build |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + # This fetch element is only important if you are use SCM based |
| 24 | + # versioning (that looks at git tags to gather the version) |
| 25 | + fetch-depth: 100 |
| 26 | + |
| 27 | + # Need the tags so that setuptools-scm can form a valid version number |
| 28 | + - name: Fetch git tags |
| 29 | + run: git fetch origin 'refs/tags/*:refs/tags/*' |
| 30 | + |
| 31 | + - name: Setup Python |
| 32 | + uses: actions/setup-python@v5 |
| 33 | + with: |
| 34 | + python-version: "3.10" |
| 35 | + - name: Install Hatch |
| 36 | + run: | |
| 37 | + pipx install hatch |
| 38 | + pip list |
| 39 | +
|
| 40 | + - name: Build package using Hatch |
| 41 | + run: | |
| 42 | + hatch build |
| 43 | + echo "" |
| 44 | + echo "Generated files:" |
| 45 | + ls -lh dist/ |
| 46 | + # Store an artifact of the build to use in the publish step below |
| 47 | + - name: Store the distribution packages |
| 48 | + uses: actions/upload-artifact@v4 |
| 49 | + with: |
| 50 | + name: python-package-distributions |
| 51 | + path: dist/ |
| 52 | + publish: |
| 53 | + name: >- |
| 54 | + Publish Python 🐍 distribution 📦 to PyPI |
| 55 | + if: github.repository_owner == 'pyopensci' |
| 56 | + needs: |
| 57 | + - build |
| 58 | + runs-on: ubuntu-latest |
| 59 | + # This is the trusted environment. Notice that it's called pypi |
| 60 | + # that is the name that you will use in your pypi configuration |
| 61 | + environment: |
| 62 | + name: pypi |
| 63 | + url: https://pypi.org/p/pyospackage |
| 64 | + permissions: |
| 65 | + id-token: write # this permission is mandatory for pypi publishing |
| 66 | + steps: |
| 67 | + # Version 4 doesn't support GitHub enterprise yet |
| 68 | + - name: Download all the dists |
| 69 | + uses: actions/download-artifact@v4 |
| 70 | + with: |
| 71 | + name: python-package-distributions |
| 72 | + path: dist/ |
| 73 | + - name: Publish package to PyPI |
| 74 | + # Only publish to real PyPI on release |
| 75 | + if: github.event_name == 'release' |
| 76 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments