Skip to content

fix NO_COLOR handling #3

fix NO_COLOR handling

fix NO_COLOR handling #3

Workflow file for this run

name: Code Coverage
on:
push:
branches: [main]
pull_request:
branches: [main]
env:
CARGO_TERM_COLOR: always
jobs:
coverage:
name: Generate Coverage Report
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-coverage-${{ hashFiles('**/Cargo.lock') }}
- name: Install tarpaulin
run: |
cargo install cargo-tarpaulin || cargo install --force cargo-tarpaulin
- name: Generate coverage report
run: |
cargo tarpaulin \
--verbose \
--all-features \
--workspace \
--timeout 300 \
--out Xml \
--out Html \
--engine llvm
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: ./cobertura.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: true
- name: Archive coverage HTML report
uses: actions/upload-artifact@v3
with:
name: coverage-report
path: tarpaulin-report.html
- name: Check coverage threshold
run: |
COVERAGE=$(grep -oP 'line-rate="\K[^"]+' cobertura.xml | head -1)
COVERAGE_PCT=$(echo "$COVERAGE * 100" | bc)
echo "Coverage: ${COVERAGE_PCT}%"
THRESHOLD=80
if (( $(echo "$COVERAGE_PCT < $THRESHOLD" | bc -l) )); then
echo "Coverage ${COVERAGE_PCT}% is below threshold ${THRESHOLD}%"
exit 1
fi
coverage-summary:
name: Coverage Summary
runs-on: ubuntu-latest
needs: coverage
if: github.event_name == 'pull_request'
steps:
- name: Download coverage report
uses: actions/download-artifact@v3
with:
name: coverage-report
- name: Comment PR with coverage
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs');
const html = fs.readFileSync('tarpaulin-report.html', 'utf8');
const match = html.match(/(\d+\.\d+)% coverage/);
const coverage = match ? match[1] : 'unknown';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `## Coverage Report\n\n📊 Code coverage: **${coverage}%**\n\n[View full report](https://codecov.io/gh/${context.repo.owner}/${context.repo.repo}/pull/${context.issue.number})`
});