|
1 | 1 | name: Tests |
2 | 2 |
|
3 | 3 | on: |
4 | | - pull_request: {} |
| 4 | + merge_group: |
| 5 | + pull_request: |
5 | 6 | push: |
6 | | - branches: [main] |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 10 | + cancel-in-progress: ${{ github.event_name == 'pull_request' }} |
| 11 | + |
| 12 | +defaults: |
| 13 | + run: |
| 14 | + shell: bash |
7 | 15 |
|
8 | 16 | env: |
9 | 17 | PYTHONWARNDEFAULTENCODING: 'true' |
10 | 18 |
|
11 | 19 | jobs: |
12 | | - tests: |
13 | | - name: ${{ matrix.os }} / ${{ matrix.python-version }} |
14 | | - runs-on: "${{ matrix.os }}-latest" |
| 20 | + changes: |
| 21 | + name: Detect changed files |
| 22 | + runs-on: ubuntu-latest |
| 23 | + outputs: |
| 24 | + project: ${{ steps.changes.outputs.project }} |
| 25 | + src: ${{ steps.changes.outputs.src }} |
| 26 | + tests: ${{ steps.changes.outputs.tests }} |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 |
| 29 | + |
| 30 | + - uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3 |
| 31 | + id: changes |
| 32 | + with: |
| 33 | + filters: | |
| 34 | + workflow: &workflow |
| 35 | + - '.github/actions/**' |
| 36 | + - '.github/workflows/tests.yaml' |
| 37 | + - '.github/workflows/.tests-matrix.yaml' |
| 38 | + project: &project |
| 39 | + - *workflow |
| 40 | + - 'poetry.lock' |
| 41 | + - 'pyproject.toml' |
| 42 | + src: |
| 43 | + - *project |
| 44 | + - 'src/**/*.py' |
| 45 | + tests: |
| 46 | + - *project |
| 47 | + - 'src/**/*.py' |
| 48 | + - 'tests/**' |
| 49 | +
|
| 50 | + lockfile: |
| 51 | + name: Check poetry.lock |
| 52 | + runs-on: ubuntu-latest |
| 53 | + if: needs.changes.outputs.project == 'true' |
| 54 | + needs: changes |
| 55 | + steps: |
| 56 | + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 |
| 57 | + |
| 58 | + - uses: ./.github/actions/bootstrap-poetry |
| 59 | + |
| 60 | + - run: poetry check --lock |
| 61 | + |
| 62 | + tests-matrix: |
| 63 | + # Use this matrix with multiple jobs defined in a reusable workflow: |
| 64 | + uses: ./.github/workflows/.tests-matrix.yaml |
| 65 | + name: ${{ matrix.os.name }} (Python ${{ matrix.python-version }}) |
| 66 | + if: '!failure() && !cancelled()' |
| 67 | + needs: |
| 68 | + - lockfile |
| 69 | + - changes |
| 70 | + with: |
| 71 | + runner: ${{ matrix.os.image }} |
| 72 | + python-version: ${{ matrix.python-version }} |
| 73 | + run-mypy: ${{ needs.changes.outputs.src == 'true' }} |
| 74 | + run-pytest: ${{ needs.changes.outputs.tests == 'true' }} |
| 75 | + run-pytest-poetry: ${{ needs.changes.outputs.src == 'true' }} |
| 76 | + secrets: inherit |
15 | 77 | strategy: |
16 | 78 | matrix: |
17 | | - os: [Ubuntu, MacOS, Windows] |
| 79 | + os: |
| 80 | + - name: Ubuntu |
| 81 | + image: ubuntu-22.04 |
| 82 | + - name: macOS |
| 83 | + image: macos-13 |
| 84 | + - name: Windows |
| 85 | + image: windows-2022 |
18 | 86 | python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] |
19 | 87 | include: |
20 | | - - os: Ubuntu |
21 | | - python-version: pypy-3.8 |
| 88 | + - os: {name: Ubuntu, image: ubuntu-22.04} |
| 89 | + python-version: pypy3.9 |
| 90 | + - os: {name: Ubuntu, image: ubuntu-22.04} |
| 91 | + python-version: pypy3.10 |
22 | 92 | fail-fast: false |
23 | | - defaults: |
24 | | - run: |
25 | | - shell: bash |
26 | | - steps: |
27 | | - - uses: actions/checkout@v4 |
28 | | - |
29 | | - - name: Set up Python ${{ matrix.python-version }} |
30 | | - uses: actions/setup-python@v5 |
31 | | - with: |
32 | | - python-version: ${{ matrix.python-version }} |
33 | | - |
34 | | - - name: Get full Python version |
35 | | - id: full-python-version |
36 | | - run: echo version=$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))") >> $GITHUB_OUTPUT |
37 | | - |
38 | | - - name: Bootstrap poetry |
39 | | - run: | |
40 | | - curl -sSL https://install.python-poetry.org | python - -y |
41 | 93 |
|
42 | | - - name: Update PATH |
43 | | - if: ${{ matrix.os != 'Windows' }} |
44 | | - run: echo "$HOME/.local/bin" >> $GITHUB_PATH |
45 | | - |
46 | | - - name: Update Path for Windows |
47 | | - if: ${{ matrix.os == 'Windows' }} |
48 | | - run: echo "$APPDATA\Python\Scripts" >> $GITHUB_PATH |
49 | | - |
50 | | - - name: Configure poetry |
51 | | - run: poetry config virtualenvs.in-project true |
52 | | - |
53 | | - - name: Set up cache |
54 | | - uses: actions/cache@v4 |
55 | | - id: cache |
56 | | - with: |
57 | | - path: .venv |
58 | | - key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }} |
59 | | - |
60 | | - - name: Ensure cache is healthy |
61 | | - if: steps.cache.outputs.cache-hit == 'true' |
62 | | - run: | |
63 | | - # `timeout` is not available on macOS, so we define a custom function. |
64 | | - [ "$(command -v timeout)" ] || function timeout() { perl -e 'alarm shift; exec @ARGV' "$@"; } |
65 | | - # Using `timeout` is a safeguard against the Poetry command hanging for some reason. |
66 | | - timeout 10s poetry run pip --version || rm -rf .venv |
67 | | -
|
68 | | - - name: Check lock file |
69 | | - run: poetry lock --check |
70 | | - |
71 | | - - name: Install dependencies |
72 | | - run: poetry install |
73 | | - |
74 | | - - name: Run tests |
75 | | - run: poetry run python -m pytest -p no:sugar -q tests/ |
76 | | - |
77 | | - - name: Run integration tests |
78 | | - run: poetry run python -m pytest -p no:sugar --integration -q tests/integration |
79 | | - |
80 | | - - name: Run mypy |
81 | | - run: poetry run mypy |
| 94 | + status: |
| 95 | + name: Status |
| 96 | + runs-on: ubuntu-latest |
| 97 | + if: '!cancelled()' |
| 98 | + needs: |
| 99 | + - lockfile |
| 100 | + - tests-matrix |
| 101 | + steps: |
| 102 | + - run: ${{ (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) && 'false' || 'true' }} |
0 commit comments