-
Notifications
You must be signed in to change notification settings - Fork 87
311 lines (264 loc) · 9.56 KB
/
build-and-test.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
name: Build and run tests
on:
push:
branches:
- main
pull_request:
types: [ opened, synchronize, reopened, ready_for_review ]
branches:
- main
- 'epic/**'
- 'support/**'
paths:
- '.github/workflows/build-and-test.yml'
- '.github/actions/**'
- '**.rs'
- '**.toml'
- 'bindings/**'
- '!bindings/**.md'
- 'bindings/wasm/README.md' # the Readme contain txm tests
env:
RUST_BACKTRACE: full
CARGO_INCREMENTAL: 0 # disabled to reduce target cache size and improve sccache (https://github.com/mozilla/sccache#known-caveats)
SCCACHE_CACHE_SIZE: 2G
SCCACHE_IDLE_TIMEOUT: 0
# SCCACHE_RECACHE: 1 # uncomment to clear sccache cache, then re-comment
jobs:
check-for-run-condition:
runs-on: ubuntu-latest
outputs:
should-run: ${{ !github.event.pull_request || github.event.pull_request.draft == false }}
steps:
- run: |
# this run step does nothing, but is needed to get the job output
check-for-modification:
needs: check-for-run-condition
if: ${{ needs.check-for-run-condition.outputs.should-run == 'true' }}
runs-on: ubuntu-latest
outputs:
core-modified: ${{ steps.change-detection.outputs.core-modified }} # map step output to job output
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Run change detection
id: change-detection
run: |
echo comparing $(git rev-parse HEAD^) and $(git rev-parse HEAD)
#https://git-scm.com/docs/git-diff#Documentation/git-diff.txt-emgitdiffemltoptionsgt--ltpathgt82308203
if [[ $(git diff HEAD^ HEAD -- ':!bindings') != '' ]]; then
# modified
CORE_MODIFIED=true
else
# unmodified
CORE_MODIFIED=false
fi
echo CORE_MODIFIED=$CORE_MODIFIED
echo "core-modified=$CORE_MODIFIED" >> $GITHUB_OUTPUT
build-and-test:
runs-on: ${{ matrix.os }}
needs: [ check-for-run-condition, check-for-modification ]
if: ${{ needs.check-for-run-condition.outputs.should-run == 'true' && needs.check-for-modification.outputs.core-modified == 'true' }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
include:
- os: ubuntu-latest
sccache-path: /home/runner/.cache/sccache
- os: macos-latest
sccache-path: /Users/runner/Library/Caches/Mozilla.sccache
- os: windows-latest
sccache-path: C:\\Users\\runner\\AppData\\Local\\Mozilla\\sccache\\cache
env:
SCCACHE_DIR: ${{ matrix.sccache-path }}
RUSTC_WRAPPER: sccache
steps:
- uses: actions/checkout@v3
- name: Ensure, OpenSSL is available in Windows
if: matrix.os == 'windows-latest'
run: |
echo "VCPKG_ROOT=$env:VCPKG_INSTALLATION_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Append
vcpkg install openssl:x64-windows-static-md
- name: Setup Rust and cache
uses: './.github/actions/rust/rust-setup'
with:
os: ${{ runner.os }}
job: ${{ github.job }}
cargo-cache-enabled: true
target-cache-enabled: true
sccache-enabled: true
sccache-path: ${{ matrix.sccache-path }}
- name: Setup sccache
uses: './.github/actions/rust/sccache/setup-sccache'
with:
os: ${{matrix.os}}
- name: Check --no-default-features
if: matrix.os == 'ubuntu-latest'
run: |
cargo metadata --format-version 1 | \
jq -r '.workspace_members[]' | \
awk '{print $1}' | \
xargs -I {} cargo check -p {} --no-default-features
- name: Check default features
if: matrix.os == 'ubuntu-latest'
run: |
cargo metadata --format-version 1 | \
jq -r '.workspace_members[]' | \
awk '{print $1}' | \
xargs -I {} cargo check -p {}
# Clean debug target to avoid bloating the GitHub Actions cache.
# The previous builds cannot be re-used at all for the full --all-features --release build anyway.
- name: Clean target
if: matrix.os == 'ubuntu-latest'
run: cargo clean
# Build the library, tests, and examples without running them to avoid recompilation in the run tests step
- name: Build with default features
run: cargo build --workspace --tests --examples --release
- name: Start iota sandbox
if: matrix.os == 'ubuntu-latest'
uses: './.github/actions/iota-sandbox/setup'
- name: Run tests excluding `custom_time` feature
run: cargo test --workspace --release
- name: Run tests with `custom_time` feature
run: cargo test --test custom_time --features="custom_time"
- name: Run Rust examples
# run examples only on ubuntu for now
if: matrix.os == 'ubuntu-latest'
run: |
cargo metadata --format-version 1 --manifest-path ./examples/Cargo.toml | \
jq -r '.packages[] | select(.name == "examples") | .targets[].name' | \
awk '$1 ~ /[0-9].*/' | \
parallel -k -j 4 --retries 3 --joblog report.log ./target/release/examples/{}
cat report.log
- name: Run Rust Readme examples
# run examples only on ubuntu for now
if: matrix.os == 'ubuntu-latest'
run: |
cd bindings/wasm
npm ci
npm run test:readme:rust
- name: Tear down iota sandbox
if: matrix.os == 'ubuntu-latest' && always()
uses: './.github/actions/iota-sandbox/tear-down'
- name: Stop sccache
uses: './.github/actions/rust/sccache/stop-sccache'
with:
os: ${{matrix.os}}
build-wasm:
needs: check-for-run-condition
if: ${{ needs.check-for-run-condition.outputs.should-run == 'true' }}
# owner/repository of workflow has to be static, see https://github.community/t/env-variables-in-uses/17466
uses: iotaledger/identity.rs/.github/workflows/shared-build-wasm.yml@main
with:
output-artifact-name: identity-wasm-bindings-build
test-wasm:
needs: build-wasm
if: ${{ needs.check-for-run-condition.outputs.should-run == 'true' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
include:
- os: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: 16.x
- name: Install JS dependencies
run: npm ci
working-directory: bindings/wasm
- name: Download bindings/wasm artifacts
uses: actions/download-artifact@v4
with:
name: identity-wasm-bindings-build
path: bindings/wasm
- name: Start iota sandbox
uses: './.github/actions/iota-sandbox/setup'
- name: Run Wasm examples
run: npm run test:readme && npm run test:node
working-directory: bindings/wasm
- name: Tear down iota sandbox
if: always()
uses: './.github/actions/iota-sandbox/tear-down'
test-wasm-firefox:
needs: build-wasm
if: ${{ needs.check-for-run-condition.outputs.should-run == 'true' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
include:
- os: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: 16.x
- name: Install JS dependencies
run: npm ci
working-directory: bindings/wasm
- name: Download bindings/wasm artifacts
uses: actions/download-artifact@v4
with:
name: identity-wasm-bindings-build
path: bindings/wasm
- name: Start iota sandbox
uses: './.github/actions/iota-sandbox/setup'
- name: Build Docker image
uses: docker/[email protected]
with:
context: bindings/wasm/
file: bindings/wasm/cypress/Dockerfile
push: false
tags: cypress-test:latest
load: true
- name: Run cypress
run: docker run --network host cypress-test test:browser:parallel:firefox
- name: Tear down iota sandbox
if: always()
uses: './.github/actions/iota-sandbox/tear-down'
test-wasm-chrome:
needs: build-wasm
if: ${{ needs.check-for-run-condition.outputs.should-run == 'true' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
include:
- os: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: 16.x
- name: Install JS dependencies
run: npm ci
working-directory: bindings/wasm
- name: Download bindings/wasm artifacts
uses: actions/download-artifact@v4
with:
name: identity-wasm-bindings-build
path: bindings/wasm
- name: Start iota sandbox
uses: './.github/actions/iota-sandbox/setup'
- name: Build Docker image
uses: docker/[email protected]
with:
context: bindings/wasm/
file: bindings/wasm/cypress/Dockerfile
push: false
tags: cypress-test:latest
load: true
- name: Run cypress
run: docker run --network host cypress-test test:browser:parallel:chrome
- name: Tear down iota sandbox
if: always()
uses: './.github/actions/iota-sandbox/tear-down'