|
| 1 | +name: "Stage 2: Test" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + |
| 6 | +permissions: |
| 7 | + contents: read |
| 8 | + security-events: write |
| 9 | + |
| 10 | +jobs: |
| 11 | + test-unit: |
| 12 | + name: Unit tests |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout code |
| 16 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 17 | + |
| 18 | + - name: Read tool versions |
| 19 | + id: tool-versions |
| 20 | + run: | |
| 21 | + echo "python=$(awk '/^python / {print $2}' .tool-versions)" >> "$GITHUB_OUTPUT" |
| 22 | + echo "uv=$(awk '/^uv / {print $2}' .tool-versions)" >> "$GITHUB_OUTPUT" |
| 23 | +
|
| 24 | + - name: Set up Python |
| 25 | + uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 |
| 26 | + with: |
| 27 | + python-version: ${{ steps.tool-versions.outputs.python }} |
| 28 | + |
| 29 | + - name: Install uv |
| 30 | + uses: astral-sh/setup-uv@887a942a15af3a7626099df99e897a18d9e5ab3a # v5.1.0 |
| 31 | + with: |
| 32 | + version: ${{ steps.tool-versions.outputs.uv }} |
| 33 | + enable-cache: true |
| 34 | + |
| 35 | + - name: Install dependencies |
| 36 | + run: uv sync --all-extras |
| 37 | + |
| 38 | + - name: Run tests |
| 39 | + run: uv run pytest |
| 40 | + |
| 41 | + - name: Upload coverage reports |
| 42 | + uses: codecov/codecov-action@cb6530fbecd68d5f1ee7a3dcd113450ea8d5d6d4 # v5.1.2 |
| 43 | + if: always() |
| 44 | + with: |
| 45 | + files: ./coverage.xml |
| 46 | + flags: unittests |
| 47 | + name: codecov-umbrella |
| 48 | + fail_ci_if_error: false |
| 49 | + |
| 50 | + test-lint: |
| 51 | + name: Lint and type checking |
| 52 | + runs-on: ubuntu-latest |
| 53 | + steps: |
| 54 | + - name: Checkout code |
| 55 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 56 | + |
| 57 | + - name: Read tool versions |
| 58 | + id: tool-versions |
| 59 | + run: | |
| 60 | + echo "python=$(awk '/^python / {print $2}' .tool-versions)" >> "$GITHUB_OUTPUT" |
| 61 | + echo "uv=$(awk '/^uv / {print $2}' .tool-versions)" >> "$GITHUB_OUTPUT" |
| 62 | +
|
| 63 | + - name: Set up Python |
| 64 | + uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 |
| 65 | + with: |
| 66 | + python-version: ${{ steps.tool-versions.outputs.python }} |
| 67 | + |
| 68 | + - name: Install uv |
| 69 | + uses: astral-sh/setup-uv@887a942a15af3a7626099df99e897a18d9e5ab3a # v5.1.0 |
| 70 | + with: |
| 71 | + version: ${{ steps.tool-versions.outputs.uv }} |
| 72 | + enable-cache: true |
| 73 | + |
| 74 | + - name: Install dependencies |
| 75 | + run: uv sync --all-extras |
| 76 | + |
| 77 | + - name: Run ruff check (SARIF) |
| 78 | + id: ruff |
| 79 | + run: | |
| 80 | + # Run ruff and capture output. If it fails or is empty, provide a valid empty SARIF. |
| 81 | + if uv run ruff check . --format sarif > ruff-results.sarif; then |
| 82 | + echo "Results generated." |
| 83 | + else |
| 84 | + echo "Ruff failed or returned non-zero. Checking if file is valid..." |
| 85 | + fi |
| 86 | +
|
| 87 | + # If the file is empty or missing, create a valid empty SARIF object |
| 88 | + if [ ! -s ruff-results.sarif ]; then |
| 89 | + echo '{"version": "2.1.0", "$schema": "https://json.schemastore.org/sarif-2.1.0-rtm.5.json", "runs": [{"tool": {"driver": {"name": "Ruff"}}, "results": []}]}' > ruff-results.sarif |
| 90 | + fi |
| 91 | + continue-on-error: true |
| 92 | + |
| 93 | + - name: Upload ruff SARIF |
| 94 | + uses: github/codeql-action/upload-sarif@8c78abb9b62512e3c45dea6559ffd924ed8549c8 # v3.28.0 |
| 95 | + with: |
| 96 | + sarif_file: ruff-results.sarif |
| 97 | + if: always() |
| 98 | + |
| 99 | + - name: Run ruff format check |
| 100 | + run: uv run ruff format --check . |
| 101 | + |
| 102 | + - name: Run pyright |
| 103 | + run: uv run pyright |
0 commit comments