chore: updates coverage GH action to compare coverage against base branch #136
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Coverage Check | |
| on: | |
| pull_request: | |
| env: | |
| COVERAGE_SENSITIVITY_PERCENT: 1 | |
| MAINNET_RPC: ${{ secrets.MAINNET_RPC }} | |
| SEPOLIA_RPC: ${{ secrets.SEPOLIA_RPC }} | |
| jobs: | |
| base-coverage: | |
| name: Generate base coverage | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| ref: ${{ github.event.pull_request.base.sha }} | |
| - name: Install Foundry | |
| uses: foundry-rs/foundry-toolchain@v1 | |
| with: | |
| version: stable | |
| - name: Use Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20.x | |
| cache: "yarn" | |
| - name: Install dependencies | |
| run: yarn --frozen-lockfile | |
| - name: Restore base coverage cache | |
| id: cache-base | |
| uses: actions/cache@v4 | |
| with: | |
| path: .coverage-base/lcov.info | |
| key: coverage-base-${{ github.event.pull_request.base.sha }} | |
| - name: Run base branch coverage | |
| if: steps.cache-base.outputs.cache-hit != 'true' | |
| run: yarn coverage | |
| - name: Prepare cached base lcov | |
| if: steps.cache-base.outputs.cache-hit != 'true' | |
| run: | | |
| mkdir -p .coverage-base | |
| cp lcov.info .coverage-base/lcov.info | |
| - name: Copy artifact file | |
| run: cp .coverage-base/lcov.info base-lcov.info | |
| - name: Upload base lcov as artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: base-lcov | |
| path: base-lcov.info | |
| check-coverage: | |
| name: Check PR coverage | |
| runs-on: ubuntu-latest | |
| needs: base-coverage | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Install Foundry | |
| uses: foundry-rs/foundry-toolchain@v1 | |
| with: | |
| version: stable | |
| - name: Use Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20.x | |
| cache: "yarn" | |
| - name: Install dependencies | |
| run: yarn --frozen-lockfile | |
| - name: Download base lcov artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: base-lcov | |
| path: . | |
| - name: Run current branch coverage | |
| run: yarn coverage | |
| - name: Setup LCOV | |
| uses: hrishikesh-kadam/setup-lcov@v1 | |
| # Updates the comment on every PR push | |
| - name: Create a comment on the PR with the current branch coverage | |
| id: new-coverage | |
| if: hashFiles('lcov.info') != '' | |
| uses: zgosalvez/github-actions-report-lcov@v4 | |
| with: | |
| coverage-files: lcov.info | |
| github-token: ${{ github.token }} | |
| update-comment: true | |
| - name: Compare previous coverage (against base branch) | |
| run: | | |
| if [ -f .coverage-base/lcov.info ]; then | |
| old=$(lcov --summary .coverage-base/lcov.info 2>/dev/null | awk '/lines\.+:/ {print $2}' | tr -d '%') | |
| else | |
| old=0 | |
| fi | |
| head="${{ steps.new-coverage.outputs.total-coverage }}" | |
| [ -z "$head" ] && head=0 | |
| new=$(awk -v a="$head" -v b="${{ env.COVERAGE_SENSITIVITY_PERCENT }}" 'BEGIN{printf "%.2f", a+b}') | |
| if awk "BEGIN {exit !($new < $old)}"; then | |
| echo "Coverage decreased from $old to $new"; exit 1 | |
| fi |