-
Notifications
You must be signed in to change notification settings - Fork 11
318 lines (292 loc) · 9.37 KB
/
ci.yml
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
311
312
313
314
315
316
317
318
name: CI/CD
on:
pull_request:
branches: [ main, develop ]
jobs:
rustfmt:
concurrency:
group: rustfmt-${{ github.ref }}
cancel-in-progress: true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install nightly
# we use nightly because of nice formatting option :)
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
components: rustfmt
default: true
- name: Rustfmt check
run: cargo +nightly fmt --all -- --check
unit-test:
concurrency:
group: unit-test-${{ github.ref }}
cancel-in-progress: true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: rustfmt, clippy
default: true
- name: Build & Run all default unit tests
run: |
RUSTFLAGS="-D warnings" cargo test --workspace --features test-all -- --test-threads=10
- name: Build & Run pallet unit tests
run: |
RUSTFLAGS="-D warnings" cargo test --workspace --features psp22_pallet -- --test-threads=10
examples-builds:
concurrency:
group: examples-builds-${{ github.ref }}
cancel-in-progress: true
runs-on: ubuntu-latest
container:
image: ghcr.io/brushfam/openbrush-contracts-ci
options: --user root
env:
CARGO_TARGET_DIR: /usr/local/cache/target
steps:
- uses: actions/setup-node@v1
with:
node-version: '16.x'
- uses: actions/checkout@v3
- name: Install stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
default: true
target: wasm32-unknown-unknown
components: rust-src
- name: NPM install dependencies
run: |
npm i
npm i ts-node
- name: Cache rust artifacts
id: cache-rust-artifacts
uses: actions/cache@v3
with:
path: /usr/local/cache/target
key: cache-rust-artifacts-${{ hashFiles('Cargo.toml') }}-${{ github.ref }}
restore-keys: |
cache-rust-artifacts-${{ hashFiles('Cargo.toml') }}
- name: Cache contract artifacts
id: cache-contract-artifacts
uses: actions/cache@v3
with:
path: artifacts
key: cache-contract-artifacts-${{ github.sha }}
- name: Typechain Compile examples
run: |
chown -R root .
chmod -R a+rwx .
npm run build:release
caching-artifacts:
concurrency:
group: caching-artifacts-${{ github.ref }}
cancel-in-progress: true
runs-on: ubuntu-latest
needs: examples-builds
container:
image: ghcr.io/brushfam/openbrush-contracts-ci
options: --user root
steps:
- uses: actions/checkout@v3
- name: Copy rust artifacts
id: cache-rust-artifacts
uses: actions/cache@v3
with:
path: /usr/local/cache/target
key: cache-rust-artifacts-${{ hashFiles('Cargo.toml') }}
contract-size:
concurrency:
group: contract-size-${{ github.ref }}
cancel-in-progress: true
runs-on: ubuntu-latest
needs: examples-builds
container:
image: ghcr.io/brushfam/openbrush-contracts-ci
options: --user root
env:
CARGO_TARGET_DIR: /usr/local/cache/target
steps:
- uses: actions/setup-node@v1
with:
node-version: '16.x'
- uses: actions/checkout@v3
- name: Cache rust artifacts for source branch
id: cache-rust-artifacts-source
uses: actions/cache@v3
with:
path: /usr/local/cache/target
key: cache-rust-artifacts-${{ hashFiles('Cargo.toml') }}-${{ github.ref }}
restore-keys: |
cache-rust-artifacts-${{ hashFiles('Cargo.toml') }}
- name: Install stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
default: true
target: wasm32-unknown-unknown
components: rust-src
- name: Find contract data for source branch
id: find-data-source
run: |
SOURCE_NAME=${{ github.head_ref }}
echo "SOURCE_NAME<<EOF" >> $GITHUB_ENV
echo "$SOURCE_NAME" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
SOURCE_DATA=$(find /usr/local/cache/target -maxdepth 2 -type f -name "*.wasm" -printf '%s ' -exec basename \{} .wasm \; | sort -k2)
echo "SOURCE_DATA<<EOF" >> $GITHUB_ENV
echo "$SOURCE_DATA" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- uses: actions/checkout@v3
with:
ref: main
- name: NPM install dependencies for destination branch
run: |
npm i
npm i ts-node
- name: Install nightly for destination branch
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2023-01-01
override: true
default: true
target: wasm32-unknown-unknown
components: rust-src
- name: Cache rust artifacts for destination branch
id: cache-rust-artifacts-destination
uses: actions/cache@v3
with:
path: /usr/local/cache/target
key: cache-rust-artifacts-pr-${{ hashFiles('Cargo.toml') }}-${{ github.ref }}
restore-keys: |
cache-rust-artifacts-pr-${{ hashFiles('Cargo.toml') }}
- name: Typechain Compile examples for destination branch
run: |
chown -R root .
chmod -R a+rwx .
npm run build:release
- name: Find contract data destination branch
id: find-data-destination
run: |
DESTINATION_DATA=$(find /usr/local/cache/target/ink -maxdepth 1 -type f -name "*.wasm" -printf '%s ' -exec basename \{} .wasm \; | sort -k2)
echo "DESTINATION_DATA<<EOF" >> $GITHUB_ENV
echo "$DESTINATION_DATA" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- uses: actions/checkout@v3
- name: Create report
run: |
chmod +x "./.github/contracts_size.sh"
"./.github/contracts_size.sh"
shell: bash
- name: Find current PR
uses: jwalton/gh-find-current-pr@v1
id: find-current-pr
with:
state: open
- name: Find Comment
uses: peter-evans/find-comment@v2
id: find-comment
with:
issue-number: ${{ steps.find-current-pr.outputs.pr }}
comment-author: 'github-actions[bot]'
- name: Create comment
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ steps.find-current-pr.outputs.pr }}
edit-mode: replace
body: |
${{ env.REPORT }}
integration-tests:
concurrency:
group: integration-tests-${{ github.ref }}
cancel-in-progress: true
runs-on: ubuntu-latest
needs: examples-builds
container:
image: ghcr.io/brushfam/openbrush-contracts-ci
options: --user root
env:
CARGO_TARGET_DIR: /usr/local/cache/target
steps:
- uses: actions/setup-node@v1
with:
node-version: '16.x'
- uses: actions/checkout@v3
- name: Install stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
default: true
target: wasm32-unknown-unknown
components: rust-src
- name: Run Test
run: |
./e2e-tests.sh ./examples/** ./examples
typechain-e2e-tests:
concurrency:
group: typechain-e2e-tests-${{ github.ref }}
cancel-in-progress: true
runs-on: ubuntu-latest
needs: examples-builds
container:
image: ghcr.io/brushfam/openbrush-contracts-ci
options: --user root
env:
CARGO_TARGET_DIR: /usr/local/cache/target
steps:
- uses: actions/setup-node@v1
with:
node-version: '16.x'
- uses: actions/checkout@v3
- name: Install stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
default: true
target: wasm32-unknown-unknown
components: rust-src
- name: Yarn install dependencies
run: |
yarn
yarn add ts-node
- name: Cache contract artifacts
id: cache-contract-artifacts
uses: actions/cache@v3
with:
path: artifacts
key: cache-contract-artifacts-${{ github.sha }}
- name: Generate Typechain code
run:
yarn build:release:no-compile
- name: Run Test Mocha
run: |
for test in $(find tests -type f -regex ".*\.ts"); do
has_timeout=true
while $has_timeout
do
substrate-contracts-node --tmp --dev & P1=$!;
set +e;
output=$(yarn test:mocha-single ./$test || true);
set -e;
if echo $output | grep -q 'For async tests and hooks, ensure "done()" is called'; then
echo $output;
has_timeout=true
else
yarn test:mocha-single ./$test
has_timeout=false
fi
kill $P1;
done
done