| 1 |
name: ci |
| 2 |
on: |
| 3 |
push: |
| 4 |
branches: [ "main" ] |
| 5 |
pull_request: |
| 6 |
branches: [ "main" ] |
| 7 |
|
| 8 |
env: |
| 9 |
TMPDIR: /tmp |
| 10 |
CI_MAX_KERNEL_VERSION: '7.1' |
| 11 |
CI_MAX_EFW_VERSION: '1.0.0-rc2' |
| 12 |
CI_MIN_CLANG_VERSION: '13' |
| 13 |
go_version: '~1.26' |
| 14 |
prev_go_version: '~1.25' |
| 15 |
CGO_ENABLED: '0' |
| 16 |
|
| 17 |
python_version: '~3.13' |
| 18 |
|
| 19 |
concurrency: |
| 20 |
group: ${{ github.workflow }}-${{ github.ref }} |
| 21 |
cancel-in-progress: ${{ github.event_name == 'pull_request' }} |
| 22 |
|
| 23 |
jobs: |
| 24 |
build-and-lint: |
| 25 |
name: Build and Lint |
| 26 |
runs-on: ubuntu-22.04 |
| 27 |
timeout-minutes: 10 |
| 28 |
steps: |
| 29 |
- uses: actions/checkout@v6 |
| 30 |
|
| 31 |
- name: Set up Go |
| 32 |
uses: actions/setup-go@v6 |
| 33 |
with: |
| 34 |
go-version: '${{ env.go_version }}' |
| 35 |
|
| 36 |
- name: Run staticcheck |
| 37 |
run: | |
| 38 |
go tool staticcheck ./... |
| 39 |
|
| 40 |
- name: Run golangci-lint |
| 41 |
uses: golangci/[email protected] |
| 42 |
|
| 43 |
- name: Build |
| 44 |
run: go build -v ./... |
| 45 |
|
| 46 |
generate-and-fix: |
| 47 |
name: Generate and Fix |
| 48 |
runs-on: ubuntu-22.04 |
| 49 |
timeout-minutes: 10 |
| 50 |
steps: |
| 51 |
- uses: actions/checkout@v6 |
| 52 |
|
| 53 |
- name: Set up Go |
| 54 |
uses: actions/setup-go@v6 |
| 55 |
with: |
| 56 |
go-version: '${{ env.go_version }}' |
| 57 |
|
| 58 |
- name: Generate and format code |
| 59 |
run: | |
| 60 |
make clean && make container-all |
| 61 |
if ! git diff --exit-code; then |
| 62 |
echo "Found unformatted source files, or generated files are not up to date, run 'make'" >&2 |
| 63 |
exit 1 |
| 64 |
fi |
| 65 |
|
| 66 |
- name: Run go fix |
| 67 |
run: | |
| 68 |
./scripts/go-fix.sh |
| 69 |
if ! git diff --exit-code; then |
| 70 |
echo "Found Go files that need fixing, run './scripts/go-fix.sh'" >&2 |
| 71 |
exit 1 |
| 72 |
fi |
| 73 |
|
| 74 |
cross-build: |
| 75 |
name: Cross build |
| 76 |
runs-on: ubuntu-22.04 |
| 77 |
timeout-minutes: 10 |
| 78 |
steps: |
| 79 |
- uses: actions/checkout@v6 |
| 80 |
|
| 81 |
- name: Set up Go |
| 82 |
uses: actions/setup-go@v6 |
| 83 |
with: |
| 84 |
go-version: '${{ env.go_version }}' |
| 85 |
|
| 86 |
- name: Cross build darwin |
| 87 |
env: |
| 88 |
GOOS: darwin |
| 89 |
run: | |
| 90 |
go build -v ./... |
| 91 |
go test -c -o /dev/null ./... >/dev/null |
| 92 |
|
| 93 |
- name: Cross build arm32 |
| 94 |
env: |
| 95 |
GOARCH: arm |
| 96 |
GOARM: 6 |
| 97 |
run: | |
| 98 |
go build -v ./... |
| 99 |
go test -c -o /dev/null ./... >/dev/null |
| 100 |
|
| 101 |
- name: Cross build wasm |
| 102 |
env: |
| 103 |
GOOS: js |
| 104 |
GOARCH: wasm |
| 105 |
run: | |
| 106 |
go build -v ./... |
| 107 |
go test -c -o /dev/null ./... >/dev/null |
| 108 |
|
| 109 |
build-docs: |
| 110 |
name: Build Documentation |
| 111 |
runs-on: ubuntu-22.04 |
| 112 |
timeout-minutes: 10 |
| 113 |
steps: |
| 114 |
- uses: actions/checkout@v6 |
| 115 |
with: |
| 116 |
|
| 117 |
|
| 118 |
fetch-depth: 0 |
| 119 |
|
| 120 |
- name: Set up Go |
| 121 |
uses: actions/setup-go@v6 |
| 122 |
with: |
| 123 |
go-version: '${{ env.go_version }}' |
| 124 |
|
| 125 |
- name: Set up Python |
| 126 |
uses: actions/setup-python@v6 |
| 127 |
with: |
| 128 |
python-version: '${{ env.python_version }}' |
| 129 |
cache: 'pipenv' |
| 130 |
|
| 131 |
- name: Install pipenv |
| 132 |
run: pip3 install pipenv |
| 133 |
|
| 134 |
- name: Install Dependencies |
| 135 |
run: pipenv install |
| 136 |
working-directory: ./docs |
| 137 |
|
| 138 |
- name: Build Documentation |
| 139 |
run: make build |
| 140 |
working-directory: ./docs |
| 141 |
|
| 142 |
test-on-prev-go: |
| 143 |
name: Run tests on previous stable Go |
| 144 |
runs-on: ubuntu-latest |
| 145 |
timeout-minutes: 15 |
| 146 |
env: |
| 147 |
CI_KERNEL_SELFTESTS: '/usr/src/linux/tools/testing/selftests/bpf' |
| 148 |
steps: |
| 149 |
- uses: actions/checkout@v6 |
| 150 |
|
| 151 |
- name: Set up Go |
| 152 |
uses: actions/setup-go@v6 |
| 153 |
with: |
| 154 |
go-version: '${{ env.prev_go_version }}' |
| 155 |
|
| 156 |
- run: go install lmb.io/vimto@latest |
| 157 |
- run: go install gotest.tools/[email protected] |
| 158 |
|
| 159 |
- uses: awalsh128/[email protected] |
| 160 |
with: |
| 161 |
packages: qemu-system-x86 |
| 162 |
|
| 163 |
- run: sudo chmod 0666 /dev/kvm |
| 164 |
|
| 165 |
- name: Test |
| 166 |
env: |
| 167 |
GOTRACEBACK: crash |
| 168 |
CGO_ENABLED: 1 |
| 169 |
run: | |
| 170 |
gotestsum --raw-command --ignore-non-json-output-lines --junitfile junit.xml -- vimto -kernel :stable-selftests -- go test -race -timeout 5m -short -count 1 -json ./... |
| 171 |
|
| 172 |
- name: Upload coredumps |
| 173 |
uses: actions/upload-artifact@v7 |
| 174 |
if: ${{ failure() }} |
| 175 |
with: |
| 176 |
name: cores |
| 177 |
if-no-files-found: ignore |
| 178 |
path: | |
| 179 |
**/core-* |
| 180 |
**/*.test |
| 181 |
|
| 182 |
- name: Upload Test Results |
| 183 |
if: always() |
| 184 |
uses: actions/upload-artifact@v7 |
| 185 |
with: |
| 186 |
name: Test Results (previous stable Go) |
| 187 |
path: junit.xml |
| 188 |
|
| 189 |
test-on-arm64: |
| 190 |
name: Run tests on arm64 |
| 191 |
runs-on: ubuntu-24.04-arm64 |
| 192 |
timeout-minutes: 15 |
| 193 |
env: |
| 194 |
EBPF_TEST_IGNORE_VERSION: 'TestKprobeMulti,TestKprobeMultiErrors,TestKprobeMultiCookie,TestKprobeMultiProgramCall,TestHaveBPFLinkKprobeMulti,TestKprobeSession,TestHaveBPFLinkKprobeSession,TestHaveProgramType/LircMode2' |
| 195 |
steps: |
| 196 |
- uses: actions/checkout@v6 |
| 197 |
|
| 198 |
- name: Set up Go |
| 199 |
uses: actions/setup-go@v6 |
| 200 |
with: |
| 201 |
go-version: '${{ env.go_version }}' |
| 202 |
|
| 203 |
- run: go install gotest.tools/[email protected] |
| 204 |
|
| 205 |
- name: Test |
| 206 |
|
| 207 |
|
| 208 |
run: gotestsum --ignore-non-json-output-lines --junitfile junit.xml -- -exec 'sudo -E' -short -count 1 -skip '^TestGoarches/loong64$' -skip '^TestKfunc$' -json ./... |
| 209 |
|
| 210 |
- name: Benchmark |
| 211 |
run: go test -exec sudo -short -run '^$' -bench . -benchtime=1x ./... |
| 212 |
|
| 213 |
- name: Upload Test Results |
| 214 |
if: always() |
| 215 |
uses: actions/upload-artifact@v7 |
| 216 |
with: |
| 217 |
name: Test Results (arm64) |
| 218 |
path: junit.xml |
| 219 |
|
| 220 |
- name: Show dmesg |
| 221 |
if: failure() |
| 222 |
run: | |
| 223 |
sudo dmesg |
| 224 |
|
| 225 |
linux-test: |
| 226 |
name: Run tests (Linux) |
| 227 |
runs-on: ubuntu-latest |
| 228 |
needs: build-and-lint |
| 229 |
timeout-minutes: 15 |
| 230 |
strategy: |
| 231 |
matrix: |
| 232 |
tag: |
| 233 |
- "mainline" |
| 234 |
- "stable" |
| 235 |
- "6.12" |
| 236 |
- "6.6" |
| 237 |
- "6.1" |
| 238 |
- "5.15" |
| 239 |
- "5.10" |
| 240 |
- "5.4" |
| 241 |
steps: |
| 242 |
- uses: actions/checkout@v6 |
| 243 |
|
| 244 |
- name: Set up Go |
| 245 |
uses: actions/setup-go@v6 |
| 246 |
with: |
| 247 |
go-version: '${{ env.go_version }}' |
| 248 |
|
| 249 |
- run: go install gotest.tools/[email protected] |
| 250 |
- run: go install lmb.io/vimto@latest |
| 251 |
|
| 252 |
- uses: awalsh128/[email protected] |
| 253 |
with: |
| 254 |
packages: qemu-system-x86 |
| 255 |
|
| 256 |
- run: sudo chmod 0666 /dev/kvm |
| 257 |
|
| 258 |
- name: Test |
| 259 |
run: gotestsum --raw-command --ignore-non-json-output-lines --junitfile junit.xml -- vimto -kernel :${{ matrix.tag }} -- go test -short -count 1 -json ./... |
| 260 |
|
| 261 |
- name: Upload Test Results |
| 262 |
if: always() |
| 263 |
uses: actions/upload-artifact@v7 |
| 264 |
with: |
| 265 |
name: Test Results (linux ${{ matrix.tag }}) |
| 266 |
path: junit.xml |
| 267 |
|
| 268 |
linux-benchmark: |
| 269 |
name: Run benchmarks (Linux) |
| 270 |
runs-on: ubuntu-latest |
| 271 |
needs: build-and-lint |
| 272 |
timeout-minutes: 15 |
| 273 |
steps: |
| 274 |
- uses: actions/checkout@v6 |
| 275 |
|
| 276 |
- name: Set up Go |
| 277 |
uses: actions/setup-go@v6 |
| 278 |
with: |
| 279 |
go-version: '${{ env.go_version }}' |
| 280 |
|
| 281 |
- run: go install lmb.io/vimto@latest |
| 282 |
|
| 283 |
- uses: awalsh128/[email protected] |
| 284 |
with: |
| 285 |
packages: qemu-system-x86 |
| 286 |
|
| 287 |
- run: sudo chmod 0666 /dev/kvm |
| 288 |
|
| 289 |
- name: Benchmark |
| 290 |
run: vimto -kernel :stable-selftests -- go test -short -run '^$' -bench . -benchtime=1x ./... |
| 291 |
|
| 292 |
windows-test: |
| 293 |
name: Run tests (Windows) |
| 294 |
runs-on: windows-2022 |
| 295 |
needs: build-and-lint |
| 296 |
timeout-minutes: 15 |
| 297 |
strategy: |
| 298 |
matrix: |
| 299 |
version: |
| 300 |
- "main" |
| 301 |
- "1.0.0-rc1" |
| 302 |
env: |
| 303 |
|
| 304 |
|
| 305 |
GOCACHE: D:\gocache |
| 306 |
GOMODCACHE: D:\gomodcache |
| 307 |
|
| 308 |
TEMP: D:\temp |
| 309 |
CI_EFW_VERSION: "0.21.0" |
| 310 |
|
| 311 |
steps: |
| 312 |
- run: mkdir D:\temp |
| 313 |
shell: pwsh |
| 314 |
|
| 315 |
- name: Download eBPF for Windows |
| 316 |
uses: actions/github-script@v9 |
| 317 |
with: |
| 318 |
script: | |
| 319 |
if ("${{ matrix.version }}" != "main") { |
| 320 |
// Use version from matrix to fetch from release |
| 321 |
const version = "${{ matrix.version }}"; |
| 322 |
const releaseTag = `Release-v${version}`; |
| 323 |
|
| 324 |
console.log(`Fetching release: ${releaseTag}`); |
| 325 |
|
| 326 |
// Get the release by tag |
| 327 |
const release = await github.rest.repos.getReleaseByTag({ |
| 328 |
owner: 'microsoft', |
| 329 |
repo: 'ebpf-for-windows', |
| 330 |
tag: releaseTag |
| 331 |
}); |
| 332 |
|
| 333 |
if (!release.data) { |
| 334 |
core.setFailed(`Release ${releaseTag} not found`); |
| 335 |
return; |
| 336 |
} |
| 337 |
|
| 338 |
console.log(`Found release: ${release.data.name}`); |
| 339 |
|
| 340 |
// Find the Build.Debug.x64.zip asset |
| 341 |
const assetName = 'Build.Debug.x64.zip'; |
| 342 |
const asset = release.data.assets.find(a => a.name === assetName); |
| 343 |
|
| 344 |
if (!asset) { |
| 345 |
console.log('Available assets:', release.data.assets.map(a => a.name)); |
| 346 |
core.setFailed(`${assetName} asset not found in release ${releaseTag}`); |
| 347 |
return; |
| 348 |
} |
| 349 |
|
| 350 |
console.log(`Downloading release asset: ${asset.browser_download_url}`); |
| 351 |
const res = await fetch(asset.browser_download_url); |
| 352 |
if (!res.ok) { |
| 353 |
core.setFailed(`Failed to download release asset: ${res.status} ${res.statusText}`); |
| 354 |
return; |
| 355 |
} |
| 356 |
require('fs').writeFileSync(process.env.TEMP + '\\efw.zip', Buffer.from(await res.arrayBuffer())); |
| 357 |
return |
| 358 |
} |
| 359 |
|
| 360 |
// Iterate through scheduled workflow runs (regardless of status) to find |
| 361 |
// one that contains the Build-x64-Debug artifact. |
| 362 |
let artifact = null; |
| 363 |
let runs_page = 1; |
| 364 |
outer: |
| 365 |
while (true) { |
| 366 |
const workflow_runs = await github.rest.actions.listWorkflowRuns({ |
| 367 |
owner: 'microsoft', |
| 368 |
repo: 'ebpf-for-windows', |
| 369 |
workflow_id: 'cicd.yml', |
| 370 |
event: 'schedule', |
| 371 |
branch: 'main', |
| 372 |
per_page: 10, |
| 373 |
page: runs_page |
| 374 |
}); |
| 375 |
|
| 376 |
if (workflow_runs.data.workflow_runs.length === 0) { |
| 377 |
core.setFailed('No scheduled workflow runs found'); |
| 378 |
return; |
| 379 |
} |
| 380 |
|
| 381 |
for (const run of workflow_runs.data.workflow_runs) { |
| 382 |
console.log(`Attempting workflow run: ${run.html_url}`); |
| 383 |
|
| 384 |
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ |
| 385 |
owner: 'microsoft', |
| 386 |
repo: 'ebpf-for-windows', |
| 387 |
run_id: run.id, |
| 388 |
per_page: 100, |
| 389 |
}); |
| 390 |
|
| 391 |
artifact = artifacts.data.artifacts.find(a => a.name === 'Build-x64-Debug'); |
| 392 |
if (artifact) { |
| 393 |
break outer; |
| 394 |
} |
| 395 |
} |
| 396 |
|
| 397 |
runs_page++; |
| 398 |
} |
| 399 |
|
| 400 |
if (!artifact) { |
| 401 |
core.setFailed('No scheduled workflow runs with Build-x64-Debug artifact found'); |
| 402 |
return; |
| 403 |
} |
| 404 |
|
| 405 |
// Download artifact bytes directly; response.data contains the zip. |
| 406 |
const response = await github.rest.actions.downloadArtifact({ |
| 407 |
owner: 'microsoft', |
| 408 |
repo: 'ebpf-for-windows', |
| 409 |
artifact_id: artifact.id, |
| 410 |
archive_format: 'zip', |
| 411 |
}); |
| 412 |
|
| 413 |
require('fs').writeFileSync(process.env.TEMP + '\\efw.zip', Buffer.from(response.data)); |
| 414 |
|
| 415 |
- name: Install eBPF for Windows |
| 416 |
shell: pwsh |
| 417 |
run: | |
| 418 |
if ("${{ matrix.version }}" -eq "main") { |
| 419 |
# Workflow artifact has nested structure: outer zip contains build-Debug.zip |
| 420 |
Expand-Archive -Path "$env:TEMP\efw.zip" -DestinationPath "$env:TEMP" |
| 421 |
Expand-Archive -Path "$env:TEMP\build-Debug.zip" -DestinationPath "$env:TEMP\ebpf" |
| 422 |
} else { |
| 423 |
# Release asset is the final zip, extract directly |
| 424 |
Expand-Archive -Path "$env:TEMP\efw.zip" -DestinationPath "$env:TEMP\ebpf" |
| 425 |
} |
| 426 |
|
| 427 |
$setupScript = Get-ChildItem -Path "$env:TEMP\ebpf" -Filter "install_ebpf.psm1" -Recurse | Select-Object -First 1 |
| 428 |
if ($setupScript) { |
| 429 |
Write-Host "Found setup script: $($setupScript.FullName)" |
| 430 |
$releasePath = "$env:TEMP\ebpf\release" |
| 431 |
Rename-Item -Path $setupScript.DirectoryName -NewName $releasePath |
| 432 |
Write-Host "Renamed directory to: $releasePath" |
| 433 |
Set-Location -Path $releasePath |
| 434 |
Write-Host "Changed directory to: $(Get-Location)" |
| 435 |
Import-Module .\\install_ebpf.psm1 -ArgumentList ($pwd, "install.log") -Force |
| 436 |
Get-PSExec |
| 437 |
Install-eBPFComponents -KmTracing $false -KmTraceType "file" -TestMode "Normal" |
| 438 |
} else { |
| 439 |
Write-Error "Setup script not found in the extracted package" |
| 440 |
exit 1 |
| 441 |
} |
| 442 |
|
| 443 |
- name: Add eBPF for Windows to PATH |
| 444 |
shell: pwsh |
| 445 |
run: echo "C:\Program Files\ebpf-for-windows\" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append |
| 446 |
|
| 447 |
- uses: actions/checkout@v6 |
| 448 |
|
| 449 |
- name: Set up Go |
| 450 |
uses: actions/setup-go@v6 |
| 451 |
with: |
| 452 |
go-version: '${{ env.go_version }}' |
| 453 |
|
| 454 |
- run: go install gotest.tools/[email protected] |
| 455 |
|
| 456 |
- name: Test |
| 457 |
run: > |
| 458 |
gotestsum --raw-command --ignore-non-json-output-lines --junitfile junit.xml -- |
| 459 |
go test -short -count 1 -json ./... |
| 460 |
|
| 461 |
- name: Upload Test Results |
| 462 |
if: always() |
| 463 |
uses: actions/upload-artifact@v7 |
| 464 |
with: |
| 465 |
name: Test Results (windows ${{ matrix.version }}) |
| 466 |
path: junit.xml |
| 467 |
|
| 468 |
results: |
| 469 |
name: Results |
| 470 |
runs-on: ubuntu-latest |
| 471 |
needs: |
| 472 |
- build-and-lint |
| 473 |
- generate-and-fix |
| 474 |
- cross-build |
| 475 |
- build-docs |
| 476 |
- test-on-prev-go |
| 477 |
- test-on-arm64 |
| 478 |
- linux-test |
| 479 |
- linux-benchmark |
| 480 |
- windows-test |
| 481 |
if: always() |
| 482 |
steps: |
| 483 |
- name: Check Results |
| 484 |
run: | |
| 485 |
if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]]; then |
| 486 |
echo "Some checks failed" |
| 487 |
exit 1 |
| 488 |
else |
| 489 |
echo "All checks passed successfully" |
| 490 |
fi |