name: Tests
on:
pull_request:
branches:
- main
jobs:
generate:
name: Generate
runs-on: ubuntu-latest
permissions:
contents: write
env:
RUSTFLAGS: "-Cinstrument-coverage"
LLVM_PROFILE_FILE: "geohasher-%p-%m.profraw"
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools-preview
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install grcov
run: |
if ! command -v grcov &> /dev/null; then
cargo install grcov
fi
- run: cargo build
- run: cargo test
- name: Generate coverage report
run: |
mkdir -p coverage
grcov . --binary-path ./target/debug/ -s . -t lcov --branch --ignore-not-existing -o ./coverage/
if [ -f ./coverage/lcov ]; then
echo "Coverage file generated successfully"
echo "coverage_report=$(base64 -w 0 ./coverage/lcov)" >> $GITHUB_OUTPUT
else
echo "Error: lcov file not generated"
exit 1
fi
- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v4.2.0
with:
file: ./coverage/lcov
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}