-
Notifications
You must be signed in to change notification settings - Fork 70
310 lines (266 loc) · 8.95 KB
/
Copy pathci-pr.yml
File metadata and controls
310 lines (266 loc) · 8.95 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
name: CI/CD Pipeline (PR Safe)
on:
pull_request:
types: [opened, synchronize, reopened]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
NPM_CONFIG_FETCH_RETRIES: 5
NPM_CONFIG_FETCH_RETRY_MINTIMEOUT: 20000
NPM_CONFIG_FETCH_RETRY_MAXTIMEOUT: 120000
jobs:
detect-changes:
name: Detect Changes
runs-on: ubuntu-latest
outputs:
contracts: ${{ steps.changes.outputs.contracts }}
backend: ${{ steps.changes.outputs.backend }}
frontend: ${{ steps.changes.outputs.frontend }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- id: changes
uses: dorny/paths-filter@v3
with:
filters: |
contracts:
- 'contracts/**'
- '.github/workflows/ci-pr.yml'
backend:
- 'backend/**'
- 'package.json'
- 'package-lock.json'
- '.github/workflows/ci-pr.yml'
frontend:
- 'frontend/**'
- 'package.json'
- 'package-lock.json'
- '.github/workflows/ci-pr.yml'
build-contracts:
name: Build & Lint Contracts
needs: detect-changes
if: ${{ needs.detect-changes.outputs.contracts == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: clippy, rustfmt
- name: Cache Cargo dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
contracts/target/
key: ${{ runner.os }}-cargo-contracts-${{ hashFiles('contracts/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-contracts-
- name: Cache cargo-audit binary
id: cache-audit
uses: actions/cache@v4
with:
path: ~/.cargo/bin/cargo-audit
key: ${{ runner.os }}-cargo-audit-bin-0.22
- name: Check formatting
run: cd contracts && cargo fmt --all -- --check
- name: Run Clippy
run: cd contracts && cargo clippy -- -D warnings
- name: Build contracts (release)
run: cd contracts && cargo build --release
- name: Build tests (no run)
run: cd contracts && cargo test --no-run --release
continue-on-error: true
test-contracts:
name: Test Contracts (${{ matrix.test-group }})
needs: build-contracts
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
test-group:
- unit
- integration
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- name: Cache Cargo dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
contracts/target/
key: ${{ runner.os }}-cargo-contracts-${{ hashFiles('contracts/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-contracts-
- name: Run ${{ matrix.test-group }} tests
run: |
if [ "${{ matrix.test-group }}" = "integration" ]; then
cd contracts && cargo test --test '*' --release
else
cd contracts && cargo test --lib --release
fi
build-backend:
name: Build Backend
needs: detect-changes
if: ${{ needs.detect-changes.outputs.backend == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: |
package-lock.json
backend/package-lock.json
- name: Verify lock file
run: |
if [ ! -f package-lock.json ]; then
echo "Error: root package-lock.json is missing. Run 'npm install --package-lock-only' in the project root"
exit 1
fi
- name: Install dependencies
run: npm ci -w backend
- name: Run backend linter
run: npm run lint -w backend 2>/dev/null || echo "No linter configured for backend"
- name: Build backend
run: npm run build -w backend
- name: Cache backend build
uses: actions/cache@v4
with:
path: backend/.next
key: ${{ runner.os }}-backend-${{ hashFiles('backend/**/*.ts', 'backend/**/*.tsx', 'backend/package-lock.json') }}
enable-cross-os-access: true
test-backend:
name: Test Backend
needs: build-backend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: |
package-lock.json
backend/package-lock.json
- name: Install dependencies
run: npm ci -w backend
- name: Run backend tests
run: npm test -w backend 2>/dev/null || echo "No tests configured for backend"
build-frontend:
name: Build Frontend
needs: detect-changes
if: ${{ needs.detect-changes.outputs.frontend == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: |
package-lock.json
frontend/package-lock.json
- name: Verify lock file
run: |
if [ ! -f package-lock.json ]; then
echo "Error: root package-lock.json is missing. Run 'npm install --package-lock-only' in the project root"
exit 1
fi
- name: Install dependencies
run: npm ci -w frontend
- name: Build frontend
run: npm run build -w frontend
env:
NEXT_PUBLIC_STELLAR_RECEIVER_ADDRESS: ${{ secrets.NEXT_PUBLIC_STELLAR_RECEIVER_ADDRESS || 'GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWNA' }}
security-scan:
name: Security Scan
needs: detect-changes
if: ${{ always() }}
runs-on: ubuntu-latest
permissions:
security-events: write
contents: read
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: package-lock.json
- name: Install root dependencies (for audit)
run: npm ci --ignore-scripts
- name: npm audit (report only, non-blocking)
run: npm audit --audit-level=critical --workspaces --include-workspace-root || echo "npm audit found issues (non-blocking)"
- name: Setup Rust for cargo-audit
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- name: Cache cargo-audit binary
id: cache-audit
uses: actions/cache@v4
with:
path: ~/.cargo/bin/cargo-audit
key: ${{ runner.os }}-cargo-audit-bin-0.22
- name: Install cargo-audit (if not cached)
if: steps.cache-audit.outputs.cache-hit != 'true'
run: cargo install --locked cargo-audit --version ^0.22 --force
- name: cargo audit (Rust dependencies, non-blocking)
working-directory: contracts
run: cargo audit || echo "cargo audit found issues (non-blocking)"
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '.'
format: 'sarif'
output: 'trivy-results.sarif'
- name: Upload Trivy scan results
uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: 'trivy-results.sarif'
ci-status:
name: CI Status Check
needs:
- build-contracts
- test-contracts
- build-backend
- test-backend
- build-frontend
- security-scan
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
- name: Check build-contracts status
run: |
echo "build-contracts: ${{ needs.build-contracts.result }}"
echo "test-contracts: ${{ needs.test-contracts.result }}"
echo "build-backend: ${{ needs.build-backend.result }}"
echo "test-backend: ${{ needs.test-backend.result }}"
echo "build-frontend: ${{ needs.build-frontend.result }}"
echo "security-scan: ${{ needs.security-scan.result }}"
- name: Fail if any critical job failed
if: >
needs.build-contracts.result == 'failure' ||
needs.build-backend.result == 'failure' ||
needs.build-frontend.result == 'failure'
run: exit 1