|
| 1 | +name: Publish to PyPI and TestPyPI |
| 2 | + |
| 3 | +on: push |
| 4 | + |
| 5 | +jobs: |
| 6 | + build: |
| 7 | + name: Build distribution |
| 8 | + runs-on: ubuntu-latest |
| 9 | + |
| 10 | + steps: |
| 11 | + - uses: actions/checkout@v4 |
| 12 | + - name: Set up Python |
| 13 | + uses: actions/setup-python@v5 |
| 14 | + with: |
| 15 | + python-version: "3.9" |
| 16 | + - name: Install pypa/build |
| 17 | + run: >- |
| 18 | + python3 -m |
| 19 | + pip install |
| 20 | + build |
| 21 | + --user |
| 22 | + - name: Build a binary wheel and a source tarball |
| 23 | + run: python3 -m build |
| 24 | + - name: Store the distribution packages |
| 25 | + uses: actions/upload-artifact@v3 |
| 26 | + with: |
| 27 | + name: python-package-distributions |
| 28 | + path: dist/ |
| 29 | + |
| 30 | + publish-to-pypi: |
| 31 | + name: Publish Python distribution on PyPI |
| 32 | + # Publish to PyPI when pushing a tag |
| 33 | + if: startsWith(github.ref, 'refs/tags/') |
| 34 | + needs: |
| 35 | + - build |
| 36 | + runs-on: ubuntu-latest |
| 37 | + environment: |
| 38 | + name: pypi |
| 39 | + url: https://pypi.org/p/ckan |
| 40 | + permissions: |
| 41 | + id-token: write |
| 42 | + steps: |
| 43 | + - name: Download all the dists |
| 44 | + uses: actions/download-artifact@v3 |
| 45 | + with: |
| 46 | + name: python-package-distributions |
| 47 | + path: dist/ |
| 48 | + - name: Publish distribution to PyPI |
| 49 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 50 | + |
| 51 | + publish-to-testpypi: |
| 52 | + name: Publish Python distribution on TestPyPI |
| 53 | + # Publish to Test PyPI when a pull request is merged |
| 54 | + if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true |
| 55 | + needs: |
| 56 | + - build |
| 57 | + runs-on: ubuntu-latest |
| 58 | + environment: |
| 59 | + name: pypi |
| 60 | + url: https://test.pypi.org/p/ckan |
| 61 | + permissions: |
| 62 | + id-token: write |
| 63 | + steps: |
| 64 | + - name: Download all the dists |
| 65 | + uses: actions/download-artifact@v3 |
| 66 | + with: |
| 67 | + name: python-package-distributions |
| 68 | + path: dist/ |
| 69 | + - name: Publish distribution to PyPI |
| 70 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 71 | + with: |
| 72 | + repository-url: https://test.pypi.org/legacy/ |
0 commit comments