Skip to content

Commit 77b7b5a

Browse files
committed
chore(ci): harden windows release gate
1 parent f2763f4 commit 77b7b5a

File tree

4 files changed

+131
-9
lines changed

4 files changed

+131
-9
lines changed

Makefile

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ RM_BIN = powershell -NoProfile -Command "if (Test-Path 'bin') { Remove-Item -Rec
88
RM_DIST = powershell -NoProfile -Command "if (Test-Path 'dist') { Remove-Item -Recurse -Force 'dist' }"
99
RM_COVER = powershell -NoProfile -Command "$$paths = @('coverage','coverage.out','coverage.out;','coverage-fresh','coverage-fresh.out'); foreach ($$path in $$paths) { if (Test-Path $$path) { Remove-Item -Force $$path } }"
1010
BIN_TARGET = bin/viaduct.exe
11-
RUN_BIN = $(BIN_TARGET)
11+
GO_RUN = powershell -NoProfile -ExecutionPolicy Bypass -File scripts/go_run_windows.ps1
12+
RUN_BIN = $(GO_RUN) ./cmd/viaduct
1213
WEB_INSTALL = cd web && npm ci
1314
COVERPROFILE_ARG = "-coverprofile=coverage.out"
1415
COVERFUNC_ARG = "-func=coverage.out"
1516
GO_BUILD_LINUX = powershell -NoProfile -Command "$$env:CGO_ENABLED='0'; $$env:GOOS='linux'; $$env:GOARCH='amd64'; go build -ldflags '-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)' -o '$(LINUX_BINARY)' ./cmd/viaduct"
1617
GO_BUILD_WINDOWS = powershell -NoProfile -Command "$$env:CGO_ENABLED='0'; $$env:GOOS='windows'; $$env:GOARCH='amd64'; go build -ldflags '-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)' -o '$(WINDOWS_BINARY)' ./cmd/viaduct"
18+
GO_TEST_RACE = powershell -NoProfile -ExecutionPolicy Bypass -File scripts/go_test_race_windows.ps1 ./... -v -race
19+
GO_TEST_RACE_COUNT = powershell -NoProfile -ExecutionPolicy Bypass -File scripts/go_test_race_windows.ps1 ./... -v -race -count=1
20+
GO_TEST_COVER = powershell -NoProfile -ExecutionPolicy Bypass -File scripts/go_test_windows.ps1 ./... $(COVERPROFILE_ARG)
1721
else
1822
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
1923
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo none)
@@ -25,11 +29,15 @@ RM_DIST = rm -rf dist/
2529
RM_COVER = rm -f coverage coverage.out
2630
BIN_TARGET = bin/viaduct
2731
RUN_BIN = ./$(BIN_TARGET)
32+
GO_RUN = go run
2833
WEB_INSTALL = cd web && npm ci
2934
COVERPROFILE_ARG = -coverprofile=coverage.out
3035
COVERFUNC_ARG = -func=coverage.out
3136
GO_BUILD_LINUX = CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)" -o $(LINUX_BINARY) ./cmd/viaduct
3237
GO_BUILD_WINDOWS = CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)" -o $(WINDOWS_BINARY) ./cmd/viaduct
38+
GO_TEST_RACE = go test ./... -v -race
39+
GO_TEST_RACE_COUNT = go test ./... -v -race -count=1
40+
GO_TEST_COVER = go test ./... $(COVERPROFILE_ARG)
3341
endif
3442

3543
COVER_MIN ?= 50.0
@@ -54,7 +62,7 @@ build-windows:
5462
$(GO_BUILD_WINDOWS)
5563

5664
test:
57-
go test ./... -v -race
65+
$(GO_TEST_RACE)
5866

5967
lint:
6068
golangci-lint run ./...
@@ -81,19 +89,19 @@ package-release:
8189
$(MKDIR_DIST)
8290
$(MAKE) build
8391
$(MAKE) web-build
84-
go run ./scripts/package_release -workspace . -version $(VERSION) -commit $(COMMIT) -date $(DATE) -binary $(BIN_TARGET) -web-dir web/dist -output-dir dist
92+
$(GO_RUN) ./scripts/package_release -workspace . -version $(VERSION) -commit $(COMMIT) -date $(DATE) -binary $(BIN_TARGET) -web-dir web/dist -output-dir dist
8593

