name: CI
on:
push:
branches: [main]
pull_request:
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: -D warnings
jobs:
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: rustup toolchain install stable --profile minimal --component rustfmt
- run: cargo fmt --all --check
clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: rustup toolchain install stable --profile minimal --component clippy
- uses: Swatinem/rust-cache@v2
- run: cargo clippy --all-targets --all-features
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: rustup toolchain install stable --profile minimal
- uses: Swatinem/rust-cache@v2
- run: cargo test --all-features
- run: cargo test --no-default-features
coverage:
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
continue-on-error: true
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- run: rustup toolchain install stable --profile minimal --component llvm-tools-preview
- uses: Swatinem/rust-cache@v2
- uses: taiki-e/install-action@cargo-llvm-cov
- run: cargo llvm-cov --workspace --all-features --no-report
- run: cargo llvm-cov report --summary-only --json --output-path coverage.json
- run: cargo llvm-cov report --codecov --output-path codecov.json
- uses: codecov/codecov-action@v5
with:
files: codecov.json
fail_ci_if_error: false
- name: Publish badge JSON to badges branch
run: |
pct=$(jq -r '.data[0].totals.lines.percent' coverage.json)
msg=$(printf '%.1f%%' "$pct")
color=$(awk -v p="$pct" 'BEGIN{print (p<60)?"red":(p<80)?"yellow":"brightgreen"}')
jq -n --arg m "$msg" --arg c "$color" \
'{schemaVersion:1,label:"coverage",message:$m,color:$c}' > badge.json
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Single-file branch built from plumbing; history is disposable, force-push.
blob=$(git hash-object -w badge.json)
tree=$(printf '100644 blob %s\tbadge.json\n' "$blob" | git mktree)
commit=$(git commit-tree "$tree" -m "coverage badge: $msg ($GITHUB_SHA)")
git push -f origin "$commit:refs/heads/badges"
doc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: rustup toolchain install stable --profile minimal
- uses: Swatinem/rust-cache@v2
- run: cargo doc --no-deps --all-features
env:
RUSTDOCFLAGS: -D warnings --html-in-header doc/katex-header.html