|
| 1 | +name: "Tests" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + |
| 6 | +jobs: |
| 7 | + unit: |
| 8 | + name: "Unit | Py${{ matrix.python-version }} on ${{ matrix.os }}" |
| 9 | + runs-on: ${{ matrix.os }} |
| 10 | + strategy: |
| 11 | + fail-fast: false |
| 12 | + matrix: |
| 13 | + include: |
| 14 | + - os: ubuntu-22.04 |
| 15 | + python-version: '3.7' |
| 16 | + - os: ubuntu-22.04 |
| 17 | + python-version: '3.8' |
| 18 | + - os: ubuntu-22.04 |
| 19 | + python-version: '3.9' |
| 20 | + - os: ubuntu-22.04 |
| 21 | + python-version: '3.10' |
| 22 | + - os: ubuntu-22.04 |
| 23 | + python-version: '3.11' |
| 24 | + - os: ubuntu-22.04 |
| 25 | + python-version: '3.12' |
| 26 | + - os: ubuntu-22.04 |
| 27 | + python-version: '3.13' |
| 28 | + - os: ubuntu-22.04 |
| 29 | + python-version: '3.14' |
| 30 | + - os: macos-latest |
| 31 | + python-version: '3.13' |
| 32 | + - os: windows-latest |
| 33 | + python-version: '3.13' |
| 34 | + |
| 35 | + steps: |
| 36 | + - name: "Checkout" |
| 37 | + uses: actions/checkout@v4 |
| 38 | + |
| 39 | + - name: "Set up Python" |
| 40 | + uses: actions/setup-python@v5 |
| 41 | + with: |
| 42 | + python-version: ${{ matrix.python-version }} |
| 43 | + cache: pip |
| 44 | + cache-dependency-path: | |
| 45 | + pyproject.toml |
| 46 | + uv.lock |
| 47 | +
|
| 48 | + - name: "Install unit test dependencies" |
| 49 | + run: python -m pip install --upgrade pip pytest pytest-cov httpx requests pyyaml |
| 50 | + |
| 51 | + - name: "Run unit tests with coverage" |
| 52 | + env: |
| 53 | + COVERAGE_FILE: coverage-unit.dat |
| 54 | + run: > |
| 55 | + pytest -q tests/test_mellophone.py tests/test_structures.py |
| 56 | + --cov=src/mellophone |
| 57 | + --cov-report= |
| 58 | +
|
| 59 | + - name: "Upload unit coverage data" |
| 60 | + if: matrix.os == 'ubuntu-22.04' && matrix.python-version == '3.13' |
| 61 | + uses: actions/upload-artifact@v4 |
| 62 | + with: |
| 63 | + name: coverage-unit-data |
| 64 | + path: coverage-unit.dat |
| 65 | + |
| 66 | + integration: |
| 67 | + name: "Integration | Py3.13 on ubuntu-22.04" |
| 68 | + runs-on: ubuntu-22.04 |
| 69 | + |
| 70 | + steps: |
| 71 | + - name: "Checkout" |
| 72 | + uses: actions/checkout@v4 |
| 73 | + |
| 74 | + - name: "Set up Python" |
| 75 | + uses: actions/setup-python@v5 |
| 76 | + with: |
| 77 | + python-version: '3.13' |
| 78 | + cache: pip |
| 79 | + cache-dependency-path: | |
| 80 | + pyproject.toml |
| 81 | + uv.lock |
| 82 | +
|
| 83 | + - name: "Install integration test dependencies" |
| 84 | + run: python -m pip install --upgrade pip pytest pytest-cov httpx requests pyyaml |
| 85 | + |
| 86 | + - name: "Cache Docker images" |
| 87 | + id: docker-cache |
| 88 | + uses: actions/cache@v4 |
| 89 | + with: |
| 90 | + path: /tmp/docker-image-cache |
| 91 | + key: docker-images-${{ runner.os }}-${{ hashFiles('docker-compose.yml') }} |
| 92 | + |
| 93 | + - name: "Load cached Docker images" |
| 94 | + if: steps.docker-cache.outputs.cache-hit == 'true' |
| 95 | + shell: bash |
| 96 | + run: | |
| 97 | + [ -f /tmp/docker-image-cache/mellophone.tar ] && docker load -i /tmp/docker-image-cache/mellophone.tar || true |
| 98 | + [ -f /tmp/docker-image-cache/postgres.tar ] && docker load -i /tmp/docker-image-cache/postgres.tar || true |
| 99 | +
|
| 100 | + - name: "Pull Docker images" |
| 101 | + if: steps.docker-cache.outputs.cache-hit != 'true' |
| 102 | + shell: bash |
| 103 | + run: | |
| 104 | + docker pull curs/mellophone2:1.6.1 |
| 105 | + docker pull postgres:16.3-alpine |
| 106 | +
|
| 107 | + - name: "Save Docker images to cache" |
| 108 | + if: steps.docker-cache.outputs.cache-hit != 'true' |
| 109 | + shell: bash |
| 110 | + run: | |
| 111 | + mkdir -p /tmp/docker-image-cache |
| 112 | + docker save curs/mellophone2:1.6.1 -o /tmp/docker-image-cache/mellophone.tar |
| 113 | + docker save postgres:16.3-alpine -o /tmp/docker-image-cache/postgres.tar |
| 114 | +
|
| 115 | + - name: "Start DB and Mellophone" |
| 116 | + run: docker compose up -d db mellophone |
| 117 | + |
| 118 | + - name: "Wait for Mellophone" |
| 119 | + shell: bash |
| 120 | + run: | |
| 121 | + for i in {1..20}; do |
| 122 | + if curl -fsS "http://localhost:8082/mellophone/authentication.gif?sesid=ci-smoke" >/dev/null; then |
| 123 | + echo "Mellophone is reachable" |
| 124 | + exit 0 |
| 125 | + fi |
| 126 | + sleep 2 |
| 127 | + done |
| 128 | + docker compose logs |
| 129 | + exit 1 |
| 130 | +
|
| 131 | + - name: "Run integration tests with coverage" |
| 132 | + env: |
| 133 | + COVERAGE_FILE: coverage-integration.dat |
| 134 | + run: > |
| 135 | + pytest -q tests/test_integration_mellophone.py |
| 136 | + --cov=src/mellophone |
| 137 | + --cov-report= |
| 138 | +
|
| 139 | + - name: "Upload integration coverage data" |
| 140 | + uses: actions/upload-artifact@v4 |
| 141 | + with: |
| 142 | + name: coverage-integration-data |
| 143 | + path: coverage-integration.dat |
| 144 | + |
| 145 | + - name: "Stop services" |
| 146 | + if: always() |
| 147 | + run: docker compose down -v |
| 148 | + |
| 149 | + coverage-report: |
| 150 | + name: "Coverage Report" |
| 151 | + needs: [unit, integration] |
| 152 | + runs-on: ubuntu-22.04 |
| 153 | + |
| 154 | + steps: |
| 155 | + - name: "Checkout" |
| 156 | + uses: actions/checkout@v4 |
| 157 | + |
| 158 | + - name: "Set up Python" |
| 159 | + uses: actions/setup-python@v5 |
| 160 | + with: |
| 161 | + python-version: '3.13' |
| 162 | + |
| 163 | + - name: "Download unit coverage data" |
| 164 | + uses: actions/download-artifact@v4 |
| 165 | + with: |
| 166 | + name: coverage-unit-data |
| 167 | + path: coverage_data/unit |
| 168 | + |
| 169 | + - name: "Download integration coverage data" |
| 170 | + uses: actions/download-artifact@v4 |
| 171 | + with: |
| 172 | + name: coverage-integration-data |
| 173 | + path: coverage_data/integration |
| 174 | + |
| 175 | + - name: "Install coverage tools" |
| 176 | + run: python -m pip install --upgrade pip coverage |
| 177 | + |
| 178 | + - name: "Combine and build coverage reports" |
| 179 | + run: | |
| 180 | + python -m coverage combine coverage_data/unit/coverage-unit.dat coverage_data/integration/coverage-integration.dat |
| 181 | + python -m coverage report -m |
| 182 | + python -m coverage xml -o coverage.xml |
| 183 | + python -m coverage json -o coverage.json |
| 184 | +
|
| 185 | + - name: "Add coverage to job summary" |
| 186 | + uses: actions/github-script@v7 |
| 187 | + with: |
| 188 | + script: | |
| 189 | + const fs = require("fs"); |
| 190 | + const report = JSON.parse(fs.readFileSync("coverage.json", "utf8")); |
| 191 | + const total = report.totals.percent_covered_display; |
| 192 | + core.summary |
| 193 | + .addHeading("Coverage (unit + integration)", 2) |
| 194 | + .addRaw(`- Total: ${total}%`) |
| 195 | + .write(); |
| 196 | +
|
| 197 | + - name: "Upload coverage artifacts" |
| 198 | + uses: actions/upload-artifact@v4 |
| 199 | + with: |
| 200 | + name: coverage-report |
| 201 | + path: | |
| 202 | + coverage.xml |
| 203 | + coverage.json |
0 commit comments