8694
package-release-linux:
8795
$(MKDIR_DIST)
8896
$(MAKE) build-linux
8997
$(MAKE) web-build
90-
go run ./scripts/package_release -workspace . -version $(VERSION) -commit $(COMMIT) -date $(DATE) -binary $(LINUX_BINARY) -web-dir web/dist -output-dir dist -bundle-goos linux -bundle-goarch amd64
98+
$(GO_RUN) ./scripts/package_release -workspace . -version $(VERSION) -commit $(COMMIT) -date $(DATE) -binary $(LINUX_BINARY) -web-dir web/dist -output-dir dist -bundle-goos linux -bundle-goarch amd64
9199

92100
package-release-windows:
93101
$(MKDIR_DIST)
94102
$(MAKE) build-windows
95103
$(MAKE) web-build
96-
go run ./scripts/package_release -workspace . -version $(VERSION) -commit $(COMMIT) -date $(DATE) -binary $(WINDOWS_BINARY) -web-dir web/dist -output-dir dist -bundle-goos windows -bundle-goarch amd64
104+
$(GO_RUN) ./scripts/package_release -workspace . -version $(VERSION) -commit $(COMMIT) -date $(DATE) -binary $(WINDOWS_BINARY) -web-dir web/dist -output-dir dist -bundle-goos windows -bundle-goarch amd64
97105

98106
package-release-matrix:
99107
$(RM_DIST)
@@ -108,7 +116,7 @@ soak-test:
108116
go test -tags soak ./tests/soak/... -count=1
109117

110118
plugin-check:
111-
go run ./scripts/plugin_manifest_check -manifest $(PLUGIN_MANIFEST) -host-version $(VERSION)
119+
$(GO_RUN) ./scripts/plugin_manifest_check -manifest $(PLUGIN_MANIFEST) -host-version $(VERSION)
112120

113121
contract-check:
114122
go test ./tests/integration/... -run TestOpenAPISpec_StableRoutesDocumented_Expected -count=1
@@ -120,7 +128,7 @@ release-gate:
120128
go build ./...
121129
go vet ./...
122130
golangci-lint run ./...
123-
go test ./... -v -race -count=1
131+
$(GO_TEST_RACE_COUNT)
124132
$(MAKE) soak-test
125133
$(MAKE) plugin-check
126134
$(MAKE) contract-check
@@ -130,9 +138,9 @@ release-gate:
130138
$(RUN_BIN) plan --help
131139
$(RUN_BIN) migrate --help
132140
$(MAKE) web-build
133-
go test ./... $(COVERPROFILE_ARG)
141+
$(GO_TEST_COVER)
134142
go tool cover $(COVERFUNC_ARG)
135-
go run ./scripts/coverage_gate.go coverage.out $(COVER_MIN)
143+
$(GO_RUN) ./scripts/coverage_gate.go coverage.out $(COVER_MIN)
136144
$(MAKE) package-release-matrix
137145

138146
clean:

scripts/go_run_windows.ps1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
param(
2+
[Parameter(ValueFromRemainingArguments = $true)]
3+
[string[]]$GoRunArgs
4+
)
5+
6+
$ErrorActionPreference = "Stop"
7+
8+
$base = Join-Path $env:LOCALAPPDATA "ViaductRun"
9+
$gocache = Join-Path $base "gocache"
10+
$gotmp = Join-Path $base "gotmp"
11+
$gomodcache = Join-Path $base "gomodcache"
12+
New-Item -ItemType Directory -Force -Path $base, $gocache, $gotmp, $gomodcache | Out-Null
13+
14+
$env:GOCACHE = $gocache
15+
$env:GOTMPDIR = $gotmp
16+
$env:GOMODCACHE = $gomodcache
17+
$env:TMP = $base
18+
$env:TEMP = $base
19+
20+
$goBinary = (Get-Command go -ErrorAction Stop).Source
21+
& $goBinary run @GoRunArgs
22+
exit $LASTEXITCODE

