-
Notifications
You must be signed in to change notification settings - Fork 26
469 lines (437 loc) · 17.4 KB
/
Copy pathtest.yml
File metadata and controls
469 lines (437 loc) · 17.4 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
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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
name: Test
on:
push: {}
workflow_dispatch:
inputs:
pr_head_repo:
description: "Fork repository containing the PR commit"
required: false
type: string
pr_head_sha:
description: "Exact PR commit to test"
required: false
type: string
# Every branch push triggers a full run and superseded runs used to keep
# running, holding self-hosted slots that every repo on the shared pool
# queues behind. Group by ref so a newer push cancels the older run for
# that branch. main and workflow_dispatch runs get run_id, a unique group
# each, because sharing a group is unsafe even with cancellation off:
# GitHub cancels an existing pending run when a newer one enters the
# group, which would drop a commit's only test signal.
concurrency:
group: test-${{ (github.event_name == 'push' && github.ref != 'refs/heads/main') && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'push' && github.ref != 'refs/heads/main' }}
# A slash-command dispatch supplies a fork repository and immutable commit SHA.
# Normal push runs use the upstream repository and pushed ref.
env:
TEST_PR_HEAD_REPO: ${{ inputs.pr_head_repo || github.repository }}
TEST_SOURCE_REPO: ${{ inputs.pr_head_repo || github.repository }}
TEST_SOURCE_REF: ${{ inputs.pr_head_sha || github.ref }}
permissions:
contents: read
jobs:
test:
runs-on: [self-hosted, linux, x64, kvm]
steps:
- uses: actions/checkout@v4
with:
clean: false
repository: ${{ env.TEST_SOURCE_REPO }}
ref: ${{ env.TEST_SOURCE_REF }}
persist-credentials: false
- name: Clean workspace (preserve binary caches)
run: |
git reset --hard HEAD
git clean -ffdx \
-e lib/vmm/binaries/ \
-e lib/hypervisor/firecracker/binaries/ \
-e lib/ingress/binaries/ \
-e bin/
- name: Set up Go
uses: actions/setup-go@v6
with:
# Not necessary to upload cache on self-hosted runner(s)
# ~/go/pkg/mod and ~/.cache/go-build stay on disk between runs automatically.
cache: false
go-version: '1.25.4'
- name: Check UFFD pager version
run: |
git fetch "https://github.com/${{ github.repository }}.git" main --depth=1
bash scripts/check-uffd-version.sh FETCH_HEAD
- name: Install dependencies
run: |
set -xe
apt_update_with_retry() {
local attempts=5
local sleep_seconds=30
local n=1
while [ "$n" -le "$attempts" ]; do
if timeout 120s sudo apt-get update; then
return 0
fi
if [ "$n" -eq "$attempts" ]; then
return 1
fi
echo "apt-get update failed (attempt ${n}/${attempts}); retrying in ${sleep_seconds}s..."
sleep "$sleep_seconds"
n=$((n + 1))
done
}
if ! command -v mkfs.erofs &> /dev/null || \
! command -v mkfs.ext4 &> /dev/null || \
! command -v iptables &> /dev/null || \
! command -v qemu-system-x86_64 &> /dev/null || \
! qemu-system-x86_64 --version >/dev/null 2>&1; then
apt_update_with_retry
timeout 300s sudo apt-get install -y erofs-utils e2fsprogs iptables qemu-system-x86 qemu-utils
fi
go mod download
- name: Verify Linux test toolchain
run: |
set -euo pipefail
TEST_PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH"
for bin in mkfs.erofs mkfs.ext4 iptables qemu-system-x86_64; do
if ! sudo env "PATH=$TEST_PATH" bash -lc "command -v '$bin' >/dev/null"; then
echo "missing required binary under sudo PATH: $bin"
exit 1
fi
sudo env "PATH=$TEST_PATH" bash -lc "command -v '$bin'"
done
# Slash-command runs are maintainer-approved and need authenticated pulls
# for images that are not covered by the prewarm cache.
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Generate OpenAPI code
run: make oapi-generate
- name: Download Cloud Hypervisor binaries
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
for version in v49.0 v51.1; do
for architecture in x86_64 aarch64; do
if [ "$architecture" = "x86_64" ]; then
asset="cloud-hypervisor-static"
file_pattern='x86-64'
else
asset="cloud-hypervisor-static-aarch64"
file_pattern='aarch64|ARM aarch64'
fi
destination="lib/vmm/binaries/cloud-hypervisor/$version/$architecture/cloud-hypervisor"
mkdir -p "$(dirname "$destination")"
gh release download "$version" \
--repo cloud-hypervisor/cloud-hypervisor \
--pattern "$asset" \
--output "$destination" \
--clobber
chmod +x "$destination"
file "$destination" | grep -Eiq "$file_pattern"
done
done
- name: Build
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
for attempt in 1 2 3; do
if make build; then
exit 0
fi
if [ "$attempt" -lt 3 ]; then
echo "build failed (attempt ${attempt}/3); retrying in 10 seconds..."
sleep 10
fi
done
exit 1
- name: Install UFFD pager systemd template
run: |
sudo mkdir -p /run/hypeman/uffd
sudo tee /etc/systemd/system/hypeman-uffd@.service > /dev/null <<'EOF'
[Unit]
Description=Hypeman UFFD Pager (%i)
Documentation=https://github.com/kernel/hypeman
After=network.target
[Service]
Type=simple
Environment="HYPEMAN_UFFD_BINARY=/opt/hypeman/bin/hypeman-uffd-pager"
Environment="HYPEMAN_UFFD_DATA_DIR=/var/lib/hypeman"
Environment="HYPEMAN_UFFD_VERSION_KEY=%i"
Environment="HYPEMAN_UFFD_CACHE_MAX_BYTES=4294967296"
EnvironmentFile=-/run/hypeman/uffd/%i.env
ExecStart=/bin/sh -c 'exec "$HYPEMAN_UFFD_BINARY" --data-dir "$HYPEMAN_UFFD_DATA_DIR" --version-key "$HYPEMAN_UFFD_VERSION_KEY" --cache-max-bytes "$HYPEMAN_UFFD_CACHE_MAX_BYTES"'
Restart=on-failure
RestartSec=5
KillMode=process
EOF
sudo systemctl daemon-reload
- name: Prewarm test cache
env:
DOCKER_CONFIG: /home/debianuser/.docker
GITHUB_TOKEN: ${{ github.token }}
HYPEMAN_TEST_REGISTRY: 127.0.0.1:5001
run: |
# Prewarm cache must live on the same filesystem as the test TMPDIR
# (/ci): the image build symlinks the oci-cache from here into each
# per-test cache and builds rootfs there, and those operations are not
# cross-filesystem safe. Keeping both on /ci avoids that.
export HYPEMAN_TEST_PREWARM_DIR="/ci/prewarm/linux-amd64"
mkdir -p "$HYPEMAN_TEST_PREWARM_DIR"
sudo chown -R "$(id -u):$(id -g)" "$HYPEMAN_TEST_PREWARM_DIR"
for attempt in 1 2 3; do
if go run ./cmd/test-prewarm; then
exit 0
fi
if [ "$attempt" -lt 3 ]; then
echo "prewarm failed (attempt ${attempt}/3); retrying in 10 seconds..."
sleep 10
fi
done
exit 1
- name: Check gofmt
run: |
set -euo pipefail
go_files="$(git ls-files '*.go')"
if [ -z "$go_files" ]; then
exit 0
fi
unformatted="$(echo "$go_files" | xargs gofmt -l)"
if [ -n "$unformatted" ]; then
echo "The following files are not gofmt-formatted:"
echo "$unformatted"
exit 1
fi
- name: Run tests
env:
GO_TEST_TIMEOUT: 600s
GITHUB_TOKEN: ${{ github.token }}
# Docker auth for tests running as root (sudo)
DOCKER_CONFIG: /home/debianuser/.docker
# TLS/ACME testing (optional - tests will skip if not configured)
ACME_EMAIL: ${{ env.TEST_PR_HEAD_REPO == github.repository && secrets.ACME_EMAIL || '' }}
ACME_DNS_PROVIDER: "cloudflare"
ACME_CA: "https://acme-staging-v02.api.letsencrypt.org/directory"
CLOUDFLARE_API_TOKEN: ${{ env.TEST_PR_HEAD_REPO == github.repository && secrets.CLOUDFLARE_API_TOKEN || '' }}
TLS_TEST_DOMAIN: "test.hypeman-development.com"
TLS_ALLOWED_DOMAINS: '*.hypeman-development.com'
HYPEMAN_TEST_PREWARM_STRICT: "1"
HYPEMAN_TEST_REFLINK_STRICT: "1"
HYPEMAN_TEST_REGISTRY: 127.0.0.1:5001
HYPEMAN_UFFD_PAGER_BINARY: ${{ runner.temp }}/hypeman-uffd-pager-${{ github.run_id }}-${{ github.run_attempt }}
HYPEMAN_UFFD_SYSTEMD_INSTANCE_PREFIX: ci-${{ github.run_id }}-${{ github.run_attempt }}
# Fast scratch filesystem provisioned on the runner. Must be reflink-capable
# (the VM disk fork fast path uses FICLONE) and kept short to stay under the
# 108-char AF_UNIX sun_path limit for VMM control sockets.
TMPDIR: /ci
run: |
cp "$PWD/bin/hypeman-uffd-pager" "$HYPEMAN_UFFD_PAGER_BINARY"
chmod +x "$HYPEMAN_UFFD_PAGER_BINARY"
export HYPEMAN_TEST_PREWARM_DIR="/ci/prewarm/linux-amd64"
make test TEST_TIMEOUT=20m
- name: Cleanup
if: always()
run: |
set -euo pipefail
run_prefix="ci-${{ github.run_id }}-${{ github.run_attempt }}"
guest_pids=()
mapfile -t vmm_pids < <(pgrep -x 'cloud-hyperviso|firecracker|qemu-system-.*' || true)
for pid in "${vmm_pids[@]}"; do
proc="/proc/$pid"
cmdline="$(cat "$proc/cmdline" 2>/dev/null | tr '\0' ' ' || true)"
if [[ "$cmdline" == *"/ci/"* ]] && sudo grep -zFqx "HYPEMAN_UFFD_SYSTEMD_INSTANCE_PREFIX=$run_prefix" "$proc/environ" 2>/dev/null; then
guest_pids+=("$pid")
fi
done
if (( ${#guest_pids[@]} > 0 )); then
echo "Stopping leftover test VMs: ${guest_pids[*]}"
sudo kill -TERM "${guest_pids[@]}" 2>/dev/null || true
sleep 2
for pid in "${guest_pids[@]}"; do
if sudo kill -0 "$pid" 2>/dev/null; then
sudo kill -KILL "$pid" 2>/dev/null || true
fi
done
fi
units="$(systemctl list-units --all --full --plain 'hypeman-uffd@ci-${{ github.run_id }}-${{ github.run_attempt }}-*.service' --no-legend | awk '{print $1}' || true)"
if [ -n "$units" ]; then
echo "$units" | xargs -r sudo systemctl stop || true
echo "$units" | xargs -r sudo systemctl reset-failed || true
fi
sudo rm -f /run/hypeman/uffd/ci-${{ github.run_id }}-${{ github.run_attempt }}-*.env
rm -f "${{ runner.temp }}/hypeman-uffd-pager-${{ github.run_id }}-${{ github.run_attempt }}"
test-darwin:
runs-on: [self-hosted, macos, arm64]
concurrency:
group: macos-ci-test-${{ inputs.pr_head_sha || github.ref }}
cancel-in-progress: true
env:
DATA_DIR: /tmp/hypeman-ci-${{ github.run_id }}
steps:
- uses: actions/checkout@v4
with:
repository: ${{ env.TEST_SOURCE_REPO }}
ref: ${{ env.TEST_SOURCE_REF }}
persist-credentials: false
- uses: actions/setup-go@v6
with:
go-version: '1.25.4'
cache: false
- name: Ensure Docker is running
run: |
if docker info >/dev/null 2>&1; then
exit 0
fi
if colima status >/dev/null 2>&1; then
colima stop --force || true
fi
if ! colima start; then
colima stop --force || true
if ! colima start; then
colima delete --force
colima start
fi
fi
for attempt in {1..30}; do
if docker info >/dev/null 2>&1; then
exit 0
fi
echo "waiting for Docker daemon (${attempt}/30)"
sleep 2
done
docker info
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Install dependencies
run: |
brew list e2fsprogs &>/dev/null || brew install e2fsprogs
brew list erofs-utils &>/dev/null || brew install erofs-utils
go mod download
- name: Create run-scoped data directory
run: mkdir -p "$DATA_DIR"
- name: Generate OpenAPI code
run: make oapi-generate
- name: Build
env:
GITHUB_TOKEN: ${{ github.token }}
run: make build
- name: Prewarm test cache
env:
GITHUB_TOKEN: ${{ github.token }}
HYPEMAN_TEST_REGISTRY: 127.0.0.1:5001
run: |
export HYPEMAN_TEST_PREWARM_DIR="$HOME/.cache/hypeman-ci/darwin-arm64"
go run ./cmd/test-prewarm
- name: Check gofmt
run: |
set -euo pipefail
go_files="$(git ls-files '*.go')"
if [ -z "$go_files" ]; then
exit 0
fi
unformatted="$(echo "$go_files" | xargs gofmt -l)"
if [ -n "$unformatted" ]; then
echo "The following files are not gofmt-formatted:"
echo "$unformatted"
exit 1
fi
- name: Run tests
env:
GO_TEST_TIMEOUT: 600s
DEFAULT_HYPERVISOR: vz
GITHUB_TOKEN: ${{ github.token }}
JWT_SECRET: ci-test-secret
HYPEMAN_TEST_PREWARM_STRICT: "1"
HYPEMAN_TEST_REGISTRY: 127.0.0.1:5001
run: |
export HYPEMAN_TEST_PREWARM_DIR="$HOME/.cache/hypeman-ci/darwin-arm64"
make test
- name: Run VZ builder integration test
env:
HYPEMAN_RUN_BUILDER_INTEGRATION_TEST: "1"
run: |
# Self-hosted runners retain Docker layers across jobs. Reclaim them so
# the builder image and two VZ builds have predictable disk headroom.
docker system prune --all --force --volumes
PATH="/opt/homebrew/opt/e2fsprogs/sbin:$PATH" \
go test -count=1 -tags containers_image_openpgp \
-run='^TestBuilderPersistentCacheReuse$' -timeout=20m -v ./integration
- name: Cleanup
if: always()
run: |
pkill -f "vz-shim.*$DATA_DIR" || true
rm -rf "$DATA_DIR"
make clean
e2e-install:
runs-on: [self-hosted, macos, arm64]
needs: test-darwin
concurrency:
group: macos-ci-e2e-${{ inputs.pr_head_sha || github.ref }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v4
with:
repository: ${{ env.TEST_SOURCE_REPO }}
ref: ${{ env.TEST_SOURCE_REF }}
persist-credentials: false
- uses: actions/setup-go@v6
with:
go-version: '1.25.4'
cache: false
- name: Install dependencies
run: |
brew list caddy &>/dev/null || brew install caddy
if ! docker info >/dev/null 2>&1; then
colima start || {
colima stop --force || true
colima start
}
fi
for attempt in {1..30}; do
if docker info >/dev/null 2>&1; then
break
fi
echo "waiting for Docker daemon (${attempt}/30)"
sleep 2
done
docker info >/dev/null
# Self-hosted runners retain Docker layers across jobs. Start the
# install E2E with deterministic headroom for its builder image.
docker system prune --all --force --volumes
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build E2E install artifacts
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
make sign-darwin
cp bin/hypeman bin/hypeman-api
go build -o bin/hypeman-token ./cmd/gen-jwt
cp config.example.darwin.yaml bin/
docker build -t hypeman/builder:latest \
-f lib/builds/images/generic/Dockerfile .
- name: Run E2E install test
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
curl -fsSL --retry 5 --retry-all-errors \
"https://raw.githubusercontent.com/${{ github.repository }}/${{ github.sha }}/scripts/e2e-install-test.sh" \
-o "$RUNNER_TEMP/e2e-install-test.sh"
HYPEMAN_E2E_REPO_DIR="$PWD" BINARY_DIR="$PWD/bin" \
bash "$RUNNER_TEMP/e2e-install-test.sh"
- name: Run E2E CLI-only install test
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
CLI_DIR="$(mktemp -d)"
INSTALL_DIR="$CLI_DIR" bash scripts/install-cli.sh
"$CLI_DIR/hypeman" --version
- name: Cleanup on failure
if: failure()
run: bash scripts/uninstall.sh || true