@@ -32,18 +32,55 @@ jobs:
3232 - coprocessor/fhevm-engine/**
3333 - coprocessor/proto/**
3434 cargo-tests :
35- name : coprocessor-cargo-test/cargo-tests (bpr)
35+ name : coprocessor-cargo-test/${{ matrix.service }}
3636 needs : check-changes
3737 if : ${{ needs.check-changes.outputs.changes-rust-files == 'true' }}
3838 permissions :
3939 contents : ' read' # Required to checkout repository code
4040 checks : ' write' # Required to create GitHub checks for test results
41- packages : ' read' # Required to read GitHub packages/container registry
42- pull-requests : ' write' # Required to post coverage comment on PR
43- runs-on : large_ubuntu_16
41+ runs-on : ${{ matrix.runner }}
4442 env :
4543 CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER : clang
4644 RUSTFLAGS : " -C link-arg=-fuse-ld=mold"
45+ strategy :
46+ fail-fast : false
47+ matrix :
48+ include :
49+ - service : tfhe-worker
50+ package : tfhe-worker
51+ needs_localstack : false
52+ needs_foundry : false
53+ runner : large_ubuntu_16
54+ - service : sns-worker
55+ package : sns-worker
56+ needs_localstack : true
57+ needs_foundry : false
58+ runner : large_ubuntu_16
59+ - service : zkproof-worker
60+ package : zkproof-worker
61+ needs_localstack : false
62+ needs_foundry : false
63+ runner : large_ubuntu_16
64+ - service : transaction-sender
65+ package : transaction-sender
66+ needs_localstack : true
67+ needs_foundry : true
68+ runner : large_ubuntu_16
69+ - service : gw-listener
70+ package : gw-listener
71+ needs_localstack : false
72+ needs_foundry : true
73+ runner : large_ubuntu_16
74+ - service : host-listener
75+ package : host-listener
76+ needs_localstack : false
77+ needs_foundry : true
78+ runner : large_ubuntu_16
79+ - service : common
80+ package : fhevm-engine-common
81+ needs_localstack : false
82+ needs_foundry : false
83+ runner : ubuntu-latest
4784 steps :
4885 - name : Checkout code
4986 uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
5491 - name : Checkout LFS objects
5592 run : git lfs checkout
5693
57- - name : Login to GitHub Container Registry
58- uses : docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
59- with :
60- registry : ghcr.io
61- username : ${{ github.actor }}
62- password : ${{ secrets.GITHUB_TOKEN }}
63-
64- - name : Login to GitHub Chainguard Registry
65- uses : docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
66- with :
67- registry : cgr.dev
68- username : ${{ secrets.CGR_USERNAME }}
69- password : ${{ secrets.CGR_PASSWORD }}
70-
71- - name : Start database services (background)
72- run : |
73- nohup docker compose up -d --build db-migration > /tmp/db-init.log 2>&1 &
74- working-directory : coprocessor/fhevm-engine/tfhe-worker
75-
7694 - name : Setup Rust toolchain file
7795 run : cp coprocessor/fhevm-engine/rust-toolchain.toml .
7896
@@ -87,10 +105,9 @@ jobs:
87105 - name : Install cargo dependencies
88106 run : |
89107 sudo apt-get update
90- sudo apt-get install -y protobuf-compiler mold clang && \
91- cargo install sqlx-cli --version 0.7.2 --no-default-features --features postgres --locked
92-
108+ sudo apt-get install -y protobuf-compiler mold clang
93109 - name : Install foundry
110+ if : ${{ matrix.needs_foundry }}
94111 uses : foundry-rs/foundry-toolchain@de808b1eea699e761c404bda44ba8f21aba30b2c
95112
96113 - name : Cache cargo
@@ -100,87 +117,98 @@ jobs:
100117 ~/.cargo/registry
101118 ~/.cargo/git
102119 target
103- key : ${{ runner.os }}-cargo-coverage-${{ hashFiles('**/Cargo.lock') }}
104- restore-keys : ${{ runner.os }}-cargo-coverage-
120+ key : ${{ runner.os }}-cargo-coverage-${{ matrix.service }}-${{ hashFiles('**/Cargo.lock') }}
121+ restore-keys : ${{ runner.os }}-cargo-coverage-${{ matrix.service }}-
105122
106123 - name : Use Node.js
107124 uses : actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
108125 with :
109126 node-version : 20.x
110127
111128 - name : Start localstack
129+ if : ${{ matrix.needs_localstack }}
112130 run : docker run --rm -d -p 4566:4566 --name localstack localstack/localstack:4.14.0
113131
114- - name : Clean previous coverage data
115- run : cargo llvm-cov clean --workspace --profile coverage
132+ - name : Run tests with coverage
133+ env :
134+ DATABASE_URL : postgresql://postgres:postgres@localhost:5432/coprocessor
135+ SQLX_OFFLINE : ' true'
136+ TEST_GLOBAL_LOCALSTACK : ${{ matrix.needs_localstack && '1' || '0' }}
137+ TEST_PACKAGE : ${{ matrix.package }}
138+ IS_MERGE_QUEUE : ${{ startsWith(github.head_ref, 'mergify/merge-queue/') && '1' || '0' }}
139+ run : |
140+ # Merge queue: leave unset so supported_types() defaults to full matrix.
141+ # PR CI: run only small types (bool through 64-bit) for faster feedback.
142+ if [ "$IS_MERGE_QUEUE" != "1" ]; then
143+ export TFHE_WORKER_EVENT_TYPE_MATRIX=local
144+ fi
145+ cargo llvm-cov clean --workspace --profile coverage
146+ cargo llvm-cov test -p "$TEST_PACKAGE" --profile coverage
116147 working-directory : coprocessor/fhevm-engine
117148
118- - name : Compile tests with coverage instrumentation
119- run : |
120- cargo llvm-cov show-env --sh > /tmp/llvm-cov-env.sh
121- source /tmp/llvm-cov-env.sh
122- DATABASE_URL=postgresql://postgres:postgres@localhost:5432/coprocessor \
123- SQLX_OFFLINE=true \
124- cargo test --no-run --workspace --profile coverage
149+ - name : Export LCOV coverage data
150+ if : ${{ !cancelled() }}
151+ run : cargo llvm-cov report --lcov --profile coverage --output-path /tmp/lcov.info || true
125152 working-directory : coprocessor/fhevm-engine
126153
127- - name : Wait for database migration
128- run : |
129- SECONDS=0
130- while ! docker container inspect db-migration > /dev/null 2>&1; do
131- if [ "$SECONDS" -ge 900 ]; then
132- echo "Timed out waiting for db-migration container after 15 minutes"
133- cat /tmp/db-init.log
134- exit 1
135- fi
136- echo "Waiting for db-migration container to be created..."
137- sleep 2
138- done
139- EXIT_CODE=$(docker wait db-migration)
140- if [ "$EXIT_CODE" != "0" ]; then
141- echo "Database migration failed with exit code $EXIT_CODE"
142- docker logs db-migration
143- cat /tmp/db-init.log
144- exit 1
145- fi
146- echo "Database migration completed"
154+ - name : Upload coverage artifact
155+ if : ${{ !cancelled() }}
156+ uses : actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
157+ with :
158+ name : lcov-${{ matrix.service }}
159+ path : /tmp/lcov.info
160+ retention-days : 1
161+ if-no-files-found : ignore
147162
148- - name : Run tests with coverage
163+ coverage-report :
164+ name : coprocessor-cargo-test/coverage-report
165+ needs : [check-changes, cargo-tests]
166+ if : ${{ !cancelled() && needs.check-changes.outputs.changes-rust-files == 'true' }}
167+ permissions :
168+ contents : ' read' # Required to checkout repository code
169+ pull-requests : ' write' # Required to post coverage comment on PR
170+ runs-on : ubuntu-latest
171+ steps :
172+ - name : Checkout code
173+ uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
174+ with :
175+ persist-credentials : ' false'
176+
177+ - name : Install lcov
178+ run : sudo apt-get update && sudo apt-get install -y lcov
179+
180+ - name : Download all coverage artifacts
181+ uses : actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
182+ with :
183+ pattern : lcov-*
184+ path : /tmp/coverage
185+
186+ - name : Merge LCOV files
149187 run : |
150- source /tmp/llvm-cov-env.sh
151- DATABASE_URL=postgresql://postgres:postgres@localhost:5432/coprocessor \
152- TEST_GLOBAL_LOCALSTACK=1 \
153- SQLX_OFFLINE=true \
154- cargo test --workspace --profile coverage
155- working-directory : coprocessor/fhevm-engine
188+ LCOV_FILES=$(find /tmp/coverage -name 'lcov.info' -size +0c)
189+ if [ -z "$LCOV_FILES" ]; then
190+ echo "No coverage data found"
191+ exit 0
192+ fi
193+ LCOV_ARGS=()
194+ for f in $LCOV_FILES; do
195+ LCOV_ARGS+=(-a "$f")
196+ done
197+ lcov "${LCOV_ARGS[@]}" -o /tmp/lcov.info
156198
157- - name : Generate coverage report
199+ - name : Generate coverage summary
158200 if : ${{ !cancelled() }}
159201 run : |
160- if cargo llvm-cov report --profile coverage > /tmp/cov-report.txt 2>&1; then
161- REPORT=$(cat /tmp/cov-report.txt)
162- else
163- echo "cargo llvm-cov report failed:"
164- cat /tmp/cov-report.txt
165- REPORT=""
166- fi
167202 {
168203 echo '## Coverage: coprocessor/fhevm-engine'
169- if [ -n "$REPORT" ]; then
204+ if [ -f /tmp/lcov.info ]; then
170205 echo '```'
171- echo "$REPORT"
206+ lcov --summary /tmp/lcov.info 2>&1 || true
172207 echo '```'
173208 else
174209 echo '*No coverage data available (tests may have failed before producing profiling data).*'
175210 fi
176211 } >> "$GITHUB_STEP_SUMMARY"
177- echo "$REPORT"
178- working-directory : coprocessor/fhevm-engine
179-
180- - name : Export LCOV coverage data
181- if : ${{ !cancelled() }}
182- run : cargo llvm-cov report --lcov --profile coverage --output-path /tmp/lcov.info || true
183- working-directory : coprocessor/fhevm-engine
184212
185213 - name : Diff coverage of changed lines
186214 if : ${{ !cancelled() }}
@@ -230,3 +258,26 @@ jobs:
230258 uses : marocchino/sticky-pull-request-comment@773744901bac0e8cbb5a0dc842800d45e9b2b405 # v2.9.4
231259 with :
232260 path : /tmp/coverage-comment.md
261+
262+ cargo-tests-status :
263+ name : coprocessor-cargo-test/cargo-tests (bpr)
264+ needs : [check-changes, cargo-tests, coverage-report]
265+ if : ${{ always() }}
266+ runs-on : ubuntu-latest
267+ env :
268+ CHECK_CHANGES_RESULT : ${{ needs.check-changes.result }}
269+ CARGO_TESTS_RESULT : ${{ needs.cargo-tests.result }}
270+ COVERAGE_RESULT : ${{ needs.coverage-report.result }}
271+ steps :
272+ - name : Check results
273+ run : |
274+ if [ "$CHECK_CHANGES_RESULT" = "failure" ] || \
275+ [ "$CHECK_CHANGES_RESULT" = "cancelled" ] || \
276+ [ "$CARGO_TESTS_RESULT" = "failure" ] || \
277+ [ "$CARGO_TESTS_RESULT" = "cancelled" ] || \
278+ [ "$COVERAGE_RESULT" = "failure" ] || \
279+ [ "$COVERAGE_RESULT" = "cancelled" ]; then
280+ echo "One or more jobs failed or were cancelled"
281+ exit 1
282+ fi
283+ echo "All jobs passed or were skipped"
0 commit comments