Skip to content

chore(deps): weekly cargo update #84

chore(deps): weekly cargo update

chore(deps): weekly cargo update #84

Workflow file for this run

name: coverage
on:
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
jobs:
coverage:
name: coverage check
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools-preview
- uses: taiki-e/install-action@cargo-llvm-cov
- uses: taiki-e/install-action@nextest
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: Get base branch coverage
env:
RPC_URL: ${{ secrets.RPC_URL }}
WS_RPC_URL: ${{ secrets.WS_RPC_URL }}
run: |
git checkout ${{ github.base_ref }}
make test-cov-json
BASE_COV=$(jq '.data[0].totals.lines.percent' coverage.json)
echo "BASE_COVERAGE=$BASE_COV" >> $GITHUB_ENV
rm coverage.json
git checkout -
- name: Get PR branch coverage
env:
RPC_URL: ${{ secrets.RPC_URL }}
WS_RPC_URL: ${{ secrets.WS_RPC_URL }}
run: |
make test-cov-json
PR_COV=$(jq '.data[0].totals.lines.percent' coverage.json)
echo "PR_COVERAGE=$PR_COV" >> $GITHUB_ENV
- name: Compare coverage
id: coverage
run: |
echo "Base branch coverage: $BASE_COVERAGE%"
echo "PR branch coverage: $PR_COVERAGE%"
DIFF=$(echo "$PR_COVERAGE - $BASE_COVERAGE" | bc)
echo "Coverage difference: $DIFF%"
echo "COVERAGE_DIFF=$DIFF" >> $GITHUB_ENV
# Check if coverage dropped by more than 2%
THRESHOLD=-2
if (( $(echo "$DIFF < $THRESHOLD" | bc -l) )); then
echo "::error::Coverage dropped by more than 2% (dropped by ${DIFF}%)"
echo "COVERAGE_FAILED=true" >> $GITHUB_ENV
else
echo "COVERAGE_FAILED=false" >> $GITHUB_ENV
fi
echo "Coverage check passed"
- name: Comment on PR
uses: actions/github-script@v7
with:
script: |
const baseCov = parseFloat(process.env.BASE_COVERAGE).toFixed(2);
const prCov = parseFloat(process.env.PR_COVERAGE).toFixed(2);
const diff = parseFloat(process.env.COVERAGE_DIFF).toFixed(2);
const failed = process.env.COVERAGE_FAILED === 'true';
const icon = diff >= 0 ? ':white_check_mark:' : (failed ? ':x:' : ':warning:');
const sign = diff >= 0 ? '+' : '';
const body = `## ${icon} Coverage Report for ${context.sha}
| Metric | Value |
|--------|-------|
| Base branch | ${baseCov}% |
| PR branch | ${prCov}% |
| Diff | ${sign}${diff}% |
${failed ? '**Coverage dropped by more than 2%!**' : ''}`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' && comment.body.includes('Coverage Report')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
}
- name: Fail if coverage dropped
if: env.COVERAGE_FAILED == 'true'
run: exit 1