|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + pull_request: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + release: |
| 10 | + types: |
| 11 | + - published |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 15 | + cancel-in-progress: true |
| 16 | + |
| 17 | +env: |
| 18 | + FORCE_COLOR: 3 |
| 19 | + |
| 20 | +jobs: |
| 21 | + pre-commit: |
| 22 | + name: Format |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v3 |
| 26 | + with: |
| 27 | + fetch-depth: 0 |
| 28 | + - uses: actions/setup-python@v4 |
| 29 | + with: |
| 30 | + python-version: "3.x" |
| 31 | + - uses: pre-commit/[email protected] |
| 32 | + with: |
| 33 | + extra_args: --hook-stage manual --all-files |
| 34 | + |
| 35 | + checks: |
| 36 | + name: Check Python ${{ matrix.python-version }} on ${{ matrix.runs-on }} |
| 37 | + runs-on: ${{ matrix.runs-on }} |
| 38 | + needs: [pre-commit] |
| 39 | + strategy: |
| 40 | + fail-fast: false |
| 41 | + matrix: |
| 42 | + python-version: ["3.7", "3.11"] |
| 43 | + runs-on: [ubuntu-latest, macos-latest, windows-latest] |
| 44 | + |
| 45 | + steps: |
| 46 | + - uses: actions/checkout@v3 |
| 47 | + with: |
| 48 | + fetch-depth: 0 |
| 49 | + |
| 50 | + - uses: actions/setup-python@v4 |
| 51 | + with: |
| 52 | + python-version: ${{ matrix.python-version }} |
| 53 | + |
| 54 | + - name: Install package |
| 55 | + run: python -m pip install .[test] |
| 56 | + |
| 57 | + - name: Test package |
| 58 | + run: >- |
| 59 | + python -m pytest -ra --cov --cov-report=xml --cov-report=term |
| 60 | + --durations=20 |
| 61 | +
|
| 62 | + - name: Upload coverage report |
| 63 | + |
| 64 | + |
| 65 | + dist: |
| 66 | + needs: [pre-commit] |
| 67 | + name: Distribution build |
| 68 | + runs-on: ubuntu-latest |
| 69 | + |
| 70 | + steps: |
| 71 | + - uses: actions/checkout@v3 |
| 72 | + with: |
| 73 | + fetch-depth: 0 |
| 74 | + |
| 75 | + - name: Build sdist and wheel |
| 76 | + run: pipx run build |
| 77 | + |
| 78 | + - uses: actions/upload-artifact@v3 |
| 79 | + with: |
| 80 | + path: dist |
| 81 | + |
| 82 | + - name: Check products |
| 83 | + run: pipx run twine check dist/* |
| 84 | + |
| 85 | + publish: |
| 86 | + needs: [dist] |
| 87 | + name: Publish to PyPI |
| 88 | + environment: pypi |
| 89 | + permissions: |
| 90 | + id-token: write |
| 91 | + runs-on: ubuntu-latest |
| 92 | + if: github.event_name == 'release' && github.event.action == 'published' |
| 93 | + |
| 94 | + steps: |
| 95 | + - uses: actions/download-artifact@v3 |
| 96 | + with: |
| 97 | + name: artifact |
| 98 | + path: dist |
| 99 | + |
| 100 | + - uses: pypa/gh-action-pypi-publish@release/v1 |
| 101 | + if: github.event_name == 'release' && github.event.action == 'published' |
| 102 | + with: |
| 103 | + # Remember to tell (test-)pypi about this repo before publishing |
| 104 | + # Remove this line to publish to PyPI |
| 105 | + repository-url: https://test.pypi.org/legacy/ |
0 commit comments