|
| 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 |
| 3 | + |
| 4 | +name: Python package |
| 5 | + |
| 6 | +on: |
| 7 | + pull_request: |
| 8 | + push: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + tags: |
| 12 | + - "v*" |
| 13 | + |
| 14 | +jobs: |
| 15 | + test: |
| 16 | + runs-on: ${{ matrix.os }} |
| 17 | + strategy: |
| 18 | + fail-fast: false |
| 19 | + matrix: |
| 20 | + os: [ubuntu-latest] #, windows-latest, macos-latest] |
| 21 | + python-version: |
| 22 | + - "3.9" |
| 23 | + - "3.10" |
| 24 | + - "3.11" |
| 25 | + - "3.12" |
| 26 | + - "3.13" |
| 27 | + - "pypy-3.9" |
| 28 | + |
| 29 | + name: ${{ matrix.os }} - ${{ matrix.python-version }} |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@v4 |
| 32 | + - name: Get history and tags for SCM versioning to work |
| 33 | + run: | |
| 34 | + git fetch --prune --unshallow |
| 35 | + git fetch --depth=1 origin +refs/tags/*:refs/tags/* |
| 36 | + - name: Install uv |
| 37 | + uses: astral-sh/setup-uv@v5 |
| 38 | + with: |
| 39 | + version: "0.5.22" |
| 40 | + - name: Set up Python ${{ matrix.python-version }} |
| 41 | + uses: actions/setup-python@v5 |
| 42 | + with: |
| 43 | + python-version: ${{ matrix.python-version }} |
| 44 | + - name: Install dependencies |
| 45 | + run: pip install tox tox-uv |
| 46 | + - name: Run tox |
| 47 | + # Run tox using the version of Python in `PATH` |
| 48 | + run: tox -e py |
| 49 | + |
| 50 | + dist: |
| 51 | + runs-on: ubuntu-latest |
| 52 | + needs: [test] |
| 53 | + name: Build Python packages |
| 54 | + steps: |
| 55 | + - uses: actions/checkout@v4 |
| 56 | + - name: Get history and tags for SCM versioning to work |
| 57 | + run: | |
| 58 | + git fetch --prune --unshallow |
| 59 | + git fetch --depth=1 origin +refs/tags/*:refs/tags/* |
| 60 | + - uses: actions/setup-python@v5 |
| 61 | + with: |
| 62 | + python-version: "3.9" |
| 63 | + - name: Install dependencies |
| 64 | + run: | |
| 65 | + python -m pip install --upgrade pip |
| 66 | + pip install --upgrade wheel setuptools build |
| 67 | + - name: Build package |
| 68 | + run: python -m build -s -w -o dist/ |
| 69 | + - uses: actions/upload-artifact@v4 |
| 70 | + with: |
| 71 | + name: dist |
| 72 | + path: dist |
| 73 | + |
| 74 | + dist_check: |
| 75 | + runs-on: ubuntu-latest |
| 76 | + needs: [dist] |
| 77 | + name: Twine check |
| 78 | + steps: |
| 79 | + - uses: actions/setup-python@v5 |
| 80 | + with: |
| 81 | + python-version: "3.9" |
| 82 | + - name: Install dependencies |
| 83 | + run: pip install twine |
| 84 | + - uses: actions/download-artifact@v4 |
| 85 | + with: |
| 86 | + name: dist |
| 87 | + path: dist |
| 88 | + - run: twine check dist/* |
| 89 | + |
| 90 | + dist_upload: |
| 91 | + runs-on: ubuntu-latest |
| 92 | + if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') |
| 93 | + needs: [dist_check] |
| 94 | + name: PyPI upload |
| 95 | + permissions: |
| 96 | + id-token: write |
| 97 | + steps: |
| 98 | + - uses: actions/download-artifact@v4 |
| 99 | + with: |
| 100 | + name: dist |
| 101 | + path: dist |
| 102 | + - name: Publish package to PyPI |
| 103 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments