blob: 52855106db44a21a9cfcfedd04777f37925152fa [file] [log] [blame]
Shaoyu Zhang230d0a92025-11-12 00:08:50 -08001name: MSVC Build
2
3on:
4 push:
5 branches: [ '*' ]
6 pull_request:
7 branches: [ '*' ]
8
Jens Geyerf8622a72026-03-22 12:35:23 +01009concurrency:
10 group: ${{ github.workflow }}-${{ github.ref }}
11 cancel-in-progress: true
12
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080013permissions:
14 contents: read
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080015
16jobs:
17 build:
Shaoyu Zhang3adaf0d2026-02-20 13:28:16 -080018 runs-on: windows-2025
Shaoyu Zhang43d74952026-03-25 21:01:51 +000019 permissions:
20 contents: read
21 packages: write
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080022 env:
23 THRIFT_BUILD_DIR: C:\thrift-build
24
25 steps:
26 - name: Checkout
Jens Geyerf8622a72026-03-22 12:35:23 +010027 uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080028
29 - name: Ensure expected workspace path
30 shell: pwsh
31 run: |
32 if (-not (Test-Path 'C:\src')) { New-Item -Path 'C:\src' -ItemType Directory | Out-Null }
33 if (Test-Path 'C:\src\thrift') { Remove-Item 'C:\src\thrift' -Recurse -Force }
34 cmd /c mklink /J C:\src\thrift $env:GITHUB_WORKSPACE
35
36 - name: Configure build output directory
37 shell: pwsh
38 run: |
39 New-Item -Path $env:THRIFT_BUILD_DIR -ItemType Directory -Force | Out-Null
40
Shaoyu Zhang43d74952026-03-25 21:01:51 +000041 - name: Configure Docker credential store
42 shell: pwsh
43 run: |
44 $dockerConfig = Join-Path $env:RUNNER_TEMP 'docker-config'
45 New-Item -Path $dockerConfig -ItemType Directory -Force | Out-Null
46
47 if (-not (Get-Command 'docker-credential-wincred.exe' -ErrorAction SilentlyContinue)) {
48 Write-Error 'docker-credential-wincred.exe is not available on this runner'
49 exit 1
50 }
51
52 '{"credsStore":"wincred"}' | Out-File -FilePath (Join-Path $dockerConfig 'config.json') -Encoding ascii
53 "DOCKER_CONFIG=$dockerConfig" | Out-File -FilePath $env:GITHUB_ENV -Append
54
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080055 - name: Set Docker image name
56 shell: pwsh
57 env:
58 OWNER: ${{ github.repository_owner }}
59 run: |
60 $image = "ghcr.io/{0}/thrift-build" -f $env:OWNER.ToLower()
61 "DOCKER_IMAGE=$image" | Out-File -FilePath $env:GITHUB_ENV -Append
62
63 - name: Compute Docker image tag
64 shell: pwsh
65 run: |
Shaoyu Zhang3adaf0d2026-02-20 13:28:16 -080066 $hash = (Get-FileHash -Algorithm SHA256 'build/docker/msvc/Dockerfile').Hash.ToLower().Substring(0, 12)
67 "IMAGE_TAG=msvc-$hash" | Out-File -FilePath $env:GITHUB_ENV -Append
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080068
69 - name: Log in to GHCR
Jens Geyerf8622a72026-03-22 12:35:23 +010070 if: github.event_name != 'pull_request'
Shaoyu Zhang43d74952026-03-25 21:01:51 +000071 shell: pwsh
72 env:
73 GHCR_USERNAME: ${{ github.actor }}
74 GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75 run: |
76 $env:GHCR_TOKEN | docker login ghcr.io --username $env:GHCR_USERNAME --password-stdin
77 if ($LASTEXITCODE -ne 0) {
78 Write-Error "Failed to log in to GHCR"
79 exit 1
80 }
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080081
82 - name: Pull cached image
83 id: pull_cached
84 continue-on-error: true
Shaoyu Zhang43d74952026-03-25 21:01:51 +000085 timeout-minutes: 40
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080086 shell: pwsh
87 run: |
88 $needBuild = $true
89
Shaoyu Zhang43d74952026-03-25 21:01:51 +000090 if ([string]::IsNullOrWhiteSpace($env:DOCKER_IMAGE) -or [string]::IsNullOrWhiteSpace($env:IMAGE_TAG)) {
91 Write-Error "DOCKER_IMAGE or IMAGE_TAG is empty. DOCKER_IMAGE='$env:DOCKER_IMAGE' IMAGE_TAG='$env:IMAGE_TAG'"
92 exit 1
93 }
94
95 Write-Host "Attempting to pull hash-based tag: $($env:DOCKER_IMAGE):$($env:IMAGE_TAG)"
96 $output = docker pull "$($env:DOCKER_IMAGE):$($env:IMAGE_TAG)" 2>&1
Jens Geyerf8622a72026-03-22 12:35:23 +010097 $output | Out-Host
98
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080099 if ($LASTEXITCODE -eq 0) {
100 Write-Host "Successfully pulled cached image with hash tag"
101 $needBuild = $false
Jens Geyerf8622a72026-03-22 12:35:23 +0100102 } elseif ($output -match 'not found|does not exist|404') {
103 Write-Host "Image not found in registry, will build from scratch."
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800104 $needBuild = $true
Jens Geyerf8622a72026-03-22 12:35:23 +0100105 } else {
106 Write-Host "##[error]Docker pull failed with unexpected error. Check logs above."
107 Write-Host "This may indicate an authentication issue, registry problem, or network error."
108 exit 1
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800109 }
110
111 Write-Host "Setting outputs: need_build=$needBuild"
112 "need_build=$needBuild" >> $env:GITHUB_OUTPUT
113
114 - name: Build Docker image
115 if: steps.pull_cached.outputs.need_build == 'true'
Jens Geyerf8622a72026-03-22 12:35:23 +0100116 timeout-minutes: 60
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800117 shell: pwsh
118 run: |
119 Write-Host "Building with tag: $($env:DOCKER_IMAGE):$($env:IMAGE_TAG)"
Shaoyu Zhang3adaf0d2026-02-20 13:28:16 -0800120 docker build -t "$($env:DOCKER_IMAGE):$($env:IMAGE_TAG)" -f build\docker\msvc\Dockerfile 'build\'
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800121 if ($LASTEXITCODE -ne 0) {
122 Write-Error "Docker build failed"
123 exit 1
124 }
125 Write-Host "Verifying tags were created:"
126 docker images "$($env:DOCKER_IMAGE)"
127
128 - name: Push Docker image
129 if: github.event_name != 'pull_request' && steps.pull_cached.outputs.need_build == 'true'
Jens Geyerf8622a72026-03-22 12:35:23 +0100130 timeout-minutes: 20
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800131 shell: pwsh
132 run: |
133 Write-Host "Pushing hash-based tag only: $($env:DOCKER_IMAGE):$($env:IMAGE_TAG)"
134 docker push "$($env:DOCKER_IMAGE):$($env:IMAGE_TAG)"
135 if ($LASTEXITCODE -ne 0) {
136 Write-Error "Failed to push hash-based tag"
137 exit 1
138 }
139 Write-Host "Successfully pushed hash-tagged image"
140
141 - name: Build and test inside container
Jens Geyerf8622a72026-03-22 12:35:23 +0100142 timeout-minutes: 120
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800143 shell: pwsh
144 run: |
Shaoyu Zhang3adaf0d2026-02-20 13:28:16 -0800145 docker run -v c:\src\thrift:C:\Thrift -v "${env:THRIFT_BUILD_DIR}:C:\build" --rm -t "$($env:DOCKER_IMAGE):$($env:IMAGE_TAG)" c:\thrift\build\docker\msvc\build.bat
Copilot1e09a042026-01-29 10:36:28 -0800146 if ($LASTEXITCODE -ne 0) {
147 Write-Error "Container build failed with exit code $LASTEXITCODE"
148 exit $LASTEXITCODE
149 }
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800150
151 - name: Check test results
152 if: always()
153 shell: pwsh
154 run: |
155 $logPath = Join-Path $env:THRIFT_BUILD_DIR 'Testing\Temporary\LastTest.log'
156 if (Test-Path $logPath) {
157 $content = Get-Content $logPath -Raw
158 if ($content -match 'Test Failed\.') {
159 Write-Error "Tests failed - check LastTest.log artifact for details"
160 exit 1
161 } else {
162 Write-Host "All tests passed"
163 }
164 } else {
Copilot1e09a042026-01-29 10:36:28 -0800165 Write-Error "LastTest.log not found at $logPath"
166 exit 1
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800167 }
168
169 - name: Upload LastTest log
170 if: always()
Jens Geyerf8622a72026-03-22 12:35:23 +0100171 uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800172 with:
Shaoyu Zhang3adaf0d2026-02-20 13:28:16 -0800173 name: msvc-LastTest-log
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800174 path: ${{ env.THRIFT_BUILD_DIR }}\Testing\Temporary\LastTest.log
175 if-no-files-found: warn
Shaoyu Zhang43d74952026-03-25 21:01:51 +0000176
177 - name: Remove Docker credential store
178 if: always()
179 shell: pwsh
180 run: |
181 if (-not [string]::IsNullOrWhiteSpace($env:DOCKER_CONFIG) -and (Test-Path $env:DOCKER_CONFIG)) {
182 Remove-Item $env:DOCKER_CONFIG -Recurse -Force
183 }