|
| 1 | +name: CI/CD Pipeline |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + |
| 9 | +env: |
| 10 | + CARGO_TERM_COLOR: always |
| 11 | + NODE_VERSION: '20' |
| 12 | + |
| 13 | +jobs: |
| 14 | + # ── Rust: Format ────────────────────────────────────────────────────────── |
| 15 | + rust-fmt: |
| 16 | + name: Rust Format Check |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - uses: actions-rs/toolchain@v1 |
| 22 | + with: |
| 23 | + toolchain: stable |
| 24 | + components: rustfmt |
| 25 | + override: true |
| 26 | + |
| 27 | + - name: Check formatting |
| 28 | + run: cargo fmt --all -- --check |
| 29 | + |
| 30 | + # ── Rust: Clippy ────────────────────────────────────────────────────────── |
| 31 | + rust-clippy: |
| 32 | + name: Rust Clippy |
| 33 | + runs-on: ubuntu-latest |
| 34 | + steps: |
| 35 | + - uses: actions/checkout@v4 |
| 36 | + |
| 37 | + - uses: actions-rs/toolchain@v1 |
| 38 | + with: |
| 39 | + toolchain: stable |
| 40 | + components: clippy |
| 41 | + override: true |
| 42 | + |
| 43 | + - name: Run Clippy |
| 44 | + run: cargo clippy --all-targets -- -D warnings |
| 45 | + |
| 46 | + # ── Rust: Test ──────────────────────────────────────────────────────────── |
| 47 | + rust-test: |
| 48 | + name: Rust Tests |
| 49 | + runs-on: ubuntu-latest |
| 50 | + steps: |
| 51 | + - uses: actions/checkout@v4 |
| 52 | + |
| 53 | + - uses: actions-rs/toolchain@v1 |
| 54 | + with: |
| 55 | + toolchain: stable |
| 56 | + override: true |
| 57 | + |
| 58 | + - name: Cache cargo registry |
| 59 | + uses: actions/cache@v4 |
| 60 | + with: |
| 61 | + path: | |
| 62 | + ~/.cargo/registry |
| 63 | + ~/.cargo/git |
| 64 | + target |
| 65 | + key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }} |
| 66 | + restore-keys: | |
| 67 | + ${{ runner.os }}-cargo- |
| 68 | +
|
| 69 | + - name: Run tests |
| 70 | + run: cargo test --all-features |
| 71 | + |
| 72 | + # ── Rust: Gas Benchmarks ────────────────────────────────────────────────── |
| 73 | + rust-gas-bench: |
| 74 | + name: Gas Consumption Benchmarks |
| 75 | + runs-on: ubuntu-latest |
| 76 | + steps: |
| 77 | + - uses: actions/checkout@v4 |
| 78 | + |
| 79 | + - uses: actions-rs/toolchain@v1 |
| 80 | + with: |
| 81 | + toolchain: stable |
| 82 | + override: true |
| 83 | + |
| 84 | + - name: Cache cargo registry |
| 85 | + uses: actions/cache@v4 |
| 86 | + with: |
| 87 | + path: | |
| 88 | + ~/.cargo/registry |
| 89 | + ~/.cargo/git |
| 90 | + target |
| 91 | + key: ${{ runner.os }}-cargo-gas-${{ hashFiles('Cargo.lock') }} |
| 92 | + restore-keys: | |
| 93 | + ${{ runner.os }}-cargo-gas- |
| 94 | +
|
| 95 | + - name: Run gas benchmarks |
| 96 | + run: cargo test --release gas_benchmarks -- --nocapture |
| 97 | + |
| 98 | + - name: Upload gas baseline artifact |
| 99 | + uses: actions/upload-artifact@v4 |
| 100 | + with: |
| 101 | + name: gas-baseline |
| 102 | + path: gas-baseline.json |
| 103 | + |
| 104 | + # ── Contract WASM Size Check ────────────────────────────────────────────── |
| 105 | + wasm-size-check: |
| 106 | + name: Contract WASM Size Check |
| 107 | + runs-on: ubuntu-latest |
| 108 | + steps: |
| 109 | + - uses: actions/checkout@v4 |
| 110 | + |
| 111 | + - uses: actions-rs/toolchain@v1 |
| 112 | + with: |
| 113 | + toolchain: stable |
| 114 | + target: wasm32-unknown-unknown |
| 115 | + override: true |
| 116 | + |
| 117 | + - name: Build contracts for WASM |
| 118 | + run: cargo build --target wasm32-unknown-unknown --release |
| 119 | + |
| 120 | + - name: Check WASM sizes (< 64KB per contract) |
| 121 | + run: | |
| 122 | + set -e |
| 123 | + MAX_SIZE=65536 |
| 124 | + FAILED=0 |
| 125 | + for wasm in target/wasm32-unknown-unknown/release/*.wasm; do |
| 126 | + [ -f "$wasm" ] || continue |
| 127 | + size=$(stat -c%s "$wasm") |
| 128 | + name=$(basename "$wasm") |
| 129 | + if [ "$size" -gt "$MAX_SIZE" ]; then |
| 130 | + echo "::error::WASM $name is $size bytes (max $MAX_SIZE)" |
| 131 | + FAILED=1 |
| 132 | + else |
| 133 | + echo "::notice::WASM $name is $size bytes (OK)" |
| 134 | + fi |
| 135 | + done |
| 136 | + [ "$FAILED" -eq 0 ] || exit 1 |
| 137 | +
|
| 138 | + # ── SDK: Lint ───────────────────────────────────────────────────────────── |
| 139 | + sdk-lint: |
| 140 | + name: SDK Lint |
| 141 | + runs-on: ubuntu-latest |
| 142 | + steps: |
| 143 | + - uses: actions/checkout@v4 |
| 144 | + |
| 145 | + - uses: actions/setup-node@v4 |
| 146 | + with: |
| 147 | + node-version: ${{ env.NODE_VERSION }} |
| 148 | + |
| 149 | + - name: Install dependencies |
| 150 | + run: npm ci |
| 151 | + working-directory: . |
| 152 | + |
| 153 | + - name: Run lint |
| 154 | + run: npm run lint |
| 155 | + working-directory: . |
| 156 | + |
| 157 | + # ── SDK: Test ───────────────────────────────────────────────────────────── |
| 158 | + sdk-test: |
| 159 | + name: SDK Tests |
| 160 | + runs-on: ubuntu-latest |
| 161 | + steps: |
| 162 | + - uses: actions/checkout@v4 |
| 163 | + |
| 164 | + - uses: actions/setup-node@v4 |
| 165 | + with: |
| 166 | + node-version: ${{ env.NODE_VERSION }} |
| 167 | + |
| 168 | + - name: Install dependencies |
| 169 | + run: npm ci |
| 170 | + working-directory: . |
| 171 | + |
| 172 | + - name: Run tests |
| 173 | + run: npm test |
| 174 | + working-directory: . |
| 175 | + |
| 176 | + # ── SDK: Build ──────────────────────────────────────────────────────────── |
| 177 | + sdk-build: |
| 178 | + name: SDK Build |
| 179 | + runs-on: ubuntu-latest |
| 180 | + steps: |
| 181 | + - uses: actions/checkout@v4 |
| 182 | + |
| 183 | + - uses: actions/setup-node@v4 |
| 184 | + with: |
| 185 | + node-version: ${{ env.NODE_VERSION }} |
| 186 | + |
| 187 | + - name: Install dependencies |
| 188 | + run: npm ci |
| 189 | + working-directory: . |
| 190 | + |
| 191 | + - name: Build SDK |
| 192 | + run: npm run build |
| 193 | + working-directory: . |
| 194 | + |
| 195 | + # ── UI: Lint ────────────────────────────────────────────────────────────── |
| 196 | + ui-lint: |
| 197 | + name: UI Lint |
| 198 | + runs-on: ubuntu-latest |
| 199 | + steps: |
| 200 | + - uses: actions/checkout@v4 |
| 201 | + |
| 202 | + - uses: actions/setup-node@v4 |
| 203 | + with: |
| 204 | + node-version: ${{ env.NODE_VERSION }} |
| 205 | + |
| 206 | + - name: Install UI dependencies |
| 207 | + run: npm ci |
| 208 | + working-directory: ui |
| 209 | + |
| 210 | + - name: Run UI lint |
| 211 | + run: npm run lint |
| 212 | + working-directory: ui |
| 213 | + |
| 214 | + # ── UI: Build ───────────────────────────────────────────────────────────── |
| 215 | + ui-build: |
| 216 | + name: UI Build |
| 217 | + runs-on: ubuntu-latest |
| 218 | + steps: |
| 219 | + - uses: actions/checkout@v4 |
| 220 | + |
| 221 | + - uses: actions/setup-node@v4 |
| 222 | + with: |
| 223 | + node-version: ${{ env.NODE_VERSION }} |
| 224 | + |
| 225 | + - name: Install UI dependencies |
| 226 | + run: npm ci |
| 227 | + working-directory: ui |
| 228 | + |
| 229 | + - name: Build UI |
| 230 | + run: npm run build |
| 231 | + working-directory: ui |
| 232 | + |
| 233 | + - name: Type check UI |
| 234 | + run: npm run type-check |
| 235 | + working-directory: ui |
| 236 | + |
| 237 | + # ── Coverage ────────────────────────────────────────────────────────────── |
| 238 | + coverage: |
| 239 | + name: Code Coverage |
| 240 | + runs-on: ubuntu-latest |
| 241 | + needs: [rust-test, sdk-test] |
| 242 | + if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/main') |
| 243 | + steps: |
| 244 | + - uses: actions/checkout@v4 |
| 245 | + |
| 246 | + - uses: actions-rs/toolchain@v1 |
| 247 | + with: |
| 248 | + toolchain: stable |
| 249 | + override: true |
| 250 | + |
| 251 | + - name: Install tarpaulin |
| 252 | + uses: actions-rs/install@v0.1 |
| 253 | + with: |
| 254 | + crate: cargo-tarpaulin |
| 255 | + version: latest |
| 256 | + use-tool-cache: true |
| 257 | + |
| 258 | + - name: Run coverage |
| 259 | + run: cargo tarpaulin --out Xml |
| 260 | + |
| 261 | + - name: Upload coverage to Codecov |
| 262 | + uses: codecov/codecov-action@v4 |
| 263 | + with: |
| 264 | + file: ./cobertura.xml |
| 265 | + fail_ci_if_error: false |
| 266 | + |
| 267 | + # ── Notifications ───────────────────────────────────────────────────────── |
| 268 | + notify: |
| 269 | + name: Notify on Main Failure |
| 270 | + runs-on: ubuntu-latest |
| 271 | + needs: |
| 272 | + - rust-fmt |
| 273 | + - rust-clippy |
| 274 | + - rust-test |
| 275 | + - rust-gas-bench |
| 276 | + - wasm-size-check |
| 277 | + - sdk-lint |
| 278 | + - sdk-test |
| 279 | + - sdk-build |
| 280 | + - ui-lint |
| 281 | + - ui-build |
| 282 | + if: failure() && github.ref == 'refs/heads/main' |
| 283 | + steps: |
| 284 | + - name: Slack Notification |
| 285 | + uses: slackapi/slack-github-action@v1.27.0 |
| 286 | + with: |
| 287 | + payload: | |
| 288 | + { |
| 289 | + "text": ":x: CI failed on `main` branch\nRepository: ${{ github.repository }}\nWorkflow: ${{ github.workflow }}\nActor: ${{ github.actor }}\nCommit: ${{ github.sha }}\nURL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 290 | + } |
| 291 | + env: |
| 292 | + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |
| 293 | + continue-on-error: true |
| 294 | + |
| 295 | + - name: Discord Notification |
| 296 | + uses: tsickert/discord-webhook@v6.0.0 |
| 297 | + with: |
| 298 | + webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }} |
| 299 | + content: ":x: **CI failed** on \`main\`\nRepository: ${{ github.repository }}\nWorkflow: ${{ github.workflow }}\nActor: ${{ github.actor }}\n[View Run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" |
| 300 | + continue-on-error: true |
| 301 | + |
| 302 | + # ── Final Gate ──────────────────────────────────────────────────────────── |
| 303 | + all-green: |
| 304 | + name: All Checks Passed |
| 305 | + runs-on: ubuntu-latest |
| 306 | + needs: |
| 307 | + - rust-fmt |
| 308 | + - rust-clippy |
| 309 | + - rust-test |
| 310 | + - rust-gas-bench |
| 311 | + - wasm-size-check |
| 312 | + - sdk-lint |
| 313 | + - sdk-test |
| 314 | + - sdk-build |
| 315 | + - ui-lint |
| 316 | + - ui-build |
| 317 | + if: always() |
| 318 | + steps: |
| 319 | + - name: Check all dependent jobs passed |
| 320 | + run: | |
| 321 | + RESULT="${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}" |
| 322 | + if [ "$RESULT" = "true" ]; then |
| 323 | + echo "::error::Some required checks have failed" |
| 324 | + exit 1 |
| 325 | + fi |
| 326 | + echo "::notice::All checks passed!" |
0 commit comments