name: CI
on:
push:
branches:
- '**'
tags:
- 'v*'
pull_request:
workflow_dispatch:
permissions:
contents: read
jobs:
build:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- name: Linux
os: ubuntu-latest
artifact: aodv-linux-x86_64
- name: macOS
os: macos-latest
artifact: aodv-macos
- name: Windows
os: windows-latest
artifact: aodv-windows
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- name: Check format
run: cargo fmt --check
- name: Check
run: cargo check --all-targets --all-features
- name: Lint
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Test
run: cargo test --all-targets --all-features
- name: Build release
run: cargo build --release --all-features
- name: Upload release binary
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact }}
path: |
target/release/aodv
target/release/aodv.exe
if-no-files-found: error
coverage:
name: Coverage
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools-preview
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Run coverage tests
run: |
cargo llvm-cov clean --workspace
cargo llvm-cov --all-targets --all-features --no-report
- name: Generate coverage reports
run: |
rm -rf target/llvm-cov
mkdir -p target/llvm-cov
cargo llvm-cov report --html --output-dir target/llvm-cov
cargo llvm-cov report --lcov --output-path target/llvm-cov/lcov.info
cargo llvm-cov report --json --summary-only --output-path target/llvm-cov/summary.json
line="$(jq -r '.data[0].totals.lines' target/llvm-cov/summary.json)"
covered="$(jq -r '.covered' <<<"$line")"
total="$(jq -r '.count' <<<"$line")"
percent="$(jq -r '.percent' <<<"$line")"
{
echo "### Test coverage"
echo
echo "| Metric | Covered | Total | Percent |"
echo "| --- | ---: | ---: | ---: |"
printf '| Lines | %s | %s | %.2f%% |\n' "$covered" "$total" "$percent"
} >> "$GITHUB_STEP_SUMMARY"
- name: Upload coverage reports
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: |
target/llvm-cov/html
target/llvm-cov/lcov.info
target/llvm-cov/summary.json
if-no-files-found: error