Skip to content

Add test for get_player_matches all lifecycle states #415

Add test for get_player_matches all lifecycle states

Add test for get_player_matches all lifecycle states #415

Workflow file for this run

name: Code Coverage
on:
push:
branches: [main, master]
paths:
- 'contracts/escrow/**'
- '.github/workflows/coverage.yml'
pull_request:
branches: [main, master]
paths:
- 'contracts/escrow/**'
- '.github/workflows/coverage.yml'
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
coverage:
name: Code Coverage Report
if: github.base_ref == 'main' || github.base_ref == 'master' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v5
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- name: Install tarpaulin
run: cargo install cargo-tarpaulin
- name: Cache cargo
uses: actions/cache@v5
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
- name: Run coverage
id: coverage
run: |
cd contracts/escrow
set +e
# Threshold aligned with COVERAGE_NOTE.md: 87% minimum, 90% goal.
# Current coverage: 87.42%. Pre-existing gap not caused by new PRs.
# TODO: Restore --fail-under 90 once overall coverage reaches goal.
cargo tarpaulin \
--lib \
--out Html \
--out Stdout \
--output-dir ../../coverage \
--timeout 300 \
--exclude-files tests/* \
--exclude-files helpers.rs \
--exclude-files 'contracts/oracle/*' \
--exclude-files 'services/event-indexer/*' \
--fail-under 87 \
-- --test-threads 1 | tee coverage-output.log
TARPAULIN_EXIT=${PIPESTATUS[0]}
set -e
# tarpaulin's Html report has no extractable aggregate score in this
# version (0.37.2) -- the real number only appears on its Stdout,
# e.g. "76.26% coverage, 1754/2300 lines covered".
COVERAGE_LINE=$(grep -oP '[0-9.]+(?=% coverage)' coverage-output.log | tail -1)
echo "coverage_percent=${COVERAGE_LINE}" >> "$GITHUB_OUTPUT"
echo "Line Coverage: ${COVERAGE_LINE}%"
if [[ "$TARPAULIN_EXIT" -ne 0 ]]; then
echo "❌ Line coverage ${COVERAGE_LINE}% is below minimum threshold of 87%"
echo "coverage_status=below_threshold" >> "$GITHUB_OUTPUT"
else
echo "✅ Line coverage ${COVERAGE_LINE}% meets 90% goal"
echo "coverage_status=ok" >> "$GITHUB_OUTPUT"
fi
- name: Upload coverage as artifact
if: always()
uses: actions/upload-artifact@v5
with:
name: coverage-report
# --output-dir ../../coverage resolves to repo root coverage/ directory
path: coverage/
retention-days: 30
- name: Comment coverage on PR
if: github.event_name == 'pull_request'
# PRs from forks get a read-only GITHUB_TOKEN, so this call to
# createComment reliably 403s there ("Resource not accessible by
# integration"). That's a missing nice-to-have, not a coverage
# failure -- the actual gate is the separate "Fail if coverage
# below threshold" step below, which doesn't depend on this.
continue-on-error: true
uses: actions/github-script@v7
with:
script: |
const coverage = '${{ steps.coverage.outputs.coverage_percent }}' || 'Unknown';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `📊 **Code Coverage Report**\n\nLine Coverage: **${coverage}%**\n\nMinimum Required: **87%**\n\n[View detailed coverage report](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})`
});
- name: Fail if coverage below threshold
if: steps.coverage.outputs.coverage_status == 'below_threshold'
run: |
echo "::error::Line coverage ${{ steps.coverage.outputs.coverage_percent }}% is below the required 87% threshold."
exit 1
- name: Warn if coverage below goal
if: steps.coverage.outputs.coverage_status == 'below_goal'
run: |
echo "::warning::Line coverage ${{ steps.coverage.outputs.coverage_percent }}% is below the 90% goal but meets the temporary 85% threshold. Project-wide coverage improvement needed."