scripts/go_test_race_windows.ps1

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
param(
2+
[Parameter(ValueFromRemainingArguments = $true)]
3+
[string[]]$GoTestArgs
4+
)
5+
6+
$ErrorActionPreference = "Stop"
7+
8+
function Resolve-CompilerPath {
9+
param(
10+
[Parameter(Mandatory = $true)]
11+
[string]$EnvironmentVariable,
12+
[Parameter(Mandatory = $true)]
13+
[string]$BinaryName
14+
)
15+
16+
$override = [Environment]::GetEnvironmentVariable($EnvironmentVariable)
17+
if ($override) {
18+
if (-not (Test-Path -LiteralPath $override)) {
19+
throw "Configured $EnvironmentVariable path '$override' does not exist."
20+
}
21+
22+
return $override
23+
}
24+
25+
$packagesRoot = Join-Path $env:LOCALAPPDATA "Microsoft\WinGet\Packages"
26+
$packageRoot = Get-ChildItem -LiteralPath $packagesRoot -Directory |
27+
Where-Object { $_.Name -like "MartinStorsjo.LLVM-MinGW.UCRT*" } |
28+
Sort-Object Name -Descending |
29+
Select-Object -First 1
30+
if (-not $packageRoot) {
31+
throw "Install the LLVM-MinGW UCRT toolchain with 'winget install --id MartinStorsjo.LLVM-MinGW.UCRT -e' before running race tests on Windows."
32+
}
33+
34+
$toolchainRoot = Get-ChildItem -LiteralPath $packageRoot.FullName -Directory |
35+
Where-Object { $_.Name -like "llvm-mingw-*" } |
36+
Sort-Object Name -Descending |
37+
Select-Object -First 1
38+
if (-not $toolchainRoot) {
39+
throw "Unable to locate the installed LLVM-MinGW toolchain under '$($packageRoot.FullName)'."
40+
}
41+
42+
$binaryPath = Join-Path $toolchainRoot.FullName ("bin\" + $BinaryName)
43+
if (-not (Test-Path -LiteralPath $binaryPath)) {
44+
throw "Unable to locate '$BinaryName' under '$($toolchainRoot.FullName)\bin'."
45+
}
46+
47+
return $binaryPath
48+
}
49+
50+
$gcc = Resolve-CompilerPath -EnvironmentVariable "VIADUCT_WINDOWS_RACE_CC" -BinaryName "x86_64-w64-mingw32-gcc.exe"
51+
$gxx = Resolve-CompilerPath -EnvironmentVariable "VIADUCT_WINDOWS_RACE_CXX" -BinaryName "x86_64-w64-mingw32-g++.exe"
52+
53+
$base = Join-Path $env:LOCALAPPDATA "ViaductRace"
54+
$gocache = Join-Path $base "gocache"
55+
$gotmp = Join-Path $base "gotmp"
56+
$gomodcache = Join-Path $base "gomodcache"
57+
New-Item -ItemType Directory -Force -Path $base, $gocache, $gotmp, $gomodcache | Out-Null
58+
59+
$env:CGO_ENABLED = "1"
60+
$env:CC = $gcc
61+
$env:CXX = $gxx
62+
$env:GOCACHE = $gocache
63+
$env:GOTMPDIR = $gotmp
64+
$env:GOMODCACHE = $gomodcache
65+
$env:TMP = $base
66+
$env:TEMP = $base
67+
68+
$goBinary = (Get-Command go -ErrorAction Stop).Source
69+
& $goBinary test @GoTestArgs
70+
exit $LASTEXITCODE

scripts/go_test_windows.ps1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
param(
2+
[Parameter(ValueFromRemainingArguments = $true)]
3+
[string[]]$GoTestArgs
4+
)
5+
6+
$ErrorActionPreference = "Stop"
7+
8+
$base = Join-Path $env:LOCALAPPDATA "ViaductTest"
9+
$gocache = Join-Path $base "gocache"
10+
$gotmp = Join-Path $base "gotmp"
11+
$gomodcache = Join-Path $base "gomodcache"
12+
New-Item -ItemType Directory -Force -Path $base, $gocache, $gotmp, $gomodcache | Out-Null
13+
14+
$env:GOCACHE = $gocache
15+
$env:GOTMPDIR = $gotmp
16+
$env:GOMODCACHE = $gomodcache
17+
$env:TMP = $base
18+
$env:TEMP = $base
19+
20+
$goBinary = (Get-Command go -ErrorAction Stop).Source
21+
& $goBinary test @GoTestArgs
22+
exit $LASTEXITCODE

0 commit comments

Comments
 (0)