Skip to content
Merged
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
102 changes: 96 additions & 6 deletions .github/workflows/coprocessor-cargo-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
contents: 'read' # Required to checkout repository code
checks: 'write' # Required to create GitHub checks for test results
packages: 'read' # Required to read GitHub packages/container registry
pull-requests: 'write' # Required to post coverage comment on PR
runs-on: large_ubuntu_16
steps:
- name: Checkout code
Expand All @@ -50,10 +51,16 @@ jobs:
- name: Checkout LFS objects
run: git lfs checkout

- name: Setup Rust toolchain file
run: cp coprocessor/fhevm-engine/rust-toolchain.toml .

- name: Setup Rust
uses: dtolnay/rust-toolchain@a54c7afa936fefeb4456b2dd8068152669aa8203
uses: dsherret/rust-toolchain-file@3551321aa44dd44a0393eb3b6bdfbc5d25ecf621 # v1

- name: Install cargo-llvm-cov
uses: taiki-e/install-action@a37010ded18ff788be4440302bd6830b1ae50d8b # v2.68.25
with:
toolchain: stable
tool: cargo-llvm-cov

- name: Install cargo dependencies
run: |
Expand All @@ -71,8 +78,8 @@ jobs:
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
key: ${{ runner.os }}-cargo-coverage-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-coverage-

- name: Login to GitHub Container Registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
Expand Down Expand Up @@ -101,7 +108,90 @@ jobs:
run: |
docker run --rm -d -p 4566:4566 --name localstack localstack/localstack:latest

- name: Run tests
- name: Clean previous coverage data
run: cargo llvm-cov clean --workspace --profile coverage
working-directory: coprocessor/fhevm-engine

- name: Run tests with coverage
run: |
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/coprocessor TEST_GLOBAL_LOCALSTACK=1 cargo test --release -- --test-threads=1
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/coprocessor \
TEST_GLOBAL_LOCALSTACK=1 \
cargo llvm-cov --no-report --workspace --profile coverage -- --test-threads=1
working-directory: coprocessor/fhevm-engine

- name: Generate coverage report
if: ${{ !cancelled() }}
run: |
if cargo llvm-cov report --profile coverage > /tmp/cov-report.txt 2>&1; then
REPORT=$(cat /tmp/cov-report.txt)
else
echo "cargo llvm-cov report failed:"
cat /tmp/cov-report.txt
REPORT=""
fi
{
echo '## Coverage: coprocessor/fhevm-engine'
if [ -n "$REPORT" ]; then
echo '```'
echo "$REPORT"
echo '```'
else
echo '*No coverage data available (tests may have failed before producing profiling data).*'
fi
} >> "$GITHUB_STEP_SUMMARY"
echo "$REPORT"
working-directory: coprocessor/fhevm-engine

- name: Export LCOV coverage data
if: ${{ !cancelled() }}
run: cargo llvm-cov report --lcov --profile coverage --output-path /tmp/lcov.info || true
working-directory: coprocessor/fhevm-engine

- name: Diff coverage of changed lines
if: ${{ !cancelled() }}
id: diff-cov
env:
BASE_REF: ${{ github.base_ref }}
run: |
if [ ! -f /tmp/lcov.info ]; then
echo "diff_pct=N/A" >> "$GITHUB_OUTPUT"
exit 0
fi
pip install --quiet diff-cover
git fetch --unshallow origin
git fetch origin "${BASE_REF}:refs/remotes/origin/${BASE_REF}"
diff-cover /tmp/lcov.info \
--compare-branch="origin/${BASE_REF}" \
--diff-range-notation='...' \
--format "json:/tmp/diff-cover.json,markdown:/tmp/diff-cover-report.md" \
--fail-under 0 || true
if [ -f /tmp/diff-cover.json ]; then
DIFF_PCT=$(python3 -c "import json; d=json.load(open('/tmp/diff-cover.json')); n=d.get('total_num_lines',0); print('N/A') if n==0 else print(f\"{d['total_percent_covered']:.1f}%\")" 2>/dev/null || echo "N/A")
else
DIFF_PCT="N/A"
fi
echo "diff_pct=${DIFF_PCT}" >> "$GITHUB_OUTPUT"

- name: Build diff coverage comment
if: ${{ !cancelled() }}
env:
DIFF_PCT: ${{ steps.diff-cov.outputs.diff_pct }}
run: |
{
echo '### Changed Lines Coverage'
echo "Coverage of added/modified lines: **${DIFF_PCT}**"
echo ''
if [ -f /tmp/diff-cover-report.md ]; then
echo '<details><summary>Per-file breakdown</summary>'
echo ''
cat /tmp/diff-cover-report.md
echo ''
echo '</details>'
fi
} | tee -a "$GITHUB_STEP_SUMMARY" > /tmp/coverage-comment.md

- name: Post coverage comment on PR
if: ${{ !cancelled() && github.event.pull_request.head.repo.full_name == github.repository }}
uses: marocchino/sticky-pull-request-comment@773744901bac0e8cbb5a0dc842800d45e9b2b405 # v2.9.4
with:
path: /tmp/coverage-comment.md
7 changes: 7 additions & 0 deletions coprocessor/fhevm-engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,10 @@ inherits = "release"
opt-level = 1
lto = false
codegen-units = 16

[profile.coverage]
inherits = "release"
opt-level = 1
lto = false
debug = 1
codegen-units = 16
1 change: 1 addition & 0 deletions coprocessor/fhevm-engine/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[toolchain]
channel = "1.91.1"
components = ["llvm-tools-preview"]
Loading