-
Notifications
You must be signed in to change notification settings - Fork 245
236 lines (199 loc) · 8.05 KB
/
rust.yml
File metadata and controls
236 lines (199 loc) · 8.05 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
name: Rust CI
on:
push:
branches: [main, "release/*"]
paths:
- "crates/**"
- "Cargo.*"
- "Makefile"
- ".github/workflows/rust.yml"
pull_request:
branches: [main, "release/*"]
paths:
- "crates/**"
- "Cargo.*"
- "Makefile"
- ".github/workflows/rust.yml"
env:
CARGO_TERM_COLOR: always
RUST_LOG: info
CI: true
jobs:
test:
name: Rust Tests & Coverage
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy, llvm-tools-preview
- uses: Swatinem/rust-cache@v2
- name: Check formatting
run: make check
- name: Run clippy
run: make lint
- name: Build
run: make build
- name: Setup Solana CLI
uses: ./.github/actions/setup-solana
- name: Install cargo-llvm-cov for coverage
run: cargo install cargo-llvm-cov
- name: Run unit tests with coverage
run: |
echo "🧪 Running unit tests with coverage instrumentation..."
cargo llvm-cov clean --workspace
cargo llvm-cov test --no-report --workspace --lib
- name: Setup Solana test validator
uses: ./.github/actions/setup-solana-validator
- name: Setup test environment
run: |
echo "🔧 Setting up test environment..."
# Create second signer key for multi-signer tests
if [ ! -f "tests/src/common/local-keys/signer2-local.json" ]; then
echo "Creating second signer key..."
solana-keygen new --outfile tests/src/common/local-keys/signer2-local.json --no-bip39-passphrase --silent
fi
KORA_PRIVATE_KEY="$(cat tests/src/common/local-keys/fee-payer-local.json)" cargo run -p tests --bin setup_test_env
- name: Setup Kora RPC server (regular config)
uses: ./.github/actions/setup-kora-rpc
with:
config-file: "tests/src/common/fixtures/kora-test.toml"
- name: Run RPC integration tests
run: |
echo "🧪 Running RPC integration tests..."
cargo llvm-cov test --no-report -p tests --test rpc
- name: Build transfer hook program for Token 2022 tests
run: |
echo "🔧 Building transfer hook program..."
make build-transfer-hook
- name: Run token integration tests
run: |
echo "🧪 Running token integration tests..."
cargo llvm-cov test --no-report -p tests --test tokens
- name: Run external integration tests
run: |
echo "🧪 Running external integration tests..."
cargo llvm-cov test --no-report -p tests --test external
- name: Stop Kora RPC server
run: |
if [ ! -z "$KORA_PID" ]; then
kill $KORA_PID || true
fi
sleep 2
- name: Setup Kora RPC server (auth config)
uses: ./.github/actions/setup-kora-rpc
with:
config-file: "tests/src/common/fixtures/auth-test.toml"
- name: Run auth integration tests
run: |
echo "🧪 Running auth integration tests..."
cargo llvm-cov test --no-report -p tests --test auth
- name: Stop Kora RPC server
run: |
if [ ! -z "$KORA_PID" ]; then
kill $KORA_PID || true
fi
sleep 2
- name: Setup Kora RPC server (payment address config)
uses: ./.github/actions/setup-kora-rpc
with:
config-file: "tests/src/common/fixtures/paymaster-address-test.toml"
initialize-atas: "true"
- name: Run payment address integration tests
run: |
echo "🧪 Running payment address integration tests..."
cargo llvm-cov test --no-report -p tests --test payment_address
- name: Stop Kora RPC server
run: |
if [ ! -z "$KORA_PID" ]; then
kill $KORA_PID || true
fi
sleep 2
- name: Setup multi-signer test environment
run: |
echo "🔧 Setting up multi-signer test environment..."
export KORA_PRIVATE_KEY="$(cat tests/src/common/local-keys/fee-payer-local.json)"
export KORA_PRIVATE_KEY_2="$(cat tests/src/common/local-keys/signer2-local.json)"
cargo run -p tests --bin setup_test_env
- name: Setup Kora RPC server (multi-signer config)
uses: ./.github/actions/setup-kora-rpc
with:
config-file: "tests/src/common/fixtures/kora-test.toml"
signers-config: "tests/src/common/fixtures/multi-signers.toml"
- name: Run multi-signer integration tests
run: |
echo "🧪 Running multi-signer integration tests..."
cargo llvm-cov test --no-report -p tests --test multi_signer
- name: Generate coverage reports
run: |
echo "📊 Generating coverage reports..."
mkdir -p coverage
cargo llvm-cov report --lcov --output-path coverage/lcov.info
- name: Display coverage summary
run: |
echo "📊 Coverage Summary:"
if [ -f "coverage/lcov.info" ]; then
echo "✅ Coverage report generated successfully"
echo "📄 Generated: coverage/lcov.info"
else
echo "❌ Coverage report not found"
fi
- name: Upload coverage artifacts
uses: actions/upload-artifact@v4
with:
name: rust-coverage-report
path: coverage/
retention-days: 30
- name: Update PR description with coverage badge
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
uses: actions/github-script@v7
with:
script: |
// Extract coverage percentage from lcov.info
const fs = require('fs');
let coverage = '0';
try {
const lcov = fs.readFileSync('coverage/lcov.info', 'utf8');
const linesFound = lcov.match(/^LF:(\d+)$/gm)?.reduce((sum, line) => sum + parseInt(line.split(':')[1]), 0) || 0;
const linesHit = lcov.match(/^LH:(\d+)$/gm)?.reduce((sum, line) => sum + parseInt(line.split(':')[1]), 0) || 0;
coverage = linesFound > 0 ? ((linesHit / linesFound) * 100).toFixed(1) : '0';
} catch (error) {
console.log('Error reading coverage:', error);
}
// Determine badge color
let color = 'red';
if (parseFloat(coverage) >= 80) color = 'green';
else if (parseFloat(coverage) >= 60) color = 'yellow';
// Get current PR
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
// Create coverage badge section
const coverageBadge = ``;
const coverageSection = `\n\n## 📊 Test Coverage\n${coverageBadge}\n\n**Coverage: ${coverage}%**\n\n[View Detailed Coverage Report](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId})`;
// Update PR body
let newBody = pr.body || '';
// Remove existing coverage section if present
newBody = newBody.replace(/\n## 📊 Test Coverage[\s\S]*?(?=\n## |\n$|$)/g, '');
// Add new coverage section
newBody += coverageSection;
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
body: newBody
});
- name: Cleanup test environment
if: always()
uses: ./.github/actions/cleanup-test-env
- name: Show failure logs
if: failure()
uses: ./.github/actions/show-failure-logs
with:
test-type: "Rust integration"