blob: 84c94f06b5d181d65bd035d4b68c5bc347c5862f [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
Jens Geyercaa4e782026-03-22 22:49:43 +010019 if: false # currently broken -> see THRIFT-5936
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080020 env:
21 THRIFT_BUILD_DIR: C:\thrift-build
22
23 steps:
24 - name: Checkout
Jens Geyerf8622a72026-03-22 12:35:23 +010025 uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080026
27 - name: Ensure expected workspace path
28 shell: pwsh
29 run: |
30 if (-not (Test-Path 'C:\src')) { New-Item -Path 'C:\src' -ItemType Directory | Out-Null }
31 if (Test-Path 'C:\src\thrift') { Remove-Item 'C:\src\thrift' -Recurse -Force }
32 cmd /c mklink /J C:\src\thrift $env:GITHUB_WORKSPACE
33
34 - name: Configure build output directory
35 shell: pwsh
36 run: |
37 New-Item -Path $env:THRIFT_BUILD_DIR -ItemType Directory -Force | Out-Null
38
39 - name: Set Docker image name
40 shell: pwsh
41 env:
42 OWNER: ${{ github.repository_owner }}
43 run: |
44 $image = "ghcr.io/{0}/thrift-build" -f $env:OWNER.ToLower()
45 "DOCKER_IMAGE=$image" | Out-File -FilePath $env:GITHUB_ENV -Append
46
47 - name: Compute Docker image tag
48 shell: pwsh
49 run: |
Shaoyu Zhang3adaf0d2026-02-20 13:28:16 -080050 $hash = (Get-FileHash -Algorithm SHA256 'build/docker/msvc/Dockerfile').Hash.ToLower().Substring(0, 12)
51 "IMAGE_TAG=msvc-$hash" | Out-File -FilePath $env:GITHUB_ENV -Append
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080052
53 - name: Log in to GHCR
Jens Geyerf8622a72026-03-22 12:35:23 +010054 if: github.event_name != 'pull_request'
Jens Geyerf8622a72026-03-22 12:35:23 +010055 uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080056 with:
57 registry: ghcr.io
58 username: ${{ github.actor }}
59 password: ${{ secrets.GITHUB_TOKEN }}
60
61 - name: Pull cached image
62 id: pull_cached
63 continue-on-error: true
Jens Geyerf8622a72026-03-22 12:35:23 +010064 timeout-minutes: 10
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080065 shell: pwsh
66 run: |
67 $needBuild = $true
68
Jens Geyerf8622a72026-03-22 12:35:23 +010069 Write-Host "Attempting to pull hash-based tag: $($env:DOCKER_IMAGE):$($env.IMAGE_TAG)"
70 $output = docker pull "$($env.DOCKER_IMAGE):$($env.IMAGE_TAG)" 2>&1
71 $output | Out-Host
72
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080073 if ($LASTEXITCODE -eq 0) {
74 Write-Host "Successfully pulled cached image with hash tag"
75 $needBuild = $false
Jens Geyerf8622a72026-03-22 12:35:23 +010076 } elseif ($output -match 'not found|does not exist|404') {
77 Write-Host "Image not found in registry, will build from scratch."
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080078 $needBuild = $true
Jens Geyerf8622a72026-03-22 12:35:23 +010079 } else {
80 Write-Host "##[error]Docker pull failed with unexpected error. Check logs above."
81 Write-Host "This may indicate an authentication issue, registry problem, or network error."
82 exit 1
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080083 }
84
85 Write-Host "Setting outputs: need_build=$needBuild"
86 "need_build=$needBuild" >> $env:GITHUB_OUTPUT
87
88 - name: Build Docker image
89 if: steps.pull_cached.outputs.need_build == 'true'
Jens Geyerf8622a72026-03-22 12:35:23 +010090 timeout-minutes: 60
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080091 shell: pwsh
92 run: |
93 Write-Host "Building with tag: $($env:DOCKER_IMAGE):$($env:IMAGE_TAG)"
Shaoyu Zhang3adaf0d2026-02-20 13:28:16 -080094 docker build -t "$($env:DOCKER_IMAGE):$($env:IMAGE_TAG)" -f build\docker\msvc\Dockerfile 'build\'
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080095 if ($LASTEXITCODE -ne 0) {
96 Write-Error "Docker build failed"
97 exit 1
98 }
99 Write-Host "Verifying tags were created:"
100 docker images "$($env:DOCKER_IMAGE)"
101
102 - name: Push Docker image
103 if: github.event_name != 'pull_request' && steps.pull_cached.outputs.need_build == 'true'
Jens Geyerf8622a72026-03-22 12:35:23 +0100104 timeout-minutes: 20
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800105 shell: pwsh
106 run: |
107 Write-Host "Pushing hash-based tag only: $($env:DOCKER_IMAGE):$($env:IMAGE_TAG)"
108 docker push "$($env:DOCKER_IMAGE):$($env:IMAGE_TAG)"
109 if ($LASTEXITCODE -ne 0) {
110 Write-Error "Failed to push hash-based tag"
111 exit 1
112 }
113 Write-Host "Successfully pushed hash-tagged image"
114
115 - name: Build and test inside container
Jens Geyerf8622a72026-03-22 12:35:23 +0100116 timeout-minutes: 120
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800117 shell: pwsh
118 run: |
Shaoyu Zhang3adaf0d2026-02-20 13:28:16 -0800119 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 -0800120 if ($LASTEXITCODE -ne 0) {
121 Write-Error "Container build failed with exit code $LASTEXITCODE"
122 exit $LASTEXITCODE
123 }
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800124
125 - name: Check test results
126 if: always()
127 shell: pwsh
128 run: |
129 $logPath = Join-Path $env:THRIFT_BUILD_DIR 'Testing\Temporary\LastTest.log'
130 if (Test-Path $logPath) {
131 $content = Get-Content $logPath -Raw
132 if ($content -match 'Test Failed\.') {
133 Write-Error "Tests failed - check LastTest.log artifact for details"
134 exit 1
135 } else {
136 Write-Host "All tests passed"
137 }
138 } else {
Copilot1e09a042026-01-29 10:36:28 -0800139 Write-Error "LastTest.log not found at $logPath"
140 exit 1
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800141 }
142
143 - name: Upload LastTest log
144 if: always()
Jens Geyerf8622a72026-03-22 12:35:23 +0100145 uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800146 with:
Shaoyu Zhang3adaf0d2026-02-20 13:28:16 -0800147 name: msvc-LastTest-log
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800148 path: ${{ env.THRIFT_BUILD_DIR }}\Testing\Temporary\LastTest.log
149 if-no-files-found: warn