name: Test
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
test:
name: Test on ${{ matrix.rust }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rust: [stable, beta, nightly]
steps:
- uses: actions/checkout@v4
- name: Install Rust (${{ matrix.rust }})
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
components: llvm-tools-preview
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Run Tests (no-std)
run: cargo test --no-default-features --features no-std-unix-debug,html-entities -- --nocapture --test-threads=1
env:
RUST_BACKTRACE: 1
- name: Run Tests (std)
run: cargo test -- --nocapture --test-threads=1
env:
RUST_BACKTRACE: 1
- name: Report Coverage to Summary
if: matrix.rust == 'nightly'
id: coverage_step
run: |
echo "## Code Coverage Report" >> $GITHUB_STEP_SUMMARY
RAW_OUTPUT=$(cargo llvm-cov --branch --ignore-filename-regex='test.rs|gen.rs' --workspace)
TOTAL_COV=$(echo "$RAW_OUTPUT" | grep "TOTAL" | awk '{print $10}')
echo "total_coverage=$TOTAL_COV" >> $GITHUB_OUTPUT
echo "${RAW_OUTPUT}" | sed -E 's/[[:space:]]{2,}/ /g' | awk '
BEGIN { FS = " "; OFS = " | "; }
/^-+$/ { next }
{
gsub(/^ +| +$/, "");
line = "| ";
for (i = 1; i <= NF; i++) {
gsub(/^ +| +$/, "", $i);
line = line $i (i == NF ? " |" : " | ");
}
print line;
}
NR == 1 {
sep = "|";
for (i = 1; i <= NF; i++) sep = sep " --- |";
print sep;
}
' >> $GITHUB_STEP_SUMMARY
- name: Update Coverage Badge
if: matrix.rust == 'nightly' && github.ref == 'refs/heads/main'
env:
GIST_ID: 3c122e76a86b680d04700e14b3161f04
COVERAGE: ${{ steps.coverage_step.outputs.total_coverage }}
run: |
echo "Current Coverage: $COVERAGE"
JSON_DATA=$(jq -n --arg cov "$COVERAGE" '{
schemaVersion: 1,
label: "coverage",
message: $cov,
color: (if ($cov | rtrimstr("%") | tonumber) > 80 then "brightgreen" else "orange" end)
}')
curl -L \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GIST_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/gists/$GIST_ID \
-d "{\"files\":{\"rushdown-coverage.json\":{\"content\":$(echo $JSON_DATA | jq -R .)}}}"