|
6 | 6 | pull_request: |
7 | 7 | branches: [main, develop] |
8 | 8 |
|
| 9 | +concurrency: |
| 10 | + group: cedarmapper-ci-${{ github.ref }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + |
| 16 | +env: |
| 17 | + # default make target used by the job; override at workflow dispatch or in job in PR comments |
| 18 | + MAKE_TARGET: ci |
| 19 | + # change this to run a different make target in the job: e.g. MAKE_TARGET=test |
| 20 | + PIP_CACHE_DIR: ~/.cache/pip |
| 21 | + |
9 | 22 | jobs: |
10 | | - test: |
| 23 | + ci: |
| 24 | + name: CI (Makefile-driven) |
11 | 25 | runs-on: ubuntu-latest |
12 | 26 | strategy: |
| 27 | + fail-fast: true |
13 | 28 | matrix: |
14 | | - python-version: ["3.12", "3.13"] |
| 29 | + python-version: [3.12, 3.13] |
15 | 30 |
|
16 | 31 | steps: |
17 | | - - uses: actions/checkout@v4 |
| 32 | + - name: Checkout repository |
| 33 | + uses: actions/checkout@v4 |
18 | 34 |
|
19 | 35 | - name: Set up Python ${{ matrix.python-version }} |
20 | 36 | uses: actions/setup-python@v4 |
21 | 37 | with: |
22 | 38 | python-version: ${{ matrix.python-version }} |
| 39 | + cache: "pip" |
23 | 40 |
|
24 | | - - name: Install dependencies |
| 41 | + - name: Cache mypy/ruff caches |
| 42 | + uses: actions/cache@v4 |
| 43 | + id: cache-mypy-ruff |
| 44 | + with: |
| 45 | + # include python version so caches are separate between interpreters |
| 46 | + path: | |
| 47 | + .mypy_cache |
| 48 | + .ruff_cache |
| 49 | + htmlcov |
| 50 | + key: ${{ runner.os }}-mypy-ruff-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }} |
| 51 | + restore-keys: | |
| 52 | + ${{ runner.os }}-mypy-ruff-${{ matrix.python-version }}- |
| 53 | + ${{ runner.os }}-mypy-ruff- |
| 54 | +
|
| 55 | + - name: Install build & dev dependencies |
| 56 | + # Keep this step hermetic and simple: install editable package with dev extras |
25 | 57 | run: | |
26 | | - python -m pip install --upgrade pip |
27 | | - pip install -e ".[dev]" |
| 58 | + python -m pip install --upgrade pip setuptools wheel |
| 59 | + # Use editable install so `make` targets that call python modules run against current source |
| 60 | + python -m pip install -e ".[dev]" |
| 61 | + # If your project needs additional build steps (e.g. C extensions) add them here. |
28 | 62 |
|
29 | | - - name: Lint with ruff |
30 | | - run: ruff check src/ tests/ |
| 63 | + - name: Show environment (quick debug) |
| 64 | + run: | |
| 65 | + python --version |
| 66 | + pip --version |
| 67 | + pip list --format=columns | sed -n '1,200p' |
| 68 | + echo "Make target: ${MAKE_TARGET}" |
31 | 69 |
|
32 | | - - name: Format check with black |
33 | | - run: black --check src/ tests/ |
| 70 | + - name: Run formatting check (black --check) |
| 71 | + # split steps so logs are clearer and failures pinpointed |
| 72 | + run: | |
| 73 | + set -eo pipefail |
| 74 | + make format || true |
| 75 | + # enforce check: black --check to ensure CI fails on unformatted code |
| 76 | + black --check src tests |
34 | 77 |
|
35 | | - - name: Type check with mypy |
36 | | - run: mypy src/ |
| 78 | + - name: Run static checks & tests via Makefile |
| 79 | + # Use MAKE_TARGET env to run the aggregate CI target from your Makefile |
| 80 | + run: | |
| 81 | + set -eo pipefail |
| 82 | + # run the Makefile target (defaults to 'ci') |
| 83 | + make ${MAKE_TARGET} |
| 84 | + env: |
| 85 | + MAKE_TARGET: ${{ env.MAKE_TARGET }} |
37 | 86 |
|
38 | | - - name: Test with pytest |
39 | | - run: pytest --cov |
| 87 | + - name: Run tests again with explicit pytest xml for artifact (optional) |
| 88 | + # Some repos emit junit xml for test reporting; optional but useful. |
| 89 | + if: always() |
| 90 | + run: | |
| 91 | + set -eo pipefail |
| 92 | + # create junit xml and coverage xml in addition to html (pytest.ini already requests coverage xml) |
| 93 | + pytest -q --junitxml=reports/junit.xml || true |
| 94 | + continue-on-error: false |
| 95 | + |
| 96 | + - name: Upload coverage HTML (artifact) |
| 97 | + if: always() |
| 98 | + uses: actions/upload-artifact@v4 |
| 99 | + with: |
| 100 | + name: coverage-html-${{ matrix.python-version }} |
| 101 | + path: htmlcov |
40 | 102 |
|
41 | | - - name: Upload coverage |
42 | | - uses: codecov/codecov-action@v3 |
| 103 | + - name: Upload pytest junit xml (artifact) |
| 104 | + if: always() |
| 105 | + uses: actions/upload-artifact@v4 |
43 | 106 | with: |
44 | | - files: ./coverage.xml |
45 | | - fail_ci_if_error: false |
| 107 | + name: pytest-junit-${{ matrix.python-version }} |
| 108 | + path: reports/junit.xml |
0 commit comments