Debian Codegraph @

.github/workflows/ci.yml

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