|
| 1 | +name: Publish to PyPI |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + # Allow manual trigger for testing |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + test_pypi: |
| 10 | + description: 'Publish to TestPyPI instead of PyPI' |
| 11 | + required: false |
| 12 | + default: 'false' |
| 13 | + type: boolean |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + name: Build distribution |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Set up Python |
| 24 | + uses: actions/setup-python@v5 |
| 25 | + with: |
| 26 | + python-version: '3.12' |
| 27 | + |
| 28 | + - name: Install build dependencies |
| 29 | + run: | |
| 30 | + python -m pip install --upgrade pip |
| 31 | + pip install build twine |
| 32 | +
|
| 33 | + - name: Build package |
| 34 | + run: python -m build |
| 35 | + |
| 36 | + - name: Check package |
| 37 | + run: | |
| 38 | + twine check dist/* |
| 39 | + echo "=== Built packages ===" |
| 40 | + ls -la dist/ |
| 41 | +
|
| 42 | + - name: Upload artifacts |
| 43 | + uses: actions/upload-artifact@v4 |
| 44 | + with: |
| 45 | + name: python-package-distributions |
| 46 | + path: dist/ |
| 47 | + |
| 48 | + publish-testpypi: |
| 49 | + name: Publish to TestPyPI |
| 50 | + needs: build |
| 51 | + runs-on: ubuntu-latest |
| 52 | + if: github.event_name == 'workflow_dispatch' && github.event.inputs.test_pypi == 'true' |
| 53 | + |
| 54 | + environment: |
| 55 | + name: testpypi |
| 56 | + url: https://test.pypi.org/p/behaverify |
| 57 | + |
| 58 | + permissions: |
| 59 | + id-token: write # Required for trusted publishing |
| 60 | + |
| 61 | + steps: |
| 62 | + - name: Download artifacts |
| 63 | + uses: actions/download-artifact@v4 |
| 64 | + with: |
| 65 | + name: python-package-distributions |
| 66 | + path: dist/ |
| 67 | + |
| 68 | + - name: Publish to TestPyPI |
| 69 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 70 | + with: |
| 71 | + repository-url: https://test.pypi.org/legacy/ |
| 72 | + |
| 73 | + publish-pypi: |
| 74 | + name: Publish to PyPI |
| 75 | + needs: build |
| 76 | + runs-on: ubuntu-latest |
| 77 | + if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.test_pypi == 'false') |
| 78 | + |
| 79 | + environment: |
| 80 | + name: pypi |
| 81 | + url: https://pypi.org/p/behaverify |
| 82 | + |
| 83 | + permissions: |
| 84 | + id-token: write # Required for trusted publishing |
| 85 | + |
| 86 | + steps: |
| 87 | + - name: Download artifacts |
| 88 | + uses: actions/download-artifact@v4 |
| 89 | + with: |
| 90 | + name: python-package-distributions |
| 91 | + path: dist/ |
| 92 | + |
| 93 | + - name: Publish to PyPI |
| 94 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments