|
| 1 | +name: Coverage |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + paths: |
| 7 | + - "Cargo.toml" |
| 8 | + - "Cargo.lock" |
| 9 | + - "crates/**" |
| 10 | + - "specs/**" |
| 11 | + - ".github/workflows/coverage.yml" |
| 12 | + - "codecov.yml" |
| 13 | + pull_request: |
| 14 | + types: [opened, synchronize, reopened, labeled] |
| 15 | + branches: [main] |
| 16 | + paths: |
| 17 | + - "Cargo.toml" |
| 18 | + - "Cargo.lock" |
| 19 | + - "crates/**" |
| 20 | + - "specs/**" |
| 21 | + - ".github/workflows/coverage.yml" |
| 22 | + - "codecov.yml" |
| 23 | + workflow_dispatch: |
| 24 | + |
| 25 | +permissions: |
| 26 | + contents: read |
| 27 | + |
| 28 | +concurrency: |
| 29 | + group: coverage-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 30 | + cancel-in-progress: true |
| 31 | + |
| 32 | +env: |
| 33 | + CARGO_TERM_COLOR: always |
| 34 | + CARGO_INCREMENTAL: "0" |
| 35 | + RUSTFLAGS: "-C debuginfo=0" |
| 36 | + |
| 37 | +jobs: |
| 38 | + coverage: |
| 39 | + name: Codecov Coverage |
| 40 | + runs-on: ubuntu-latest |
| 41 | + timeout-minutes: 45 |
| 42 | + |
| 43 | + if: >- |
| 44 | + github.event_name == 'push' || |
| 45 | + github.event_name == 'workflow_dispatch' || |
| 46 | + contains(github.event.pull_request.labels.*.name, 'coverage') || |
| 47 | + contains(github.event.pull_request.labels.*.name, 'full-ci') || |
| 48 | + contains(github.event.pull_request.labels.*.name, 'ci:full') |
| 49 | +
|
| 50 | + steps: |
| 51 | + - uses: actions/checkout@v4 |
| 52 | + |
| 53 | + - name: Install Rust |
| 54 | + uses: dtolnay/rust-toolchain@master |
| 55 | + with: |
| 56 | + toolchain: "1.92.0" |
| 57 | + components: llvm-tools-preview |
| 58 | + |
| 59 | + - name: Install Linux HID build deps |
| 60 | + run: | |
| 61 | + sudo apt-get update |
| 62 | + sudo apt-get install -y libudev-dev |
| 63 | +
|
| 64 | + - name: Use larger target dir |
| 65 | + run: echo "CARGO_TARGET_DIR=${RUNNER_TEMP}/target" >> "$GITHUB_ENV" |
| 66 | + |
| 67 | + - uses: Swatinem/rust-cache@v2 |
| 68 | + with: |
| 69 | + cache-on-failure: true |
| 70 | + cache-directories: ${{ runner.temp }}/target |
| 71 | + shared-key: coverage-1.92 |
| 72 | + save-if: ${{ github.ref == 'refs/heads/main' }} |
| 73 | + |
| 74 | + - name: Install coverage tools |
| 75 | + uses: taiki-e/install-action@v2 |
| 76 | + with: |
| 77 | + tool: cargo-llvm-cov,cargo-nextest |
| 78 | + |
| 79 | + - name: Generate coverage |
| 80 | + env: |
| 81 | + CI: true |
| 82 | + PROPTEST_CASES: "64" |
| 83 | + INSTA_UPDATE: "no" |
| 84 | + run: | |
| 85 | + set -euo pipefail |
| 86 | + cargo llvm-cov clean --workspace |
| 87 | +
|
| 88 | + cargo llvm-cov nextest \ |
| 89 | + --locked \ |
| 90 | + --no-report \ |
| 91 | + -p flight-core \ |
| 92 | + -p flight-axis \ |
| 93 | + -p flight-bus \ |
| 94 | + -p flight-scheduler \ |
| 95 | + -p flight-rules \ |
| 96 | + -p flight-profile \ |
| 97 | + -p flight-units \ |
| 98 | + -p flight-session \ |
| 99 | + -p flight-metrics \ |
| 100 | + -p flight-device-common \ |
| 101 | + -p flight-hid-types \ |
| 102 | + -p flight-adapter-common \ |
| 103 | + -p flight-test-helpers \ |
| 104 | + -p flight-workspace-meta |
| 105 | +
|
| 106 | + cargo llvm-cov report --json --output-path coverage.json |
| 107 | + cargo llvm-cov report --lcov --output-path lcov.info |
| 108 | + cargo llvm-cov report --text | tee coverage.txt |
| 109 | +
|
| 110 | + - name: Validate coverage output |
| 111 | + run: | |
| 112 | + set -euo pipefail |
| 113 | + test -s coverage.json |
| 114 | + test -s coverage.txt |
| 115 | + test -s lcov.info |
| 116 | +
|
| 117 | + - name: Detect Codecov token |
| 118 | + id: codecov-token |
| 119 | + env: |
| 120 | + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
| 121 | + run: | |
| 122 | + if [ -n "${CODECOV_TOKEN:-}" ]; then |
| 123 | + echo "present=true" >> "$GITHUB_OUTPUT" |
| 124 | + else |
| 125 | + echo "present=false" >> "$GITHUB_OUTPUT" |
| 126 | + fi |
| 127 | +
|
| 128 | + - name: Upload coverage to Codecov (main) |
| 129 | + if: ${{ always() && github.event_name == 'push' && hashFiles('lcov.info') != '' && steps.codecov-token.outputs.present == 'true' }} |
| 130 | + uses: codecov/codecov-action@v5 |
| 131 | + with: |
| 132 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 133 | + files: lcov.info |
| 134 | + flags: rust-core |
| 135 | + name: openflight-rust-core |
| 136 | + fail_ci_if_error: true |
| 137 | + |
| 138 | + - name: Upload coverage to Codecov (advisory) |
| 139 | + if: ${{ always() && github.event_name != 'push' && hashFiles('lcov.info') != '' && steps.codecov-token.outputs.present == 'true' }} |
| 140 | + uses: codecov/codecov-action@v5 |
| 141 | + with: |
| 142 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 143 | + files: lcov.info |
| 144 | + flags: rust-core |
| 145 | + name: openflight-rust-core |
| 146 | + fail_ci_if_error: false |
| 147 | + |
| 148 | + - name: Write coverage receipt |
| 149 | + if: always() |
| 150 | + run: | |
| 151 | + mkdir -p target/coverage |
| 152 | + python3 - <<'PY' |
| 153 | + import json |
| 154 | + import pathlib |
| 155 | +
|
| 156 | + receipt = { |
| 157 | + "schema_version": 1, |
| 158 | + "repo": "OpenFlight", |
| 159 | + "lane": "coverage", |
| 160 | + "flag": "rust-core", |
| 161 | + "workflow": "Coverage", |
| 162 | + "scope": "portable-core-control-plane", |
| 163 | + "artifacts": { |
| 164 | + "coverage_json": pathlib.Path("coverage.json").exists(), |
| 165 | + "coverage_text": pathlib.Path("coverage.txt").exists(), |
| 166 | + "lcov": pathlib.Path("lcov.info").exists(), |
| 167 | + }, |
| 168 | + "claim_boundary": [ |
| 169 | + "execution_surface_only", |
| 170 | + "not_realtime_deadline_proof", |
| 171 | + "not_hardware_correctness", |
| 172 | + "not_simulator_adapter_correctness", |
| 173 | + "not_force_feedback_safety", |
| 174 | + "not_hil_readiness", |
| 175 | + "not_bdd_completeness", |
| 176 | + "not_fuzz_robustness", |
| 177 | + "not_release_readiness" |
| 178 | + ], |
| 179 | + } |
| 180 | +
|
| 181 | + pathlib.Path("target/coverage/coverage-receipt.json").write_text( |
| 182 | + json.dumps(receipt, indent=2) + "\n", |
| 183 | + encoding="utf-8", |
| 184 | + ) |
| 185 | + PY |
| 186 | +
|
| 187 | + - name: Upload coverage artifacts |
| 188 | + if: always() |
| 189 | + uses: actions/upload-artifact@v4 |
| 190 | + with: |
| 191 | + name: coverage-report |
| 192 | + path: | |
| 193 | + coverage.json |
| 194 | + coverage.txt |
| 195 | + lcov.info |
| 196 | + target/coverage/coverage-receipt.json |
| 197 | + retention-days: 14 |
| 198 | + |
| 199 | + - name: Summarize coverage artifacts |
| 200 | + if: always() |
| 201 | + run: | |
| 202 | + { |
| 203 | + echo "## Coverage" |
| 204 | + echo "" |
| 205 | + echo "| Artifact | Present |" |
| 206 | + echo "| --- | ---: |" |
| 207 | + echo "| coverage.json | $([ -s coverage.json ] && echo yes || echo no) |" |
| 208 | + echo "| coverage.txt | $([ -s coverage.txt ] && echo yes || echo no) |" |
| 209 | + echo "| lcov.info | $([ -s lcov.info ] && echo yes || echo no) |" |
| 210 | + echo "| coverage-receipt.json | $([ -s target/coverage/coverage-receipt.json ] && echo yes || echo no) |" |
| 211 | + echo "" |
| 212 | + echo "Codecov flag: \`rust-core\`" |
| 213 | + echo "Scope: portable core/control-plane crates" |
| 214 | + } >> "$GITHUB_STEP_SUMMARY" |
0 commit comments