---
name: Coverage
on:
workflow_call:
secrets:
CODECOV_TOKEN:
required: true
jobs:
coverage:
name: Coverage
runs-on: ubuntu-latest
services:
postgres:
image: postgres:18
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
POSTGRES_HOST_AUTH_METHOD: trust
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 5s
--health-timeout 5s
--health-retries 10
--health-start-period 10s
ports:
- 5432:5432
steps:
- uses: actions/checkout@v5
- name: Cache Rust toolchain and dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-coverage-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-coverage-
${{ runner.os }}-cargo-
- uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools-preview
- name: Wait for PostgreSQL
run: |
timeout 30 bash -c 'until pg_isready -h localhost -p 5432 -U postgres; do sleep 1; done'
echo "PostgreSQL is ready!"
- name: Run tests
run: cargo test --verbose -- --nocapture
env:
PG_EXPORTER_DSN: postgresql://postgres:postgres@localhost:5432/postgres
RUST_BACKTRACE: full
CARGO_INCREMENTAL: 0
LLVM_PROFILE_FILE: coverage-%p-%m.profraw
RUSTFLAGS: -Cinstrument-coverage -Ccodegen-units=1 -Clink-dead-code -Coverflow-checks=off
RUSTDOCFLAGS: -Cinstrument-coverage -Ccodegen-units=1 -Clink-dead-code -Coverflow-checks=off
- name: Install grcov
run: |
if [[ ! -e ~/.cargo/bin/grcov ]]; then
cargo install grcov
else
echo "grcov already installed"
fi
- name: Run grcov
run: grcov . --binary-path target/debug/ -s . -t lcov --branch --ignore-not-existing
--ignore '../**' --ignore '/*' -o coverage.lcov
- name: Upload to codecov.io
uses: codecov/codecov-action@v5
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
files: coverage.lcov
flags: rust
- name: Coveralls GitHub Action
uses: coverallsapp/github-action@v2