forked from LabsCrypt/flowfi
-
Notifications
You must be signed in to change notification settings - Fork 0
270 lines (225 loc) · 8.03 KB
/
Copy pathci.yml
File metadata and controls
270 lines (225 loc) · 8.03 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
# Continuous Integration workflow for FlowFi
# Covers frontend linting/build, backend build/test, and Soroban contract build/test.
name: CI
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
jobs:
frontend:
name: Frontend CI
runs-on: ubuntu-latest
steps:
- name: Checkout code
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 dependencies
run: npm ci
- name: Lint
run: npm run lint
working-directory: frontend
- name: Install Rollup Native Binding
run: npm install @rollup/rollup-linux-x64-gnu --no-save
working-directory: frontend
- name: Run Frontend Tests
run: npm run test:coverage
working-directory: frontend
- name: Upload frontend coverage to Codecov
uses: codecov/codecov-action@v5
with:
files: frontend/coverage/lcov.info
flags: frontend
name: frontend-coverage
fail_ci_if_error: false
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Build
run: npm run build
working-directory: frontend
backend:
name: Backend CI
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16-alpine@sha256:e013e867e712fec275706a6c51c966f0bb0c93cfa8f51000f85a15f9865a28cb
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: flowfi_test
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout code
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 dependencies
run: npm ci --include=optional
- name: Setup Database
run: |
npx prisma generate --schema=prisma/schema.prisma
npx prisma db push --accept-data-loss --schema=prisma/schema.prisma
working-directory: backend
env:
DATABASE_URL: postgresql://postgres:password@127.0.0.1:5432/flowfi_test
- name: Build
run: npm run build
working-directory: backend
- name: Install Rollup Native Binding
run: npm install @rollup/rollup-linux-x64-gnu --no-save
- name: Run Backend Tests
run: |
ls -la src/generated/prisma
npm install @vitest/coverage-v8@2.1.9 --no-save
npx vitest run --coverage --reporter=basic
working-directory: backend
env:
DATABASE_URL: postgresql://postgres:password@127.0.0.1:5432/flowfi_test
NODE_ENV: test
- name: Upload backend coverage to Codecov
uses: codecov/codecov-action@v5
with:
files: backend/coverage/lcov.info
flags: backend
name: backend-coverage
fail_ci_if_error: false
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
backend-docker:
name: Backend Docker Image CI
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check changed files
id: filter
uses: dorny/paths-filter@v3
with:
filters: |
backend:
- 'backend/**'
- 'docker-compose.yml'
- name: Build Docker Image
if: steps.filter.outputs.backend == 'true' || github.event_name == 'push'
run: docker build -f backend/Dockerfile backend -t flowfi-backend:test
- name: Docker Compose Build
if: steps.filter.outputs.backend == 'true' || github.event_name == 'push'
run: docker compose build
- name: Boot and Check Health
if: steps.filter.outputs.backend == 'true' || github.event_name == 'push'
run: |
docker compose up -d postgres
sleep 10
docker compose run --rm -e DATABASE_URL=postgresql://flowfi:flowfi_dev_password@postgres:5432/flowfi backend npx -y prisma db push --accept-data-loss
docker compose up -d backend
sleep 15
curl --fail http://localhost:3001/health || (docker compose logs backend && exit 1)
contracts:
name: Soroban Contracts CI
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
targets: wasm32-unknown-unknown
components: rustfmt, clippy
- name: Rust Cache
uses: Swatinem/rust-cache@v2
with:
workspace: "contracts -> target"
- name: Check Formatting
run: cargo fmt --all -- --check
working-directory: contracts
- name: Run Clippy
run: cargo clippy --all-targets -- -D warnings
working-directory: contracts
- name: Build Contracts
run: cargo build --target wasm32-unknown-unknown --release
working-directory: contracts
- name: Run Contract Tests
run: cargo test
working-directory: contracts
- name: Install cargo-tarpaulin
run: cargo install cargo-tarpaulin --locked
- name: Run Contract Coverage
run: cargo tarpaulin --workspace --out Xml --output-dir coverage --fail-under 70
working-directory: contracts
- name: Upload contract coverage to Codecov
uses: codecov/codecov-action@v5
with:
files: contracts/coverage/cobertura.xml
flags: contracts
name: contracts-coverage
fail_ci_if_error: false
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Install Stellar CLI
run: |
curl -fsSL https://github.com/stellar/stellar-cli/raw/main/install.sh | sh -s -- --install-deps
echo "$HOME/.stellar-cli/bin" >> $GITHUB_PATH
shell: bash
- name: Optimize WASM files
run: |
set -euo pipefail
# Target the precise release build directory
RELEASE_DIR="contracts/target/wasm32-unknown-unknown/release"
# Use your strict selection logic to target un-optimized raw binaries only
WASMS=$(find "$RELEASE_DIR" -maxdepth 1 -type f -name "*.wasm" ! -name "*.optimized.wasm")
if [ -z "$WASMS" ]; then
echo "Error: No raw WASM files found in $RELEASE_DIR"
exit 1
fi
for w in $WASMS; do
filename=$(basename "$w")
out="$RELEASE_DIR/${filename%.wasm}.optimized.wasm"
echo "Optimizing $filename -> $(basename "$out")"
stellar contract optimize --wasm "$w" --wasm-out "$out"
done
shell: bash
- name: Check WASM size budget
run: |
set -euo pipefail
RELEASE_DIR="contracts/target/wasm32-unknown-unknown/release"
WASM_SIZE_LIMIT=200000 # 200KB budget for optimized WASM
for wasm in "$RELEASE_DIR"/*.optimized.wasm; do
if [ -f "$wasm" ]; then
size=$(stat -c%s "$wasm")
filename=$(basename "$wasm")
echo "Optimized WASM size: $filename = $size bytes"
if [ "$size" -gt "$WASM_SIZE_LIMIT" ]; then
echo "Error: $filename exceeds size budget of $WASM_SIZE_LIMIT bytes"
exit 1
fi
fi
done
shell: bash
- name: Upload optimized WASM artifacts
uses: actions/upload-artifact@v4
with:
name: optimized-wasm
path: contracts/target/wasm32-unknown-unknown/release/*.optimized.wasm
if-no-files-found: error