|
| 1 | +name: Code Coverage |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + web-prover-circuits-cache-key: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + outputs: |
| 10 | + coverage-report: |
| 11 | + description: "Path to the coverage report" |
| 12 | + value: ${{ jobs.coverage.outputs.coverage-report }} |
| 13 | + |
| 14 | +jobs: |
| 15 | + coverage: |
| 16 | + name: Generate code coverage |
| 17 | + runs-on: ubuntu-latest |
| 18 | + permissions: |
| 19 | + contents: read |
| 20 | + checks: write |
| 21 | + pull-requests: write # Needed for coverage comments |
| 22 | + outputs: |
| 23 | + coverage-report: ${{ steps.upload-coverage.outputs.artifact-url }} |
| 24 | + |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + fetch-depth: 2 # Needed for coverage comparison in PRs |
| 29 | + |
| 30 | + - uses: ./.github/actions/setup-rust-ubuntu |
| 31 | + with: |
| 32 | + rust-cache-key: coverage |
| 33 | + |
| 34 | + - name: Fetch web-prover-circuits cache |
| 35 | + uses: actions/cache/restore@v4 |
| 36 | + with: |
| 37 | + path: proofs/web_proof_circuits |
| 38 | + key: ${{ inputs.web-prover-circuits-cache-key }} |
| 39 | + fail-on-error: true |
| 40 | + |
| 41 | + - name: Install tarpaulin |
| 42 | + run: cargo install cargo-tarpaulin --version "^0.27" # Pin version for stability |
| 43 | + |
| 44 | + - name: Run tarpaulin |
| 45 | + id: run-tarpaulin |
| 46 | + run: | |
| 47 | + cargo tarpaulin --workspace \ |
| 48 | + --exclude client_wasm \ |
| 49 | + --timeout 360 \ |
| 50 | + --out Xml \ |
| 51 | + --out Html \ |
| 52 | + --output-dir coverage \ |
| 53 | + --exclude-files 'tests/*' \ |
| 54 | + --fail-under 70 # Fail if coverage drops below 70% |
| 55 | +
|
| 56 | + - name: Upload coverage reports to Codecov |
| 57 | + uses: codecov/codecov-action@v3 |
| 58 | + with: |
| 59 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 60 | + files: ./coverage/cobertura.xml |
| 61 | + fail_ci_if_error: true # Fail if upload fails |
| 62 | + verbose: true # Better debugging |
| 63 | + |
| 64 | + - name: Upload coverage report |
| 65 | + id: upload-coverage |
| 66 | + uses: actions/upload-artifact@v4 |
| 67 | + with: |
| 68 | + name: coverage-report |
| 69 | + path: coverage/ |
| 70 | + retention-days: 7 |
| 71 | + if-no-files-found: error # Fail if no coverage files generated |
| 72 | + |
| 73 | + - name: Check coverage report exists |
| 74 | + run: | |
| 75 | + if [ ! -f coverage/tarpaulin-report.html ]; then |
| 76 | + echo "Coverage report not generated" |
| 77 | + exit 1 |
| 78 | + fi |
0 commit comments