|
| 1 | +name: Publish to PyPI |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | +jobs: |
| 8 | + prerequisites: |
| 9 | + uses: ./.github/workflows/test.yml |
| 10 | + # Setup build separate from publish for added security |
| 11 | + # See https://github.com/pypa/gh-action-pypi-publish/issues/217#issuecomment-1965727093 |
| 12 | + build: |
| 13 | + needs: [prerequisites] |
| 14 | + runs-on: ubuntu-latest |
| 15 | + # Environment is encouraged for increased security |
| 16 | + steps: |
| 17 | + - name: Checkout |
| 18 | + uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + # This fetch element is only important if you are use SCM based |
| 21 | + # versioning (that looks at git tags to gather the version). |
| 22 | + # setuptools-scm needs tags to form a valid version number |
| 23 | + fetch-tags: true |
| 24 | + |
| 25 | + - name: Setup Python |
| 26 | + uses: actions/setup-python@v5 |
| 27 | + with: |
| 28 | + # You can modify what version of Python you want to use for your release |
| 29 | + python-version: "3.11" |
| 30 | + |
| 31 | + # Whenever possible, pin your project development dependencies to a specific version |
| 32 | + - name: Install Hatch |
| 33 | + run: | |
| 34 | + pip install hatch==1.15.1 |
| 35 | +
|
| 36 | + - name: Build package using Hatch |
| 37 | + run: | |
| 38 | + hatch build |
| 39 | + echo "" |
| 40 | + echo "Generated files:" |
| 41 | + ls -lh dist/ |
| 42 | +
|
| 43 | + # Store an artifact of the build to use in the publish step below |
| 44 | + - name: Store the distribution packages |
| 45 | + uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 #v5.0.0 |
| 46 | + with: |
| 47 | + name: python-package-distributions |
| 48 | + path: dist/ |
| 49 | + if-no-files-found: error |
| 50 | + publish: |
| 51 | + name: >- |
| 52 | + Publish Python 🐍 distribution 📦 to PyPI |
| 53 | + # Modify the repo name below to be your project's repo name. |
| 54 | + if: github.repository_owner == "pyopensci" |
| 55 | + needs: |
| 56 | + - build |
| 57 | + runs-on: ubuntu-latest |
| 58 | + # Environment required here for trusted publisher |
| 59 | + # You can set permissions for this environment so it can only be used by |
| 60 | + # certain people |
| 61 | + environment: |
| 62 | + name: pypi |
| 63 | + # Modify the url to be the name of your package |
| 64 | + url: https://pypi.org/p/pyospackage |
| 65 | + permissions: |
| 66 | + id-token: write # this permission is mandatory for PyPI publishing |
| 67 | + steps: |
| 68 | + - name: Download dists |
| 69 | + uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 #v6.0.0 |
| 70 | + with: |
| 71 | + name: python-package-distributions |
| 72 | + path: dist/ |
| 73 | + merge-multiple: true |
| 74 | + - name: Publish package to PyPI |
| 75 | + # Only publish to real PyPI on release |
| 76 | + if: github.event_name == 'release' && github.event.action == 'published' |
| 77 | + uses: pypa/gh-action-pypi-publish@release/ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0 |
0 commit comments