-
Notifications
You must be signed in to change notification settings - Fork 50
355 lines (312 loc) · 12.5 KB
/
e2e-test.yml
File metadata and controls
355 lines (312 loc) · 12.5 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
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
name: e2e-test
on:
schedule:
# Every weekday (Mon–Fri) at 02:00 UTC
- cron: "0 2 * * 1-5"
workflow_dispatch:
inputs:
test_filters:
description: "Only execute these (space-separated) tests. Can be used in
conjunction with skip_tests"
required: false
skip_tests:
description:
"Space-separated list of tests to skip. Can be used in conjunction
with test_filters"
required: false
delay_deprovision_on_failure:
description: "Delay teardown by 1 hour on failure so you can SSH in to debug"
type: boolean
default: false
instance_type:
description: "Exoscale compute instance type"
type: choice
options:
- standard.medium
- standard.large
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
TEST_CRATE_DIR: nym-vpn-core/crates/test
DEFAULT_INSTANCE_TYPE: standard.medium
jobs:
build:
name: Build test binaries
runs-on: arc-linux-latest
steps:
- name: Checkout repo
uses: actions/checkout@v6
with:
fetch-depth: 1
- name: Dotenv Action
uses: xom9ikk/dotenv@v2.4.0
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_VERSION }}
targets: x86_64-unknown-linux-gnu
- name: Install Zig
uses: mlugg/setup-zig@v1
with:
version: 0.13.0
- name: Install cargo-zigbuild
run: cargo install --locked cargo-zigbuild
- name: Install system dependencies
run: |
sudo apt-get update && sudo apt-get install -y \
gcc make pkg-config \
libdbus-1-dev libmnl-dev libnftnl-dev \
libssl-dev libpcap-dev
- name: Install Protoc
uses: arduino/setup-protoc@v3
with:
version: "21.12"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Restore cargo registry cache
uses: actions/cache/restore@v5
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-cargo-${{ env.RUST_VERSION }}-${{ hashFiles('nym-vpn-core/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-${{ env.RUST_VERSION }}-
- name: Restore cargo build cache
uses: actions/cache/restore@v5
with:
path: nym-vpn-core/target/
key: ${{ runner.os }}-cargo-build-${{ env.RUST_VERSION }}-${{ hashFiles('nym-vpn-core/Cargo.lock') }}-${{ hashFiles('nym-vpn-core/**/*.rs') }}
restore-keys: |
${{ runner.os }}-cargo-build-${{ env.RUST_VERSION }}-${{ hashFiles('nym-vpn-core/Cargo.lock') }}-
${{ runner.os }}-cargo-build-${{ env.RUST_VERSION }}-
- name: Install Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GOLANG_VERSION}}
cache-dependency-path: wireguard/libwg/go.sum
- name: Build wireguard-go
run: ./wireguard/build-wireguard-go.sh
- name: Build nym-vpnc, nym-vpnd and nym-socks5-proxy
env:
CFLAGS_x86_64_unknown_linux_gnu: -I/usr/include/x86_64-linux-gnu
BINDGEN_EXTRA_CLANG_ARGS_x86_64_unknown_linux_gnu: -I/usr/include/x86_64-linux-gnu
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS: -L /usr/lib/x86_64-linux-gnu
run: cargo zigbuild --release --target x86_64-unknown-linux-gnu.2.36 -p nym-vpnc -p nym-vpnd -p nym-socks5-proxy
working-directory: nym-vpn-core
- name: Build test-manager, test-runner
env:
CFLAGS_x86_64_unknown_linux_gnu: -I/usr/include/x86_64-linux-gnu
BINDGEN_EXTRA_CLANG_ARGS_x86_64_unknown_linux_gnu: -I/usr/include/x86_64-linux-gnu
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS: -L /usr/lib/x86_64-linux-gnu
run: |
cargo zigbuild --release --target x86_64-unknown-linux-gnu.2.36 \
-p test-manager -p test-runner
working-directory: ${{ env.TEST_CRATE_DIR }}
- name: Save cargo registry cache
if: always()
uses: actions/cache/save@v5
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-cargo-${{ env.RUST_VERSION }}-${{ hashFiles('nym-vpn-core/Cargo.lock') }}
- name: Save cargo build cache
if: always()
uses: actions/cache/save@v5
with:
path: nym-vpn-core/target/
key: ${{ runner.os }}-cargo-build-${{ env.RUST_VERSION }}-${{ hashFiles('nym-vpn-core/Cargo.lock') }}-${{ hashFiles('nym-vpn-core/**/*.rs') }}
- name: Save Go modules cache
if: always()
uses: actions/cache/save@v5
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
- name: Collect binaries
run: |
mkdir -p /tmp/dist
cp nym-vpn-core/target/x86_64-unknown-linux-gnu/release/nym-vpnc /tmp/dist/
cp nym-vpn-core/target/x86_64-unknown-linux-gnu/release/nym-vpnd /tmp/dist/
cp nym-vpn-core/target/x86_64-unknown-linux-gnu/release/nym-socks5-proxy /tmp/dist/
cp nym-vpn-core/target/x86_64-unknown-linux-gnu/release/test-manager /tmp/dist/
cp nym-vpn-core/target/x86_64-unknown-linux-gnu/release/test-runner /tmp/dist/
- name: Upload binaries
uses: actions/upload-artifact@v7
with:
name: test-binaries
path: /tmp/dist/
retention-days: 3
e2e-test:
name: Run E2E tests
needs: build
runs-on: arc-linux-latest
env:
SSH_KEY_PATH: /tmp/exoscale_key
SSH_OPTS: "-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o
ConnectTimeout=10 -o ServerAliveInterval=30 -o ServerAliveCountMax=3"
VM_USER: ubuntu
VM_DIST_DIR: /home/ubuntu/dist
TF_DIR: nym-vpn-core/crates/test/ci
steps:
- name: Resolve instance type
id: instance-type
run: |
TYPE="${{ inputs.instance_type || env.DEFAULT_INSTANCE_TYPE }}"
echo "value=$TYPE" >> "$GITHUB_OUTPUT"
- name: Checkout repo
uses: actions/checkout@v6
with:
fetch-depth: 1
- name: Download binaries
uses: actions/download-artifact@v8
with:
name: test-binaries
path: /tmp/dist
- name: Make binaries executable
run: chmod +x /tmp/dist/*
- name: Setup SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.EXOSCALE_SSH_PRIVATE_KEY }}" > ${{ env.SSH_KEY_PATH }}
chmod 600 ${{ env.SSH_KEY_PATH }}
- name: Setup Terraform
uses: hashicorp/setup-terraform@v4
with:
terraform_wrapper: false
- name: Terraform init
working-directory: ${{ env.TF_DIR }}
run: terraform init
- name: Terraform apply
working-directory: ${{ env.TF_DIR }}
env:
TF_VAR_exoscale_api_key: ${{ secrets.EXOSCALE_API_KEY }}
TF_VAR_exoscale_api_secret: ${{ secrets.EXOSCALE_API_SECRET }}
TF_VAR_data_volume_id: ${{ secrets.EXOSCALE_DATA_VOLUME_ID }}
TF_VAR_template_id: ${{ secrets.EXOSCALE_TEMPLATE_ID }}
TF_VAR_instance_type: ${{ steps.instance-type.outputs.value }}
TF_VAR_run_id: ${{ github.run_id }}
run: terraform apply -auto-approve
- name: Get VM IP
id: vm-ip
working-directory: ${{ env.TF_DIR }}
run: echo "ip=$(terraform output -raw instance_ip)" >> "$GITHUB_OUTPUT"
- name: Wait for SSH
env:
VM_IP: ${{ steps.vm-ip.outputs.ip }}
run: |
echo "Waiting for VM SSH to become available..."
for i in $(seq 1 30); do
if ssh ${{ env.SSH_OPTS }} -i ${{ env.SSH_KEY_PATH }} \
${{ env.VM_USER }}@${VM_IP} "echo ok" 2>/dev/null; then
echo "SSH is ready"
exit 0
fi
echo "Attempt $i/30 — waiting 10s..."
sleep 10
done
echo "ERROR: SSH never became available after 30 attempts"
exit 1
- name: SCP binaries and test script to VM
env:
VM_IP: ${{ steps.vm-ip.outputs.ip }}
run: |
ssh ${{ env.SSH_OPTS }} -i ${{ env.SSH_KEY_PATH }} \
${{ env.VM_USER }}@${VM_IP} "mkdir -p ${{ env.VM_DIST_DIR }}"
scp ${{ env.SSH_OPTS }} -i ${{ env.SSH_KEY_PATH }} \
/tmp/dist/* ${{ env.VM_USER }}@${VM_IP}:${{ env.VM_DIST_DIR }}/
scp ${{ env.SSH_OPTS }} -i ${{ env.SSH_KEY_PATH }} \
${{ env.TEST_CRATE_DIR }}/test-manager/test.sh \
${{ env.VM_USER }}@${VM_IP}:${{ env.VM_DIST_DIR }}/test.sh
- name: Configure test VM
env:
VM_IP: ${{ steps.vm-ip.outputs.ip }}
TEST_HARNESS_MNEMONIC: ${{ secrets.TEST_HARNESS_MAINNET_MNEMONIC }}
run: |
ssh ${{ env.SSH_OPTS }} -i ${{ env.SSH_KEY_PATH }} \
${{ env.VM_USER }}@${VM_IP} \
"NYM_TEST_QCOW_IMAGE=/mnt/data/fresh_debian12_cli.qcow2 \
NYM_TEST_VM_CONFIG=debian12_cli \
TEST_HARNESS_MNEMONIC='${TEST_HARNESS_MNEMONIC}' \
TEST_DIST_DIR=${{ env.VM_DIST_DIR }} \
bash ${{ env.VM_DIST_DIR }}/test.sh configure"
- name: Run E2E tests
timeout-minutes: 45
env:
VM_IP: ${{ steps.vm-ip.outputs.ip }}
TEST_HARNESS_MNEMONIC: ${{ secrets.TEST_HARNESS_MAINNET_MNEMONIC }}
TEST_FILTERS: ${{ inputs.test_filters }}
SKIP_TESTS: ${{ inputs.skip_tests }}
# escaping metacharacters so they become literal - to avoid shell injection in GH job input fields
run: |
SAFE_FILTERS=$(printf '%q' "$TEST_FILTERS")
SAFE_SKIP=$(printf '%q' "$SKIP_TESTS")
ssh ${{ env.SSH_OPTS }} -i ${{ env.SSH_KEY_PATH }} \
${{ env.VM_USER }}@${VM_IP} \
"NYM_TEST_QCOW_IMAGE=/mnt/data/fresh_debian12_cli.qcow2 \
NYM_TEST_VM_CONFIG=debian12_cli \
TEST_HARNESS_MNEMONIC='${TEST_HARNESS_MNEMONIC}' \
TEST_DIST_DIR=${{ env.VM_DIST_DIR }} \
TEST_REPORT=/tmp/test-report.txt \
TEST_FILTERS=${SAFE_FILTERS} \
SKIP_TESTS=${SAFE_SKIP} \
bash ${{ env.VM_DIST_DIR }}/test.sh run-tests"
- name: Retrieve test report
if: always()
env:
VM_IP: ${{ steps.vm-ip.outputs.ip }}
run: |
scp ${{ env.SSH_OPTS }} -i ${{ env.SSH_KEY_PATH }} \
${{ env.VM_USER }}@${VM_IP}:/tmp/test-report.txt /tmp/test-report.txt 2>/dev/null || \
echo "No test report found"
- name: Format test report
if: always()
run: |
if [ -f /tmp/test-report.txt ]; then
/tmp/dist/test-manager format-test-reports /tmp/test-report.txt > /tmp/test-report.html
cat /tmp/test-report.html >> "$GITHUB_STEP_SUMMARY"
else
echo "No test report file to format"
fi
- name: Upload test report
if: always()
uses: actions/upload-artifact@v7
with:
name: test-report
path: |
/tmp/test-report.txt
/tmp/test-report.html
if-no-files-found: warn
# repo maximum
retention-days: 20
- name: Delay deprovision for debugging
if: >-
always() && inputs.delay_deprovision_on_failure == true &&
steps.vm-ip.outputs.ip && job.status == 'failure'
env:
VM_IP: ${{ steps.vm-ip.outputs.ip }}
run: |
echo "Tests failed, keeping the VM around for 1 hour for debugging..."
echo "You can SSH into the VM at ${{ env.VM_USER }}@${VM_IP}"
echo "If you want to trigger VM deprovision earlier, cancel this workflow"
sleep 3600
- name: Terraform destroy
if: always()
working-directory: ${{ env.TF_DIR }}
env:
TF_VAR_exoscale_api_key: ${{ secrets.EXOSCALE_API_KEY }}
TF_VAR_exoscale_api_secret: ${{ secrets.EXOSCALE_API_SECRET }}
TF_VAR_data_volume_id: ${{ secrets.EXOSCALE_DATA_VOLUME_ID }}
TF_VAR_template_id: ${{ secrets.EXOSCALE_TEMPLATE_ID }}
TF_VAR_instance_type: ${{ steps.instance-type.outputs.value }}
TF_VAR_run_id: ${{ github.run_id }}
run: terraform destroy -auto-approve
- name: Cleanup SSH key
if: always()
run: rm -f ${{ env.SSH_KEY_PATH }}