feat(coprocessor): add local coverage tooling and pre-push hook #7272
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: coprocessor-cargo-test | |
| on: | |
| pull_request: | |
| permissions: {} | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.head_ref }} | |
| cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} | |
| jobs: | |
| check-changes: | |
| name: coprocessor-cargo-test/check-changes | |
| permissions: | |
| actions: 'read' # Required to read workflow run information | |
| contents: 'read' # Required to checkout repository code | |
| pull-requests: 'read' # Required to read pull request information | |
| runs-on: ubuntu-latest | |
| outputs: | |
| changes-rust-files: ${{ steps.filter.outputs.rust-files }} | |
| steps: | |
| - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| with: | |
| persist-credentials: 'false' | |
| - uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 | |
| id: filter | |
| with: | |
| filters: | | |
| rust-files: | |
| - .github/workflows/coprocessor-cargo-tests.yml | |
| - coprocessor/fhevm-engine/** | |
| - coprocessor/proto/** | |
| cargo-tests: | |
| name: coprocessor-cargo-test/cargo-tests (bpr) | |
| needs: check-changes | |
| if: ${{ needs.check-changes.outputs.changes-rust-files == 'true' }} | |
| permissions: | |
| 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 | |
| runs-on: large_ubuntu_16 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| with: | |
| persist-credentials: 'false' | |
| lfs: true | |
| - name: Checkout LFS objects | |
| run: git lfs checkout | |
| - name: Setup Rust | |
| uses: dtolnay/rust-toolchain@a54c7afa936fefeb4456b2dd8068152669aa8203 | |
| with: | |
| toolchain: "1.91.1" | |
| components: llvm-tools-preview | |
| - name: Install cargo-llvm-cov | |
| uses: taiki-e/install-action@a37010ded18ff788be4440302bd6830b1ae50d8b # v2.68.25 | |
| with: | |
| tool: cargo-llvm-cov | |
| - name: Install cargo dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y protobuf-compiler && \ | |
| cargo install sqlx-cli --version 0.7.2 --no-default-features --features postgres --locked | |
| - name: Install foundry | |
| uses: foundry-rs/foundry-toolchain@de808b1eea699e761c404bda44ba8f21aba30b2c | |
| - name: Cache cargo | |
| uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| target | |
| 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 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Login to GitHub Chainguard Registry | |
| uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 | |
| with: | |
| registry: cgr.dev | |
| username: ${{ secrets.CGR_USERNAME }} | |
| password: ${{ secrets.CGR_PASSWORD }} | |
| - name: Init database | |
| run: make init_db | |
| working-directory: coprocessor/fhevm-engine/tfhe-worker | |
| - name: Use Node.js | |
| uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 | |
| with: | |
| node-version: 20.x | |
| - name: Start localstack | |
| run: | | |
| docker run --rm -d -p 4566:4566 --name localstack localstack/localstack:latest | |
| - 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 llvm-cov --no-report --workspace --profile coverage -- --test-threads=1 | |
| working-directory: coprocessor/fhevm-engine | |
| - name: Generate coverage report | |
| if: always() | |
| 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 |