|
| 1 | +name: Publish to PyPI |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + test-pypi: |
| 9 | + description: 'Publish to Test PyPI instead of PyPI' |
| 10 | + required: false |
| 11 | + type: boolean |
| 12 | + default: false |
| 13 | + |
| 14 | +jobs: |
| 15 | + build: |
| 16 | + name: Build distribution |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Set up Python |
| 22 | + uses: actions/setup-python@v5 |
| 23 | + with: |
| 24 | + python-version: "3.12" |
| 25 | + |
| 26 | + - name: Install uv |
| 27 | + uses: astral-sh/setup-uv@v4 |
| 28 | + |
| 29 | + - name: Build package |
| 30 | + run: uv build |
| 31 | + |
| 32 | + - name: Store the distribution packages |
| 33 | + uses: actions/upload-artifact@v4 |
| 34 | + with: |
| 35 | + name: python-package-distributions |
| 36 | + path: dist/ |
| 37 | + |
| 38 | + publish-to-pypi: |
| 39 | + name: Publish to PyPI |
| 40 | + if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && !inputs.test-pypi) |
| 41 | + needs: |
| 42 | + - build |
| 43 | + runs-on: ubuntu-latest |
| 44 | + environment: |
| 45 | + name: pypi |
| 46 | + url: https://pypi.org/p/forminit |
| 47 | + permissions: |
| 48 | + id-token: write |
| 49 | + steps: |
| 50 | + - name: Download all the dists |
| 51 | + uses: actions/download-artifact@v4 |
| 52 | + with: |
| 53 | + name: python-package-distributions |
| 54 | + path: dist/ |
| 55 | + |
| 56 | + - name: Publish to PyPI (Trusted Publishing with Token Fallback) |
| 57 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 58 | + with: |
| 59 | + password: ${{ secrets.PYPI_API_TOKEN || '' }} |
| 60 | + skip-existing: true |
| 61 | + |
| 62 | + publish-to-testpypi: |
| 63 | + name: Publish to TestPyPI |
| 64 | + if: github.event_name == 'workflow_dispatch' && inputs.test-pypi |
| 65 | + needs: |
| 66 | + - build |
| 67 | + runs-on: ubuntu-latest |
| 68 | + environment: |
| 69 | + name: testpypi |
| 70 | + url: https://test.pypi.org/p/forminit |
| 71 | + permissions: |
| 72 | + id-token: write |
| 73 | + steps: |
| 74 | + - name: Download all the dists |
| 75 | + uses: actions/download-artifact@v4 |
| 76 | + with: |
| 77 | + name: python-package-distributions |
| 78 | + path: dist/ |
| 79 | + |
| 80 | + - name: Publish to TestPyPI (Trusted Publishing with Token Fallback) |
| 81 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 82 | + with: |
| 83 | + repository-url: https://test.pypi.org/legacy/ |
| 84 | + password: ${{ secrets.TEST_PYPI_API_TOKEN || '' }} |
| 85 | + skip-existing: true |
0 commit comments