|
| 1 | +--- |
1 | 2 | name: Release to PyPI |
2 | 3 |
|
| 4 | +# yamllint disable-line rule:truthy |
3 | 5 | on: |
4 | | - workflow_dispatch: |
| 6 | + release: |
| 7 | + types: |
| 8 | + - published |
| 9 | + - edited |
5 | 10 |
|
6 | 11 | permissions: |
7 | | - contents: write |
8 | | - id-token: write |
| 12 | + contents: read |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: release |
| 16 | + cancel-in-progress: false |
9 | 17 |
|
10 | 18 | jobs: |
11 | | - release: |
| 19 | + build: |
| 20 | + name: Build distribution |
12 | 21 | runs-on: ubuntu-latest |
| 22 | + permissions: |
| 23 | + contents: read |
13 | 24 | steps: |
14 | 25 | - name: Checkout code |
15 | 26 | uses: actions/checkout@v6 |
| 27 | + with: |
| 28 | + persist-credentials: false |
16 | 29 |
|
17 | 30 | - name: Set up Python 3.11 |
18 | 31 | uses: actions/setup-python@v6 |
19 | 32 | with: |
20 | 33 | python-version: '3.11' |
| 34 | + cache: 'pip' |
| 35 | + |
| 36 | + - name: Upgrade pip |
| 37 | + run: python -m pip install --upgrade pip |
21 | 38 |
|
22 | 39 | - name: Install build dependencies |
23 | | - run: pip install build |
| 40 | + run: python -m pip install build twine |
24 | 41 |
|
25 | 42 | - name: Build package |
26 | 43 | run: python -m build |
27 | 44 |
|
28 | | - - name: Release to PyPI |
| 45 | + - name: Check package |
| 46 | + run: twine check dist/* |
| 47 | + |
| 48 | + - name: Store the distribution packages |
| 49 | + uses: actions/upload-artifact@v4 |
| 50 | + with: |
| 51 | + name: python-package-distributions |
| 52 | + path: dist/ |
| 53 | + |
| 54 | + publish-testpypi: |
| 55 | + name: Publish to TestPyPI |
| 56 | + needs: build |
| 57 | + if: github.event.release.prerelease |
| 58 | + runs-on: ubuntu-latest |
| 59 | + permissions: |
| 60 | + contents: read |
| 61 | + id-token: write |
| 62 | + environment: |
| 63 | + name: testpypi |
| 64 | + url: https://test.pypi.org/project/timerun/ |
| 65 | + steps: |
| 66 | + - name: Download distribution packages |
| 67 | + uses: actions/download-artifact@v4 |
| 68 | + with: |
| 69 | + name: python-package-distributions |
| 70 | + path: dist/ |
| 71 | + |
| 72 | + - name: Publish to TestPyPI |
29 | 73 | uses: pypa/gh-action-pypi-publish@release/v1 |
| 74 | + with: |
| 75 | + repository-url: https://test.pypi.org/legacy/ |
30 | 76 |
|
31 | | - - name: Create tag |
32 | | - run: | |
33 | | - VERSION=$(python -c "import timerun; print(timerun.__version__)") |
34 | | - git tag "v$VERSION" |
35 | | - git push origin "v$VERSION" |
| 77 | + publish-pypi: |
| 78 | + name: Publish to PyPI |
| 79 | + needs: build |
| 80 | + if: ${{ !github.event.release.prerelease }} |
| 81 | + runs-on: ubuntu-latest |
| 82 | + permissions: |
| 83 | + contents: read |
| 84 | + id-token: write |
| 85 | + environment: |
| 86 | + name: pypi |
| 87 | + url: https://pypi.org/project/timerun/ |
| 88 | + steps: |
| 89 | + - name: Download distribution packages |
| 90 | + uses: actions/download-artifact@v4 |
| 91 | + with: |
| 92 | + name: python-package-distributions |
| 93 | + path: dist/ |
| 94 | + |
| 95 | + - name: Publish to PyPI |
| 96 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments