forked from Web3Novalabs/predifi
-
Notifications
You must be signed in to change notification settings - Fork 0
166 lines (139 loc) · 4.94 KB
/
backend.yml
File metadata and controls
166 lines (139 loc) · 4.94 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
name: Backend CI
on:
push:
branches:
- main
- contract
paths:
- "contract/**"
- "backend/**"
- ".github/workflows/backend.yml"
pull_request:
branches:
- main
- contract
paths:
- "contract/**"
- "backend/**"
- ".github/workflows/backend.yml"
workflow_dispatch:
concurrency:
group: backend-ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
WASM_SIZE_THRESHOLD_KB: 200
jobs:
contract-checks:
name: Contract Checks (WASM)
runs-on: ubuntu-latest
timeout-minutes: 20
defaults:
run:
working-directory: ./contract
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
targets: wasm32-unknown-unknown
- name: Install wasm-opt (binaryen)
run: |
BINARYEN_VERSION="120"
curl -fsSL "https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz" \
| tar -xz -C /tmp
sudo mv "/tmp/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt" /usr/local/bin/wasm-opt
wasm-opt --version
- name: Cache Cargo dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
contract/target
key: ${{ runner.os }}-cargo-${{ hashFiles('contract/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Check formatting
run: cargo fmt --all -- --check
- name: Lint with clippy
run: cargo clippy --workspace --target wasm32-unknown-unknown -- -D warnings
- name: Build contract
run: cargo build --workspace --target wasm32-unknown-unknown --release
- name: Run wasm-opt -O3
run: |
WASM_DIR="target/wasm32-unknown-unknown/release"
echo "| Contract | Raw (bytes) | After wasm-opt -O3 (bytes) | Reduction |" >> "$GITHUB_STEP_SUMMARY"
echo "|---|---|---|---|" >> "$GITHUB_STEP_SUMMARY"
for CONTRACT in predifi_contract access_control; do
RAW="${WASM_DIR}/${CONTRACT}.wasm"
OPT="${WASM_DIR}/${CONTRACT}.wasm-opt.wasm"
[[ -f "$RAW" ]] || continue
RAW_BYTES=$(wc -c < "$RAW")
wasm-opt -O3 --strip-debug --enable-bulk-memory --enable-sign-ext -o "$OPT" "$RAW"
OPT_BYTES=$(wc -c < "$OPT")
REDUCTION=$(( RAW_BYTES - OPT_BYTES ))
echo "| ${CONTRACT} | ${RAW_BYTES} | ${OPT_BYTES} | -${REDUCTION} bytes |" >> "$GITHUB_STEP_SUMMARY"
done
- name: Test wasm-opt integration
run: bash scripts/tests/test_wasm_opt.sh
- name: Run unit tests
run: cargo test --workspace
- name: Check WASM size
run: bash scripts/wasm_size_check.sh
- name: Print WASM size summary
if: always()
run: |
WASM="target/wasm32-unknown-unknown/release/predifi_contract.wasm"
if [[ -f "$WASM" ]]; then
BYTES=$(wc -c < "$WASM")
KB=$(( BYTES / 1024 ))
echo "### WASM Size: ${KB} KB (${BYTES} bytes)" >> "$GITHUB_STEP_SUMMARY"
echo "Threshold: ${WASM_SIZE_THRESHOLD_KB} KB" >> "$GITHUB_STEP_SUMMARY"
fi
- name: Upload WASM artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: predifi-wasm-${{ github.sha }}
path: |
contract/target/wasm32-unknown-unknown/release/predifi_contract.wasm
contract/target/wasm32-unknown-unknown/release/predifi_contract.wasm-opt.wasm
contract/target/wasm32-unknown-unknown/release/access_control.wasm
contract/target/wasm32-unknown-unknown/release/access_control.wasm-opt.wasm
if-no-files-found: ignore
retention-days: 90
backend-checks:
name: Backend Checks
runs-on: ubuntu-latest
timeout-minutes: 20
defaults:
run:
working-directory: ./backend
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Cache Cargo dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
backend/target
key: ${{ runner.os }}-cargo-${{ hashFiles('backend/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Check formatting
run: cargo fmt --all -- --check
- name: Lint with clippy
run: cargo clippy --all-targets -- -D warnings
- name: Build backend
run: cargo build --release
- name: Run tests (unit + integration)
run: cargo test