|
| 1 | +name: E2E Tests |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - Henrik/e2e-cpu-smoke |
| 7 | + # Uncomment to run on every push to main / pull request: |
| 8 | + # push: |
| 9 | + # branches: [main] |
| 10 | + # pull_request: |
| 11 | + # branches: [main] |
| 12 | + workflow_dispatch: |
| 13 | + inputs: |
| 14 | + tests: |
| 15 | + description: 'E2E test filter (pytest -k expression, leave empty to run all e2e tests)' |
| 16 | + required: false |
| 17 | + default: '' |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: read |
| 21 | + |
| 22 | +env: |
| 23 | + PYTHON_VERSION: '3.11' |
| 24 | + |
| 25 | +jobs: |
| 26 | + unit-tests: |
| 27 | + name: Unit + Integration |
| 28 | + runs-on: ubuntu-latest |
| 29 | + timeout-minutes: 15 |
| 30 | + |
| 31 | + steps: |
| 32 | + - name: Checkout code |
| 33 | + uses: actions/checkout@v4 |
| 34 | + |
| 35 | + - name: Set up Python |
| 36 | + uses: actions/setup-python@v5 |
| 37 | + with: |
| 38 | + python-version: ${{ env.PYTHON_VERSION }} |
| 39 | + |
| 40 | + - name: Install uv |
| 41 | + uses: astral-sh/setup-uv@v5 |
| 42 | + with: |
| 43 | + enable-cache: true |
| 44 | + cache-dependency-glob: "pyproject.toml" |
| 45 | + |
| 46 | + - name: Install dependencies |
| 47 | + run: uv sync --all-groups |
| 48 | + |
| 49 | + - name: Run unit + integration tests |
| 50 | + run: | |
| 51 | + uv run pytest tests/unit/ tests/integration/ \ |
| 52 | + -n auto \ |
| 53 | + --timeout=60 \ |
| 54 | + --junitxml=unit-results.xml \ |
| 55 | + --cov-report=xml:coverage.xml \ |
| 56 | + --cov-fail-under=0 |
| 57 | +
|
| 58 | + - name: Upload test results |
| 59 | + uses: actions/upload-artifact@v4 |
| 60 | + if: always() |
| 61 | + with: |
| 62 | + name: unit-results |
| 63 | + path: unit-results.xml |
| 64 | + |
| 65 | + - name: Upload coverage |
| 66 | + uses: actions/upload-artifact@v4 |
| 67 | + if: always() |
| 68 | + with: |
| 69 | + name: coverage |
| 70 | + path: coverage.xml |
| 71 | + |
| 72 | + e2e: |
| 73 | + name: E2E |
| 74 | + runs-on: ubuntu-latest |
| 75 | + timeout-minutes: 30 |
| 76 | + |
| 77 | + steps: |
| 78 | + - name: Checkout code |
| 79 | + uses: actions/checkout@v4 |
| 80 | + |
| 81 | + - name: Set up Python |
| 82 | + uses: actions/setup-python@v5 |
| 83 | + with: |
| 84 | + python-version: ${{ env.PYTHON_VERSION }} |
| 85 | + |
| 86 | + - name: Install uv |
| 87 | + uses: astral-sh/setup-uv@v5 |
| 88 | + with: |
| 89 | + enable-cache: true |
| 90 | + cache-dependency-glob: "pyproject.toml" |
| 91 | + |
| 92 | + - name: Install dependencies |
| 93 | + run: uv sync --all-groups |
| 94 | + |
| 95 | + - name: Run E2E tests |
| 96 | + env: |
| 97 | + RUNPOD_API_KEY: ${{ secrets.RUNPOD_API_KEY }} |
| 98 | + run: | |
| 99 | + uv run pytest e2e/ \ |
| 100 | + ${{ inputs.tests != '' && format('-k "{0}"', inputs.tests) || '' }} \ |
| 101 | + -v \ |
| 102 | + --timeout=0 \ |
| 103 | + --no-cov \ |
| 104 | + -p no:xdist \ |
| 105 | + --override-ini="addopts=" \ |
| 106 | + --junitxml=e2e-results.xml \ |
| 107 | + -s |
| 108 | +
|
| 109 | + - name: Check at least one test ran |
| 110 | + if: always() |
| 111 | + run: | |
| 112 | + python - <<'EOF' |
| 113 | + import xml.etree.ElementTree as ET, sys |
| 114 | + try: |
| 115 | + tree = ET.parse("e2e-results.xml") |
| 116 | + root = tree.getroot() |
| 117 | + if root.tag == "testsuites": |
| 118 | + tests = sum(int(s.attrib.get("tests", 0)) for s in root.findall("testsuite")) |
| 119 | + else: |
| 120 | + tests = int(root.attrib.get("tests", 0)) |
| 121 | + print(f"Tests run: {tests}") |
| 122 | + if tests == 0: |
| 123 | + print("ERROR: 0 tests ran — check test filter or test collection") |
| 124 | + sys.exit(1) |
| 125 | + except FileNotFoundError: |
| 126 | + print("ERROR: e2e-results.xml not found — pytest did not run") |
| 127 | + sys.exit(1) |
| 128 | + EOF |
| 129 | +
|
| 130 | + - name: Upload test results |
| 131 | + uses: actions/upload-artifact@v4 |
| 132 | + if: always() |
| 133 | + with: |
| 134 | + name: e2e-results |
| 135 | + path: e2e-results.xml |
| 136 | + |
| 137 | + summary: |
| 138 | + name: Summary |
| 139 | + needs: [unit-tests, e2e] |
| 140 | + if: always() |
| 141 | + runs-on: ubuntu-latest |
| 142 | + timeout-minutes: 5 |
| 143 | + |
| 144 | + steps: |
| 145 | + - name: Download unit results |
| 146 | + uses: actions/download-artifact@v4 |
| 147 | + with: |
| 148 | + name: unit-results |
| 149 | + continue-on-error: true |
| 150 | + |
| 151 | + - name: Download coverage |
| 152 | + uses: actions/download-artifact@v4 |
| 153 | + with: |
| 154 | + name: coverage |
| 155 | + continue-on-error: true |
| 156 | + |
| 157 | + - name: Download E2E results |
| 158 | + uses: actions/download-artifact@v4 |
| 159 | + with: |
| 160 | + name: e2e-results |
| 161 | + continue-on-error: true |
| 162 | + |
| 163 | + - name: Write summary |
| 164 | + env: |
| 165 | + UNIT_RESULT: ${{ needs.unit-tests.result }} |
| 166 | + E2E_RESULT: ${{ needs.e2e.result }} |
| 167 | + run: | |
| 168 | + python - <<'EOF' |
| 169 | + import xml.etree.ElementTree as ET, os, sys |
| 170 | +
|
| 171 | + summary_file = os.environ.get("GITHUB_STEP_SUMMARY") |
| 172 | + out = open(summary_file, "a") if summary_file else sys.stdout |
| 173 | +
|
| 174 | + def parse_junit(path): |
| 175 | + """Return (total, failures, duration) from a JUnit XML file.""" |
| 176 | + try: |
| 177 | + root = ET.parse(path).getroot() |
| 178 | + suites = root.findall("testsuite") if root.tag == "testsuites" else [root] |
| 179 | + total = sum(int(s.attrib.get("tests", 0)) for s in suites) |
| 180 | + failures = sum(int(s.attrib.get("failures", 0)) + int(s.attrib.get("errors", 0)) for s in suites) |
| 181 | + duration = sum(float(s.attrib.get("time", 0)) for s in suites) |
| 182 | + failed_names = [ |
| 183 | + tc.get("classname", "") + "::" + tc.get("name", "") |
| 184 | + for s in suites |
| 185 | + for tc in s.findall("testcase") |
| 186 | + if tc.find("failure") is not None or tc.find("error") is not None |
| 187 | + ] |
| 188 | + return total, failures, duration, failed_names |
| 189 | + except FileNotFoundError: |
| 190 | + return None, None, None, [] |
| 191 | +
|
| 192 | + def status_icon(result, total, failures): |
| 193 | + if total is None: return ":x: Did not run" |
| 194 | + if total == 0: return ":warning: No tests ran" |
| 195 | + if failures == 0: return ":white_check_mark: Passed" |
| 196 | + return ":x: Failed" |
| 197 | +
|
| 198 | + unit_total, unit_fail, unit_dur, unit_failed_names = parse_junit("unit-results.xml") |
| 199 | + e2e_total, e2e_fail, e2e_dur, e2e_failed_names = parse_junit("e2e-results.xml") |
| 200 | +
|
| 201 | + unit_pass = (unit_total - unit_fail) if unit_total is not None else None |
| 202 | + e2e_pass = (e2e_total - e2e_fail) if e2e_total is not None else None |
| 203 | +
|
| 204 | + unit_result = os.environ.get("UNIT_RESULT", "") |
| 205 | + e2e_result = os.environ.get("E2E_RESULT", "") |
| 206 | +
|
| 207 | + print("# Test Results\n", file=out) |
| 208 | + print("| Suite | Status | Passed | Failed | Total | Duration |", file=out) |
| 209 | + print("|---|---|---|---|---|---|", file=out) |
| 210 | + print(f"| Unit + Integration | {status_icon(unit_result, unit_total, unit_fail)} | " |
| 211 | + f"{unit_pass if unit_pass is not None else '-'} | " |
| 212 | + f"{unit_fail if unit_fail is not None else '-'} | " |
| 213 | + f"{unit_total if unit_total is not None else '-'} | " |
| 214 | + f"{unit_dur:.1f}s |" if unit_dur is not None else "- |", file=out) |
| 215 | + print(f"| E2E | {status_icon(e2e_result, e2e_total, e2e_fail)} | " |
| 216 | + f"{e2e_pass if e2e_pass is not None else '-'} | " |
| 217 | + f"{e2e_fail if e2e_fail is not None else '-'} | " |
| 218 | + f"{e2e_total if e2e_total is not None else '-'} | " |
| 219 | + f"{e2e_dur:.1f}s |" if e2e_dur is not None else "- |", file=out) |
| 220 | + print("", file=out) |
| 221 | +
|
| 222 | + all_failed = [("Unit", n) for n in unit_failed_names] + [("E2E", n) for n in e2e_failed_names] |
| 223 | + if all_failed: |
| 224 | + print("## Failed Tests\n", file=out) |
| 225 | + print("| Suite | Test |", file=out) |
| 226 | + print("|---|---|", file=out) |
| 227 | + for suite, name in all_failed: |
| 228 | + print(f"| {suite} | `{name}` |", file=out) |
| 229 | + print("", file=out) |
| 230 | +
|
| 231 | + # Coverage |
| 232 | + print("## Coverage\n", file=out) |
| 233 | + try: |
| 234 | + cov_root = ET.parse("coverage.xml").getroot() |
| 235 | + line_rate = float(cov_root.attrib.get("line-rate", 0)) |
| 236 | + total_cov = f"{line_rate * 100:.1f}%" |
| 237 | + print(f"**Total: {total_cov}**\n", file=out) |
| 238 | + print("<details>", file=out) |
| 239 | + print("<summary>Per-package breakdown</summary>\n", file=out) |
| 240 | + print("| Package | Coverage |", file=out) |
| 241 | + print("|---|---|", file=out) |
| 242 | + for pkg in cov_root.iter("package"): |
| 243 | + name = pkg.attrib.get("name", "") |
| 244 | + rate = float(pkg.attrib.get("line-rate", 0)) |
| 245 | + print(f"| `{name}` | {rate * 100:.1f}% |", file=out) |
| 246 | + print("</details>", file=out) |
| 247 | + except FileNotFoundError: |
| 248 | + print("> Coverage data not available.", file=out) |
| 249 | + EOF |
0 commit comments