ci: build Go test binaries while fixtures are provisioned (#2656)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke
2026-10-10 18:15:14 +02:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 465fccbe69
commit d25d2328f2
5 changed files with 155 additions and 117 deletions
+42 -44
View File
@@ -1,6 +1,6 @@
name: CI
# Windows tests are gated on Go and workflow changes for pull requests and branch pushes.
# Windows tests are gated on Go, workflow and Go test script changes for pull requests and branch pushes.
on:
push:
branches:
@@ -56,7 +56,7 @@ jobs:
exit 0
fi
changed_files=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" -- '*.go' '.github/workflows/ci.yml')
changed_files=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" -- '*.go' '.github/workflows/ci.yml' 'tools/build-go-tests.ps1' 'tools/run-go-tests.ps1')
if [[ -n "$changed_files" ]]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
else
@@ -403,6 +403,14 @@ jobs:
path: ${{ runner.temp }}/sql-server/setup
key: sql-server-2025-express-fa7e1fabc9a2-${{ runner.os }}
# Its PATH changes apply only after a wait step includes it.
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
id: setup-go
background: true
with:
# renovate: golang=go
go-version: '1.27.2'
# Steps that do not register services run in the background while Windows features install.
- name: Download SQL Server media
id: download-mssql
@@ -584,11 +592,15 @@ jobs:
- name: Wait for downloads
wait: [download-mssql, install-freerdp, download-container-prereqs]
# Install every Windows feature in one foreground step. Steps that register
# services, such as SQL Server setup, New-Cluster, and containerd, start only
# afterwards: changing service configuration during the install aborts its
# registry transaction, and the rollback then requires a restart.
# Install every Windows feature in one step. Steps that register services,
# such as SQL Server setup, New-Cluster, and containerd, start only after
# "Wait for Windows features": changing service configuration during the
# install aborts its registry transaction, and the rollback then requires
# a restart.
- name: Install Windows features
id: install-windows-features
# Setting up Go and building the tests register no services, so they overlap the install.
background: true
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
@@ -627,6 +639,23 @@ jobs:
Get-WindowsFeature -Name $features |
Format-Table DisplayName, Name, InstallState
- name: Wait for Go
wait: [setup-go]
# Linking the race-enabled test binaries takes minutes; do it while the
# fixtures below are provisioned instead of in the Go tests step.
- name: Build Go test binaries
id: build-go-tests
background: true
shell: pwsh
run: |
./tools/build-go-tests.ps1 -OutputDirectory (Join-Path $env:RUNNER_TEMP "go-tests")
go build -trimpath -o windows_exporter.exe ./cmd/windows_exporter
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
- name: Wait for Windows features
wait: [install-windows-features]
- name: Setup SQL Server Express
id: setup-mssql
background: true
@@ -1566,14 +1595,9 @@ jobs:
}
# The foreground waits for SQL Server here anyway, so Go setup costs nothing.
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
# renovate: golang=go
go-version: '1.27.2'
- name: Wait for background setup
wait:
- build-go-tests
- pull-hostprocess
- pull-nanoserver
- setup-bitlocker
@@ -1609,43 +1633,20 @@ jobs:
if ($LASTEXITCODE -ne 0) { throw "Failed to synchronize WMI performance counters" }
- name: Go tests
id: go-tests
shell: pwsh
env:
# Temporary: log raw ClusAPI property lists for parser fixtures.
WINDOWS_EXPORTER_TEST_CLUSAPI_DUMP: "1"
run: |
go test -json -count=1 -race -timeout=10m ./... 2>&1 | Tee-Object test-results.jsonl |
ForEach-Object {
$line = $_.ToString()
try {
$event = $line | ConvertFrom-Json -ErrorAction Stop
if ($event.Output) { [Console]::Write($event.Output) }
} catch {
Write-Host $line
}
}
$testExitCode = $LASTEXITCODE
"exit_code=$testExitCode" | Add-Content $env:GITHUB_OUTPUT
exit $testExitCode
run: ./tools/run-go-tests.ps1 -BinaryDirectory (Join-Path $env:RUNNER_TEMP "go-tests") -Timeout 10m
- name: Summarize Windows feature tests
- name: Smoke test exporter
shell: pwsh
run: ./tools/end-to-end-test.ps1
- name: Collect Windows setup logs
if: ${{ always() }}
shell: pwsh
env:
TEST_EXIT_CODE: ${{ steps.go-tests.outputs.exit_code || '1' }}
run: |
Copy-Item "$env:windir/Logs/DISM/dism.log" (Join-Path $env:RUNNER_TEMP "dism.log") -ErrorAction SilentlyContinue
# CBS.log names the files that make role installation request a restart.
Copy-Item "$env:windir/Logs/CBS/CBS.log" (Join-Path $env:RUNNER_TEMP "cbs.log") -ErrorAction SilentlyContinue
./tools/test-summary.ps1 -TestExitCode ([int]$env:TEST_EXIT_CODE)
- name: Build and smoke test exporter
shell: pwsh
run: |
go build -trimpath -o windows_exporter.exe ./cmd/windows_exporter
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
./tools/end-to-end-test.ps1
- name: Upload test logs
if: ${{ always() }}
@@ -1653,9 +1654,6 @@ jobs:
with:
name: windows-test-results-${{ matrix.os }}
path: |
test-output.txt
test-results.jsonl
feature-summary.md
${{ runner.temp }}/windows_exporter.*.log
${{ runner.temp }}/kubelet.*.log
${{ runner.temp }}/sql-server-summary.txt