forked from Crowdfunding-DApp/stellar-raise-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (122 loc) · 4.38 KB
/
Copy pathrust_ci.yml
File metadata and controls
145 lines (122 loc) · 4.38 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
name: Rust CI
on:
push:
branches:
- develop
- main
pull_request:
branches:
- develop
- main
env:
CARGO_TERM_COLOR: always
jobs:
frontend:
name: Frontend UI Tests
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Audit NPM dependencies
run: npm audit --audit-level=moderate
- name: Run frontend tests with coverage
run: npm run test:coverage -- --ci --reporters=default
check:
name: Check, Lint & Test
runs-on: ubuntu-latest
# Hard cap: entire job must complete within 30 minutes.
# Prevents runaway builds from blocking the merge queue indefinitely.
timeout-minutes: 30
steps:
- name: Record job start time
run: echo "JOB_START=$(date +%s)" >> "$GITHUB_ENV"
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Lint commit messages
uses: wagoid/commitlint-github-action@v6
continue-on-error: true
with:
configFile: .commitlintrc.json
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
components: clippy, rustfmt
# ── Cache ────────────────────────────────────────────
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
with:
# Cache key prefix — increment to bust cache manually
prefix-key: "v1-rust"
# Cache the registry and target directories
shared-key: "crowdfund"
cache-targets: true
cache-all-crates: true
# ── Alternative: using actions/cache directly ────────
# Uncomment below and remove rust-cache above if preferred:
#
# - name: Cache cargo registry
# uses: actions/cache@v3
# with:
# path: |
# ~/.cargo/registry
# ~/.cargo/git
# target/
# key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
# restore-keys: |
# ${{ runner.os }}-cargo-
- name: Check formatting
run: cargo fmt --all -- --check
- name: Build crowdfund WASM for tests
# Bound: WASM build should complete within 10 minutes on a warm cache.
timeout-minutes: 10
run: cargo build --release --target wasm32-unknown-unknown -p crowdfund
- name: Run Clippy
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Run tests including property-based tests
# Bound: test suite must complete within 15 minutes.
timeout-minutes: 15
env:
PROPTEST_CASES: 1000
run: cargo test --workspace
- name: Generate Rustdoc
run: cargo doc --no-deps --workspace
- name: Report WASM binary size
run: ls -lh target/wasm32-unknown-unknown/release/crowdfund.wasm
- name: Install wasm-opt (Binaryen)
run: sudo apt-get install -y binaryen
- name: Optimize WASM with wasm-opt
run: |
wasm-opt -Oz --enable-sign-ext \
target/wasm32-unknown-unknown/release/crowdfund.wasm \
-o target/wasm32-unknown-unknown/release/crowdfund.opt.wasm
- name: Fail if WASM exceeds 256 KB
run: |
SIZE=$(stat -c%s target/wasm32-unknown-unknown/release/crowdfund.opt.wasm)
MAX=$((256 * 1024))
if [ "$SIZE" -gt "$MAX" ]; then
echo "WASM binary too large: $SIZE bytes (max $MAX bytes)"
exit 1
else
echo "WASM size OK: $SIZE bytes"
fi
- name: Log total job elapsed time
if: always()
run: |
END=$(date +%s)
ELAPSED=$(( END - JOB_START ))
echo "Total job time: ${ELAPSED}s"
# Warn (but do not fail) if elapsed exceeds the soft target of 20 min.
SOFT_LIMIT_S=$(( 20 * 60 ))
if [ "$ELAPSED" -gt "$SOFT_LIMIT_S" ]; then
echo "::warning::Job took ${ELAPSED}s — exceeds soft limit of ${SOFT_LIMIT_S}s. Consider optimising slow steps."
fi