blob: 4fb84a1864cdbdf946b544def62941aac6ffb7c7 [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 Zhang230d0a92025-11-12 00:08:50 -080019 env:
20 THRIFT_BUILD_DIR: C:\thrift-build
21
22 steps:
23 - name: Checkout
Jens Geyerf8622a72026-03-22 12:35:23 +010024 uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080025
26 - name: Ensure expected workspace path
27 shell: pwsh
28 run: |
29 if (-not (Test-Path 'C:\src')) { New-Item -Path 'C:\src' -ItemType Directory | Out-Null }
30 if (Test-Path 'C:\src\thrift') { Remove-Item 'C:\src\thrift' -Recurse -Force }
31 cmd /c mklink /J C:\src\thrift $env:GITHUB_WORKSPACE
32
33 - name: Configure build output directory
34 shell: pwsh
35 run: |
36 New-Item -Path $env:THRIFT_BUILD_DIR -ItemType Directory -Force | Out-Null
37
38 - name: Set Docker image name
39 shell: pwsh
40 env:
41 OWNER: ${{ github.repository_owner }}
42 run: |
43 $image = "ghcr.io/{0}/thrift-build" -f $env:OWNER.ToLower()
44 "DOCKER_IMAGE=$image" | Out-File -FilePath $env:GITHUB_ENV -Append
45
46 - name: Compute Docker image tag
47 shell: pwsh
48 run: |
Shaoyu Zhang3adaf0d2026-02-20 13:28:16 -080049 $hash = (Get-FileHash -Algorithm SHA256 'build/docker/msvc/Dockerfile').Hash.ToLower().Substring(0, 12)
50 "IMAGE_TAG=msvc-$hash" | Out-File -FilePath $env:GITHUB_ENV -Append
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080051
52 - name: Log in to GHCR
Jens Geyerf8622a72026-03-22 12:35:23 +010053 if: github.event_name != 'pull_request'
Jens Geyerf8622a72026-03-22 12:35:23 +010054 uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080055 with:
56 registry: ghcr.io
57 username: ${{ github.actor }}
58 password: ${{ secrets.GITHUB_TOKEN }}
59
60 - name: Pull cached image
61 id: pull_cached
62 continue-on-error: true
Jens Geyerf8622a72026-03-22 12:35:23 +010063 timeout-minutes: 10
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080064 shell: pwsh
65 run: |
66 $needBuild = $true
67
Jens Geyerf8622a72026-03-22 12:35:23 +010068 Write-Host "Attempting to pull hash-based tag: $($env:DOCKER_IMAGE):$($env.IMAGE_TAG)"
69 $output = docker pull "$($env.DOCKER_IMAGE):$($env.IMAGE_TAG)" 2>&1
70 $output | Out-Host
71
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080072 if ($LASTEXITCODE -eq 0) {
73 Write-Host "Successfully pulled cached image with hash tag"
74 $needBuild = $false
Jens Geyerf8622a72026-03-22 12:35:23 +010075 } elseif ($output -match 'not found|does not exist|404') {
76 Write-Host "Image not found in registry, will build from scratch."
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080077 $needBuild = $true
Jens Geyerf8622a72026-03-22 12:35:23 +010078 } else {
79 Write-Host "##[error]Docker pull failed with unexpected error. Check logs above."
80 Write-Host "This may indicate an authentication issue, registry problem, or network error."
81 exit 1
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080082 }
83
84 Write-Host "Setting outputs: need_build=$needBuild"
85 "need_build=$needBuild" >> $env:GITHUB_OUTPUT
86
87 - name: Build Docker image
88 if: steps.pull_cached.outputs.need_build == 'true'
Jens Geyerf8622a72026-03-22 12:35:23 +010089 timeout-minutes: 60
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080090 shell: pwsh
91 run: |
92 Write-Host "Building with tag: $($env:DOCKER_IMAGE):$($env:IMAGE_TAG)"
Shaoyu Zhang3adaf0d2026-02-20 13:28:16 -080093 docker build -t "$($env:DOCKER_IMAGE):$($env:IMAGE_TAG)" -f build\docker\msvc\Dockerfile 'build\'
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080094 if ($LASTEXITCODE -ne 0) {
95 Write-Error "Docker build failed"
96 exit 1
97 }
98 Write-Host "Verifying tags were created:"
99 docker images "$($env:DOCKER_IMAGE)"
100
101 - name: Push Docker image
102 if: github.event_name != 'pull_request' && steps.pull_cached.outputs.need_build == 'true'
Jens Geyerf8622a72026-03-22 12:35:23 +0100103 timeout-minutes: 20
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800104 shell: pwsh
105 run: |
106 Write-Host "Pushing hash-based tag only: $($env:DOCKER_IMAGE):$($env:IMAGE_TAG)"
107 docker push "$($env:DOCKER_IMAGE):$($env:IMAGE_TAG)"
108 if ($LASTEXITCODE -ne 0) {
109 Write-Error "Failed to push hash-based tag"
110 exit 1
111 }
112 Write-Host "Successfully pushed hash-tagged image"
113
114 - name: Build and test inside container
Jens Geyerf8622a72026-03-22 12:35:23 +0100115 timeout-minutes: 120
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800116 shell: pwsh
117 run: |
Shaoyu Zhang3adaf0d2026-02-20 13:28:16 -0800118 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 -0800119 if ($LASTEXITCODE -ne 0) {
120 Write-Error "Container build failed with exit code $LASTEXITCODE"
121 exit $LASTEXITCODE
122 }
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800123
124 - name: Check test results
125 if: always()
126 shell: pwsh
127 run: |
128 $logPath = Join-Path $env:THRIFT_BUILD_DIR 'Testing\Temporary\LastTest.log'
129 if (Test-Path $logPath) {
130 $content = Get-Content $logPath -Raw
131 if ($content -match 'Test Failed\.') {
132 Write-Error "Tests failed - check LastTest.log artifact for details"
133 exit 1
134 } else {
135 Write-Host "All tests passed"
136 }
137 } else {
Copilot1e09a042026-01-29 10:36:28 -0800138 Write-Error "LastTest.log not found at $logPath"
139 exit 1
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800140 }
141
142 - name: Upload LastTest log
143 if: always()
Jens Geyerf8622a72026-03-22 12:35:23 +0100144 uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800145 with:
Shaoyu Zhang3adaf0d2026-02-20 13:28:16 -0800146 name: msvc-LastTest-log
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800147 path: ${{ env.THRIFT_BUILD_DIR }}\Testing\Temporary\LastTest.log
148 if-no-files-found: warn