Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Code Coverage (Nightly)

on:
schedule:
# Run at 2:00 AM UTC every day
- cron: '0 2 * * *'
workflow_dispatch:
inputs:
coverage_type:
description: 'Type of coverage to run'
required: false
default: 'comprehensive'
type: choice
options:
- 'basic'
- 'comprehensive'

env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: full
OPENMINA_PANIC_ON_BUG: true

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
code-coverage:
runs-on: ubuntu-22.04

steps:
- name: Git checkout
uses: actions/checkout@v4

- name: Setup build dependencies
run: |
sudo apt update
sudo apt install -y protobuf-compiler

- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, llvm-tools-preview
toolchain: 1.84

- name: Setup Rust Cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: "coverage-v0"

- name: Install grcov
run: |
cargo install grcov

- name: Determine coverage type
id: coverage-type
run: |
if [ "${{ github.event.inputs.coverage_type }}" = "basic" ]; then
echo "target=test-coverage" >> $GITHUB_OUTPUT
echo "type=basic" >> $GITHUB_OUTPUT
else
echo "target=test-with-coverage" >> $GITHUB_OUTPUT
echo "type=comprehensive" >> $GITHUB_OUTPUT
fi

- name: Run tests with coverage
run: |
make ${{ steps.coverage-type.outputs.target }}

- name: Generate LCOV report
run: |
make coverage-lcov

- name: Generate HTML report
run: |
make coverage-report

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: target/coverage/lcov.info
flags: ${{ steps.coverage-type.outputs.type }}
name: openmina-coverage
fail_ci_if_error: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

- name: Upload coverage reports as artifacts
uses: actions/upload-artifact@v4
with:
name: coverage-reports-${{ steps.coverage-type.outputs.type }}
path: |
target/coverage/lcov.info
target/coverage/html/
retention-days: 30

- name: Coverage Summary
run: |
echo "## Coverage Summary" >> $GITHUB_STEP_SUMMARY
echo "Coverage report type: ${{ steps.coverage-type.outputs.type }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Coverage Report Files" >> $GITHUB_STEP_SUMMARY
echo "- LCOV: \`target/coverage/lcov.info\`" >> $GITHUB_STEP_SUMMARY
echo "- HTML Report: \`target/coverage/html/index.html\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Coverage Summary" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
make coverage-summary >> $GITHUB_STEP_SUMMARY || echo "Coverage summary generation failed" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ pkg/
cargo-build-test.json
tests.tsv

# Coverage
target/coverage/

# Generated API docs should not be committed
website/static/api-docs/

Expand Down
102 changes: 102 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,108 @@ test-release: ## Run tests in release mode
test-vrf: ## Run VRF tests, requires nightly Rust
@cd vrf && cargo +nightly test --release -- -Z unstable-options --report-time

# Coverage targets

.PHONY: setup-coverage-tools
setup-coverage-tools: ## Install tools required for code coverage
@echo "Installing coverage tools..."
@rustup component add llvm-tools-preview
@cargo install grcov || echo "grcov already installed"
@echo "Coverage tools installed successfully"

.PHONY: test-coverage
test-coverage: ## Run tests with code coverage (basic, fast)
@echo "Running tests with code coverage..."
@mkdir -p target/coverage
@CARGO_INCREMENTAL=0 \
RUSTFLAGS="-Cinstrument-coverage" \
LLVM_PROFILE_FILE="target/coverage/cargo-test-%p-%m.profraw" \
cargo test --workspace \
--exclude fuzzer \
--exclude heartbeats-processor \
--lib \
--tests
@echo "Coverage data collected in target/coverage/"

.PHONY: test-with-coverage
test-with-coverage: ## Run comprehensive tests with code coverage (slower, more complete)
@echo "Running comprehensive tests with code coverage..."
@mkdir -p target/coverage
@CARGO_INCREMENTAL=0 \
RUSTFLAGS="-Cinstrument-coverage" \
LLVM_PROFILE_FILE="target/coverage/cargo-test-%p-%m.profraw" \
cargo test --workspace \
--exclude fuzzer \
--exclude heartbeats-processor \
--lib \
--tests \
--bins
@echo "Coverage data collected in target/coverage/"

.PHONY: coverage-report
coverage-report: ## Generate HTML coverage report from collected data
@echo "Generating HTML coverage report..."
@mkdir -p target/coverage/html
@grcov target/coverage \
--binary-path target/debug/deps/ \
--source-dir . \
--output-types html \
--branch \
--ignore-not-existing \
--ignore "/*" \
--ignore "target/*" \
--ignore "tests/*" \
--ignore "**/tests.rs" \
--ignore "**/test_*.rs" \
--ignore "**/bench_*.rs" \
--ignore "**/benches/*" \
--output-path target/coverage/html
@echo "HTML coverage report generated in target/coverage/html/"
@echo "Open target/coverage/html/index.html in your browser to view the report"

.PHONY: coverage-lcov
coverage-lcov: ## Generate LCOV coverage report for CI/codecov
@echo "Generating LCOV coverage report..."
@mkdir -p target/coverage
@grcov target/coverage \
--binary-path target/debug/deps/ \
--source-dir . \
--output-types lcov \
--branch \
--ignore-not-existing \
--ignore "/*" \
--ignore "target/*" \
--ignore "tests/*" \
--ignore "**/tests.rs" \
--ignore "**/test_*.rs" \
--ignore "**/bench_*.rs" \
--ignore "**/benches/*" \
--output-path target/coverage/lcov.info
@echo "LCOV coverage report generated at target/coverage/lcov.info"

.PHONY: coverage-clean
coverage-clean: ## Clean coverage data and reports
@echo "Cleaning coverage data..."
@rm -rf target/coverage
@echo "Coverage data cleaned"

.PHONY: coverage-summary
coverage-summary: ## Display coverage summary from collected data
@echo "Generating coverage summary..."
@grcov target/coverage \
--binary-path target/debug/deps/ \
--source-dir . \
--output-types markdown \
--branch \
--ignore-not-existing \
--ignore "/*" \
--ignore "target/*" \
--ignore "tests/*" \
--ignore "**/tests.rs" \
--ignore "**/test_*.rs" \
--ignore "**/bench_*.rs" \
--ignore "**/benches/*"

# Docker build targets

.PHONY: docker-build-all
Expand Down
51 changes: 51 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
codecov:
require_ci_to_pass: yes
notify:
after_n_builds: 1

coverage:
precision: 2
round: down
range: "70...95"

status:
project:
default:
target: auto
threshold: 1%
if_not_found: success
if_ci_failed: error
patch:
default:
target: auto
threshold: 1%
if_not_found: success
if_ci_failed: error

parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: no
macro: no

ignore:
- "**/*test*.rs"
- "**/tests.rs"
- "**/benches/**"
- "**/target/**"
- "**/fuzzer/**"
- "**/tools/fuzzing/**"
- "**/examples/**"
- "**/node/testing/**"

comment:
layout: "reach,diff,flags,tree"
behavior: default
require_changes: no
require_base: no
require_head: yes

github_checks:
annotations: true
Loading
Loading