-
Notifications
You must be signed in to change notification settings - Fork 2.2k
197 lines (174 loc) · 6.9 KB
/
coprocessor-cargo-tests.yml
File metadata and controls
197 lines (174 loc) · 6.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
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
pull-requests: 'write' # Required to post coverage comment on PR
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 toolchain file
run: cp coprocessor/fhevm-engine/rust-toolchain.toml .
- name: Setup Rust
uses: dsherret/rust-toolchain-file@3551321aa44dd44a0393eb3b6bdfbc5d25ecf621 # v1
- 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
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