-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.yml
More file actions
416 lines (388 loc) · 16.1 KB
/
Copy pathaction.yml
File metadata and controls
416 lines (388 loc) · 16.1 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
name: BPFCompat eBPF Compatibility Gate
author: Kernel Guard
description: Validate eBPF .bpf.o artifacts across Linux kernel profiles and fail CI on compatibility regressions.
inputs:
suite:
description: Optional suite YAML. When set, the action runs bpfcompat suite instead of single-artifact mode.
required: false
default: ""
artifact:
description: "Local path to a compiled .bpf.o artifact, or a remote OCI reference the CLI pulls (for example ghcr.io/org/gadget:latest, host:port/repo, or an @sha256: digest)."
required: false
default: ""
command:
description: "Command-mode validation: shell command run as root inside each kernel VM; the per-kernel verdict is its exit code. Use instead of (or alongside) artifact to validate via your project's own loader binary. Exposes $BPFCOMPAT_BIN, $BPFCOMPAT_ARTIFACT, and $BPFCOMPAT_REMOTE_ROOT."
required: false
default: ""
command-binary:
description: Local loader executable shipped into each guest and exposed to command as $BPFCOMPAT_BIN.
required: false
default: ""
command-expect-exit:
description: Exit code that counts as a pass in command mode.
required: false
default: "0"
disk-resize:
description: "Grow each guest overlay disk by N GiB before boot (cloud-init growpart expands it). Use for command-mode lanes that install a toolchain or build inside near-full cloud images. 0 (default) leaves the image size unchanged."
required: false
default: "0"
matrix:
description: "Path to matrix YAML. A bare name (for example quirk-library) that does not exist in the caller repository resolves to the matching matrices/<name>.yaml shipped with the action."
required: false
default: ""
out:
description: Path to JSON report output.
required: false
default: ""
suite-out:
description: Path to suite JSON summary output when suite mode is used.
required: false
default: "reports/bpfcompat-suite.json"
suite-markdown:
description: Path to suite Markdown summary output when suite mode is used.
required: false
default: "reports/bpfcompat-suite.md"
manifest:
description: Path to manifest YAML.
required: false
default: ""
validation-mode:
description: "Optional single-artifact validation mode: load_only, load_attach, or behavior. Suite mode should set validation_mode inside the suite YAML."
required: false
default: ""
markdown:
description: Path to Markdown report output.
required: false
default: ""
timeout:
description: Per-target timeout (for example 180s, 8m).
required: false
default: "180s"
workdir:
description: Working directory root.
required: false
default: ".bpfcompat"
concurrency:
description: Maximum concurrent VM jobs.
required: false
default: "2"
keep-vm-on-failure:
description: Keep VM overlays/logs on target failure.
required: false
default: "false"
build:
description: Build ./bin/bpfcompat with make before running tests.
required: false
default: "true"
prebuilt:
description: Use prebuilt release binaries when the action is pinned to a release tag or to a commit SHA that matches a release tag ("auto"), or always build from source ("never"). Downloads are checksum-checked and verified against GitHub build attestations; runners without gh build from source.
required: false
default: "auto"
binary:
description: Path to bpfcompat binary. Relative paths are resolved from the caller repository root.
required: false
default: "./bin/bpfcompat"
runs:
using: composite
steps:
- name: Download prebuilt binaries
id: prebuilt
if: ${{ inputs.prebuilt != 'never' }}
shell: bash
env:
ACTION_REF: ${{ github.action_ref }}
GITHUB_API_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
echo "resolved=false" >> "$GITHUB_OUTPUT"
ref="${ACTION_REF:-}"
if [[ "$ref" =~ ^[0-9a-f]{40}$ ]] && command -v jq >/dev/null 2>&1; then
# Pinned by commit SHA (the recommended way to pin third-party
# actions). Resolve the commit to the release tag that points at it
# so SHA-pinned consumers still get prebuilt binaries instead of
# silently requiring libbpf build deps on the runner. Any API
# hiccup or no matching tag falls through to the source build.
tags_json="$(curl -fsSL --retry 2 --connect-timeout 10 --max-time 60 \
-H "Authorization: Bearer ${GITHUB_API_TOKEN}" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/Kernel-Guard/bpfcompat/tags?per_page=100" || true)"
resolved_tag="$(printf '%s' "$tags_json" \
| jq -r --arg sha "$ref" \
'[.[] | select(.commit.sha == $sha) | .name | select(test("^v[0-9]"))][0] // empty' \
2>/dev/null || true)"
if [[ -n "$resolved_tag" ]]; then
echo "Commit ${ref} is release ${resolved_tag}; using its prebuilt binaries."
ref="$resolved_tag"
fi
fi
if [[ ! "$ref" =~ ^v[0-9] ]]; then
echo "Action not pinned to a release tag (ref: ${ref:-none}); building from source."
exit 0
fi
if [[ "$(uname -m)" != "x86_64" ]]; then
echo "No prebuilt binaries for $(uname -m); building from source."
exit 0
fi
base="https://github.com/Kernel-Guard/bpfcompat/releases/download/${ref}"
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
for asset in bpfcompat-linux-amd64 bpfcompat-validator-static-linux-amd64 SHA256SUMS; do
if ! curl -fsSL --retry 2 --connect-timeout 10 --max-time 300 \
-o "$tmp/$asset" "$base/$asset"; then
echo "Release asset $asset not available for ${ref}; building from source."
exit 0
fi
done
if ! command -v gh >/dev/null 2>&1 || ! gh attestation --help >/dev/null 2>&1; then
echo "GitHub CLI attestation verification is unavailable; building from the pinned Action source instead of using unverifiable prebuilt binaries."
exit 0
fi
# A failed verification is a hard error, not a fallback: assets exist
# but do not match what the release workflow published or attested.
GH_TOKEN="$GITHUB_API_TOKEN" bash \
"$GITHUB_ACTION_PATH/scripts/verify-release-assets.sh" \
"$tmp" Kernel-Guard/bpfcompat \
bpfcompat-linux-amd64 bpfcompat-validator-static-linux-amd64
mkdir -p "$GITHUB_ACTION_PATH/bin" "$GITHUB_ACTION_PATH/validator/c-libbpf/bin"
install -m 0755 "$tmp/bpfcompat-linux-amd64" "$GITHUB_ACTION_PATH/bin/bpfcompat"
install -m 0755 "$tmp/bpfcompat-validator-static-linux-amd64" "$GITHUB_ACTION_PATH/validator/c-libbpf/bin/bpfcompat-validator"
echo "resolved=true" >> "$GITHUB_OUTPUT"
echo "Using prebuilt release binaries for ${ref}."
- name: Build bpfcompat
if: ${{ inputs.build == 'true' && steps.prebuilt.outputs.resolved != 'true' }}
shell: bash
run: |
set -euo pipefail
if [[ -z "${GITHUB_ACTION_PATH:-}" ]]; then
echo "::error::GITHUB_ACTION_PATH is not set"
exit 1
fi
pushd "$GITHUB_ACTION_PATH" >/dev/null
make build
make validator-static
popd >/dev/null
- name: Run bpfcompat
shell: bash
env:
# Free-text inputs go through the environment, never inline
# interpolation, so they cannot inject host-side shell syntax.
INPUT_COMMAND: ${{ inputs.command }}
INPUT_COMMAND_BINARY: ${{ inputs.command-binary }}
INPUT_COMMAND_EXPECT_EXIT: ${{ inputs.command-expect-exit }}
run: |
set -euo pipefail
workspace="${GITHUB_WORKSPACE:-$PWD}"
action_root="${GITHUB_ACTION_PATH:-$PWD}"
resolve_path() {
local input="$1"
if [[ -z "$input" ]]; then
echo ""
return
fi
if [[ "$input" = /* ]]; then
echo "$input"
else
echo "$workspace/$input"
fi
}
# An artifact is either a local .bpf.o path or a remote OCI reference
# the CLI pulls itself (ghcr.io/org/gadget:latest, host:port/repo,
# localhost/..., or an @sha256: digest). A remote ref must bypass path
# resolution and the local-file existence check below — otherwise it is
# mangled into "$workspace/ghcr.io/..." and rejected as "not found".
# Host detection follows the OCI/Docker rule: the segment before the
# first "/" is a registry host if it contains "." or ":" or is localhost.
is_remote_artifact() {
local a="$1"
case "$a" in
*://* | *@sha256:*) return 0 ;;
esac
local first="${a%%/*}"
case "$first" in
"" | "." | "..") return 1 ;;
localhost | localhost:*) return 0 ;;
esac
if [[ "$a" == */* && ( "$first" == *.* || "$first" == *:* ) ]]; then
return 0
fi
return 1
}
artifact_input="${{ inputs.artifact }}"
artifact_is_remote=false
if [[ -n "$artifact_input" ]] && is_remote_artifact "$artifact_input"; then
artifact_path="$artifact_input"
artifact_is_remote=true
else
artifact_path="$(resolve_path "$artifact_input")"
fi
matrix_path="$(resolve_path "${{ inputs.matrix }}")"
command_binary_path="$(resolve_path "$INPUT_COMMAND_BINARY")"
# Built-in matrix convenience: a bare name (e.g. quirk-library) that
# does not exist in the caller repo resolves to the matrices/ directory
# shipped with the action.
if [[ -n "$matrix_path" && ! -f "$matrix_path" ]]; then
matrix_input="${{ inputs.matrix }}"
if [[ "$matrix_input" != /* && -f "$action_root/matrices/${matrix_input}.yaml" ]]; then
matrix_path="$action_root/matrices/${matrix_input}.yaml"
elif [[ "$matrix_input" != /* && -f "$action_root/$matrix_input" ]]; then
matrix_path="$action_root/$matrix_input"
fi
fi
out_path="$(resolve_path "${{ inputs.out }}")"
manifest_path="$(resolve_path "${{ inputs.manifest }}")"
markdown_path="$(resolve_path "${{ inputs.markdown }}")"
workdir_path="$(resolve_path "${{ inputs.workdir }}")"
suite_path="$(resolve_path "${{ inputs.suite }}")"
suite_out_path="$(resolve_path "${{ inputs.suite-out }}")"
suite_markdown_path="$(resolve_path "${{ inputs.suite-markdown }}")"
binary_input="${{ inputs.binary }}"
binary_path=""
if [[ "$binary_input" = /* ]]; then
binary_path="$binary_input"
elif [[ -x "$workspace/$binary_input" ]]; then
binary_path="$workspace/$binary_input"
elif [[ -x "$action_root/$binary_input" ]]; then
binary_path="$action_root/$binary_input"
elif [[ -x "$action_root/bin/bpfcompat" ]]; then
binary_path="$action_root/bin/bpfcompat"
fi
if [[ -z "$binary_path" || ! -x "$binary_path" ]]; then
echo "::error::bpfcompat binary not found or not executable. Checked: $workspace/$binary_input, $action_root/$binary_input, $action_root/bin/bpfcompat"
exit 1
fi
if [[ -n "$suite_path" ]]; then
if [[ ! -f "$suite_path" ]]; then
echo "::error::suite file not found: $suite_path"
exit 1
fi
mkdir -p "$(dirname "$suite_out_path")"
if [[ -n "$suite_markdown_path" ]]; then
mkdir -p "$(dirname "$suite_markdown_path")"
fi
pushd "$action_root" >/dev/null
cmd=(
"$binary_path"
suite
--suite "$suite_path"
--out "$suite_out_path"
--timeout "${{ inputs.timeout }}"
--workdir "$workdir_path"
--concurrency "${{ inputs.concurrency }}"
)
if [[ -n "$suite_markdown_path" ]]; then
cmd+=(--markdown "$suite_markdown_path")
fi
echo "Running: ${cmd[*]}"
set +e
"${cmd[@]}"
status=$?
set -e
if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then
if [[ -f "$suite_markdown_path" ]]; then
cat "$suite_markdown_path" >>"$GITHUB_STEP_SUMMARY" || echo "::warning::failed to write bpfcompat suite summary"
else
{
echo
echo "# bpfcompat Compatibility Suite"
echo
echo "Suite run did not produce a Markdown summary. Check the action logs for setup or runner errors."
} >>"$GITHUB_STEP_SUMMARY" || true
fi
fi
popd >/dev/null
exit "$status"
fi
if [[ -z "$artifact_path" && -z "$INPUT_COMMAND" ]]; then
echo "::error::artifact or command is required unless suite is set"
exit 1
fi
if [[ -z "$matrix_path" ]]; then
echo "::error::matrix is required unless suite is set"
exit 1
fi
if [[ -z "$out_path" ]]; then
echo "::error::out is required unless suite is set"
exit 1
fi
if [[ -n "$artifact_path" && "$artifact_is_remote" != true && ! -f "$artifact_path" ]]; then
echo "::error::artifact not found: $artifact_path"
exit 1
fi
if [[ -n "$command_binary_path" && ! -f "$command_binary_path" ]]; then
echo "::error::command-binary not found: $command_binary_path"
exit 1
fi
if [[ -n "$command_binary_path" && -z "$INPUT_COMMAND" ]]; then
echo "::error::command-binary requires command"
exit 1
fi
if [[ ! -f "$matrix_path" ]]; then
echo "::error::matrix not found: $matrix_path"
exit 1
fi
mkdir -p "$(dirname "$out_path")"
if [[ -n "$markdown_path" ]]; then
mkdir -p "$(dirname "$markdown_path")"
fi
pushd "$action_root" >/dev/null
cmd=(
"$binary_path"
test
--matrix "$matrix_path"
--out "$out_path"
--timeout "${{ inputs.timeout }}"
--workdir "$workdir_path"
--concurrency "${{ inputs.concurrency }}"
)
if [[ -n "$artifact_path" ]]; then
cmd+=(--artifact "$artifact_path")
fi
if [[ -n "$INPUT_COMMAND" ]]; then
cmd+=(--command "$INPUT_COMMAND")
if [[ -n "$command_binary_path" ]]; then
cmd+=(--command-binary "$command_binary_path")
fi
if [[ -n "$INPUT_COMMAND_EXPECT_EXIT" && "$INPUT_COMMAND_EXPECT_EXIT" != "0" ]]; then
cmd+=(--command-expect-exit "$INPUT_COMMAND_EXPECT_EXIT")
fi
fi
if [[ -n "$manifest_path" ]]; then
cmd+=(--manifest "$manifest_path")
fi
if [[ -n "${{ inputs.disk-resize }}" && "${{ inputs.disk-resize }}" != "0" ]]; then
cmd+=(--disk-resize "${{ inputs.disk-resize }}")
fi
if [[ -n "${{ inputs.validation-mode }}" ]]; then
cmd+=(--validation-mode "${{ inputs.validation-mode }}")
fi
if [[ -n "$markdown_path" ]]; then
cmd+=(--markdown "$markdown_path")
fi
if [[ "${{ inputs.keep-vm-on-failure }}" == "true" ]]; then
cmd+=(--keep-vm-on-failure=true)
fi
echo "Running: ${cmd[*]}"
set +e
"${cmd[@]}"
status=$?
set -e
if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then
if [[ -f "$out_path" ]]; then
{
echo
"$binary_path" report-summary --report "$out_path" --max-targets 25 --max-failures 10
} >>"$GITHUB_STEP_SUMMARY" || echo "::warning::failed to write bpfcompat job summary"
else
{
echo
echo "# bpfcompat Compatibility Gate"
echo
echo "Validation did not produce a JSON report. Check the action logs for setup or runner errors."
} >>"$GITHUB_STEP_SUMMARY" || true
fi
fi
popd >/dev/null
exit "$status"
branding:
icon: shield
color: blue