|
1 | | -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions |
2 | | -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions |
| 1 | +# This workflow runs whenever a new tag is pushed. |
| 2 | +# It will install Python dependencies, run tests and lint with a variety of Python versions |
| 3 | +# If tests pass, it will build the package and publish it on pypi.org |
3 | 4 |
|
4 | 5 | name: Python package |
5 | 6 |
|
6 | 7 | on: |
7 | 8 | push: |
8 | | - branches: [ '*' ] |
9 | | - pull_request: |
10 | | - branches: [ $default-branch ] |
| 9 | + tags: |
| 10 | + - 'v*' |
11 | 11 |
|
12 | 12 | jobs: |
13 | | - build: |
14 | | - |
| 13 | + test: |
15 | 14 | runs-on: ubuntu-latest |
16 | 15 | strategy: |
17 | 16 | fail-fast: false |
18 | 17 | matrix: |
19 | 18 | python-version: ["3.10", "3.11", "3.12", "3.13"] |
20 | 19 |
|
21 | 20 | steps: |
22 | | - - uses: actions/checkout@v2 |
| 21 | + - uses: actions/checkout@v5 |
23 | 22 | - name: Set up Python ${{ matrix.python-version }} |
24 | | - uses: actions/setup-python@v2 |
| 23 | + uses: actions/setup-python@v5 |
25 | 24 | with: |
26 | 25 | python-version: ${{ matrix.python-version }} |
27 | 26 | - name: Install dependencies |
|
30 | 29 | python -m pip install tox |
31 | 30 | - name: tox |
32 | 31 | run: tox |
| 32 | + |
| 33 | + build: |
| 34 | + name: Build package for PyPI |
| 35 | + runs-on: ubuntu-latest |
| 36 | + needs: test |
| 37 | + steps: |
| 38 | + - uses: actions/checkout@v5 |
| 39 | + - name: Set up Python ${{ matrix.python-version }} |
| 40 | + uses: actions/setup-python@v5 |
| 41 | + with: |
| 42 | + python-version: '3.11' |
| 43 | + - name: Build release |
| 44 | + run: | |
| 45 | + python -m pip install --upgrade build |
| 46 | + python -m build |
| 47 | + - name: Upload dist |
| 48 | + uses: actions/upload-artifact@v4 |
| 49 | + with: |
| 50 | + name: release-dists |
| 51 | + path: dist/ |
| 52 | + |
| 53 | + publish: |
| 54 | + name: Publish package to PyPI |
| 55 | + runs-on: ubuntu-latest |
| 56 | + needs: build |
| 57 | + steps: |
| 58 | + - name: Retrieve dist |
| 59 | + uses: actions/download-artifact@v5 |
| 60 | + with: |
| 61 | + name: release-dists |
| 62 | + path: dist/ |
| 63 | + - name: Push to pypi |
| 64 | + # if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') |
| 65 | + uses: pypa/gh-action-pypi-publish@release/v1.13 |
| 66 | + with: |
| 67 | + user: __token__ |
| 68 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 69 | + verbose: true |
| 70 | + |
0 commit comments