-
Notifications
You must be signed in to change notification settings - Fork 2
416 lines (374 loc) · 15.3 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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
name: CI
on:
pull_request:
push:
branches:
- main
concurrency:
group: ci-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
IROH_FORCE_STAGING_RELAYS: "1"
jobs:
build_and_test_nix:
name: Build and test
timeout-minutes: 30
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
name: [ubuntu-latest, macOS-arm-latest]
rust: [stable]
include:
- name: ubuntu-latest
os: ubuntu-latest
release-os: linux
release-arch: amd64
runner: [self-hosted, linux, X64]
- name: macOS-arm-latest
os: macOS-latest
release-os: darwin
release-arch: aarch64
runner: [self-hosted, macOS, ARM64]
steps:
- name: checkout
uses: actions/checkout@v4
- name: Install ${{ matrix.rust }} rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- name: install cargo-nextest
uses: taiki-e/install-action@v2
with:
tool: nextest
- name: run tests
run: |
cargo nextest run --all-features --lib --bins --tests --no-fail-fast
env:
RUST_LOG: "TRACE"
- name: build
run: |
cargo build --release
cargo run --features headers --bin generate_headers --release
- name: build test binary
run: |
cc -o main{,.c} -L target/release -l iroh_c_ffi -lc -lm
env:
LD_LIBRARY_PATH: target/release
- name: test run
id: run_tests
continue-on-error: true
env:
LD_LIBRARY_PATH: target/release
run: |
./main server --json > server_output.json &
server_pid=$!
# Wait for the server to start
sleep 10
# Read the second line of the file
line=$(sed -n '2p' server_output.json)
# Check if the line is empty
if [[ -z "$line" ]]; then
echo "Error: server_output.json does not have at least 2 lines"
echo "server_output.json:"
cat server_output.json
exit 1
fi
# Parse the JSON
json_output=$(echo $line | jq .)
# Store variables
node_id=$(echo $json_output | jq -r '.node_id')
relay=$(echo $json_output | jq -r '.relay')
addrs=$(echo $json_output | jq -r '.addrs[]')
./main client $node_id $relay ${addrs[@]}
sleep 10
# wait for server the shutdown
wait $server_pid
server_status=$?
echo ""
echo "Server closed with status $server_status"
if [[ "$server_status" != "0" ]]; then
exit 1
fi
# Read the 3rd line of the file
last_line=$(sed -n '3p' server_output.json)
# Parse the JSON
json_output=$(echo $last_line | jq -r '.data')
# Ensure json_output is as expected
if [[ "$json_output" != "hello world from C" ]]; then
echo "Error: Unexpected output for line 3"
echo "server_output.json:"
cat server_output.json
exit 1
fi
# Repeat for the 6th line of the file
last_line=$(sed -n '6p' server_output.json)
# Parse the JSON
json_output=$(echo $last_line | jq -r '.data')
# Ensure json_output is as expected
if [[ "$json_output" != "hello world from C" ]]; then
echo "Error: Unexpected output for line 6"
echo "server_output.json:"
cat server_output.json
exit 1
fi
echo ""
echo "Success"
echo "server_output.json:"
cat server_output.json
- name: Fail Job if Tests Failed
if: ${{ steps.run_tests.outcome == 'failure' }}
run: |
echo "Tests failed, server logs are:"
cat server_output.json
exit 1
- name: check headers
shell: bash
run: |
cp irohnet.h irohnet.h.orig
echo "Running generate_headers"
./target/release/generate_headers
echo "Generating diff of irohnet.h"
diff_output="$(diff irohnet.h irohnet.h.orig)" || true
echo "Checking diff"
# Check if the diff_output is not empty
if [ -n "$diff_output" ]; then
echo "Error: Differences were found compared to the checked in headers"
echo "$diff_output"
exit 1
fi
env:
CARGO_CRATE_NAME: iroh_c_ffi
build_and_test_windows:
name: Build and test
timeout-minutes: 30
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
name: [windows-latest]
rust: [stable]
target:
- x86_64-pc-windows-gnu
include:
- name: windows-latest
os: windows
runner: [self-hosted, windows, x64]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install ${{ matrix.rust }}
run: |
rustup toolchain install ${{ matrix.rust }}
rustup toolchain default ${{ matrix.rust }}
rustup target add ${{ matrix.target }}
rustup set default-host ${{ matrix.target }}
- name: Install cargo-nextest
shell: powershell
run: |
$tmp = New-TemporaryFile | Rename-Item -NewName { $_ -replace 'tmp$', 'zip' } -PassThru
Invoke-WebRequest -OutFile $tmp https://get.nexte.st/latest/windows
$outputDir = if ($Env:CARGO_HOME) { Join-Path $Env:CARGO_HOME "bin" } else { "~/.cargo/bin" }
$tmp | Expand-Archive -DestinationPath $outputDir -Force
$tmp | Remove-Item
- uses: msys2/setup-msys2@v2
- name: run tests
run: |
cargo nextest run --all-features --lib --bins --tests --no-fail-fast
env:
RUST_LOG: "TRACE"
- name: build
run: |
cargo build --release --target ${{ matrix.target }}
cargo run --features headers --bin generate_headers --release --target ${{ matrix.target }}
- name: build test binary
run: |
cp target/x86_64-pc-windows-gnu/release/iroh_c_ffi.dll iroh_c_ffi.dll
gcc -o main.exe main.c -L target/x86_64-pc-windows-gnu/release -liroh_c_ffi -lm -lkernel32 -ladvapi32 -lbcrypt -lntdll -luserenv -lws2_32 -lmsvcrt
env:
LD_LIBRARY_PATH: target/release
- name: test run
id: run_tests
continue-on-error: true
run: |
$server_process = Start-Process -PassThru -NoNewWindow -FilePath "./main.exe" -ArgumentList "server", "--json" -RedirectStandardOutput "server_output.json"
# Wait for the server to start
Start-Sleep -Seconds 10
# Read the second line of the file
$line = Get-Content server_output.json | Select-Object -Index 1
# Check if the line is empty
if ([string]::IsNullOrEmpty($line)) {
Write-Output "Error: server_output.json does not have at least 2 lines"
exit 1
}
# Parse the JSON
$json_output = ConvertFrom-Json $line
# Store variables
$node_id = $json_output.node_id
$relay = $json_output.relay
$addrs = $json_output.addrs
& "./main" "client" $node_id $relay $addrs
# wait for the server process to terminate
Wait-Process -InputObject $server_process
# # ramfox: ExitCode in windows seems to not work in all environments. I've tried a few variations, but they all show the exitCode as Null. commenting this out for now.
# $exitCode = $server_process.ExitCode
# Write-Output ""
# Write-Output "Server process exited with code: $exitCode"
# if ($exitCode -ne 0) {
# exit 1
# }
# Read the 3rd line of the file
Write-Output "checking first data transfer:"
$last_line = Get-Content server_output.json | Select-Object -Index 2
# Parse the JSON
$json_output = ConvertFrom-Json $last_line
# Ensure json_output is as expected
if ($json_output.data -ne "hello world from C") {
Write-Output "Error: Unexpected output for line 3"
Write-Output $json_output
exit 1
}
Write-Output "checking second data transfer:"
# Repeat for the 6th line of the file
$last_line = Get-Content server_output.json | Select-Object -Index 5
# Parse the JSON
$json_output = ConvertFrom-Json $last_line
# Ensure json_output is as expected
if ($json_output.data -ne "hello world from C") {
Write-Output "Error: Unexpected output for line 6"
Write-Output $json_output
exit 1
}
Write-Output ""
Write-Output "Success"
Write-Output "server_output.json:"
Get-Content server_output.json
- name: Fail Job if Tests Failed
if: ${{ steps.run_tests.outcome == 'failure' }}
run: |
Write-Output "Tests failed, server logs are:"
Get-Content server_output.json
exit 1
android_build:
name: Android Build Only
timeout-minutes: 30
# runs-on: ubuntu-latest
runs-on: [self-hosted, linux, X64]
strategy:
fail-fast: false
matrix:
target:
- aarch64-linux-android
- armv7-linux-androideabi
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
target: ${{ matrix.target }}
- name: Install rustup target
run: rustup target add ${{ matrix.target }}
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- name: Setup Android SDK
uses: android-actions/setup-android@v3
- name: Setup Android NDK
uses: arqu/setup-ndk@main
id: setup-ndk
with:
ndk-version: r23
add-to-path: true
- name: Build
env:
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
run: |
cargo install cargo-ndk
cargo ndk --target ${{ matrix.target }} build
cross:
timeout-minutes: 30
name: Cross compile
runs-on: [self-hosted, linux, X64]
strategy:
fail-fast: false
matrix:
target:
- i686-unknown-linux-gnu
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Install rust stable
uses: dtolnay/rust-toolchain@stable
- name: Cleanup Docker
continue-on-error: true
run: |
docker kill $(docker ps -q)
- name: Install cross
# See https://github.com/cross-rs/cross/issues/1222
run: cargo install cross --git https://github.com/cross-rs/cross
- name: build
# cross tests are currently broken vor armv7 and aarch64
# see https://github.com/cross-rs/cross/issues/1311. So on
# those platforms we only build but do not run tests.
if: matrix.target != 'i686-unknown-linux-gnu'
run: cross build --all --target ${{ matrix.target }}
env:
RUST_LOG: ${{ runner.debug && 'DEBUG' || 'INFO'}}
- name: test
# cross tests are currently broken for armv7 and aarch64
# see https://github.com/cross-rs/cross/issues/1311
if: matrix.target == 'i686-unknown-linux-gnu'
run: cross test --all --target ${{ matrix.target }} -- --test-threads=12
env:
RUST_LOG: ${{ runner.debug && 'DEBUG' || 'INFO'}}
cargo_deny:
timeout-minutes: 30
name: cargo deny
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: EmbarkStudios/cargo-deny-action@v1
with:
command: check advisories bans licenses sources
check_fmt_and_docs:
timeout-minutes: 30
name: Checking fmt and docs
runs-on: ubuntu-latest
env:
RUSTC_WRAPPER: "sccache"
SCCACHE_GHA_ENABLED: "on"
steps:
- uses: actions/checkout@master
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Install sccache
uses: mozilla-actions/[email protected]
- name: fmt
run: cargo fmt --all -- --check
- name: Docs
run: cargo doc --workspace --all-features --no-deps --document-private-items
clippy_check:
timeout-minutes: 30
runs-on: ubuntu-latest
env:
RUSTC_WRAPPER: "sccache"
SCCACHE_GHA_ENABLED: "on"
steps:
- uses: actions/checkout@master
- uses: dtolnay/rust-toolchain@stable
- name: Install sccache
uses: mozilla-actions/[email protected]
# TODO: We have a bunch of platform-dependent code so should
# probably run this job on the full platform matrix
- name: clippy check (all features)
run: cargo clippy --workspace --all-features --all-targets --bins --tests --benches
- name: clippy check (no features)
run: cargo clippy --workspace --no-default-features --lib --bins --tests
- name: clippy check (default features)
run: cargo clippy --workspace --all-targets