blob: 88e6853b4c38aa537592f784de8d9fbd26612506 [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'
54 permissions:
55 packages: write
56 uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080057 with:
58 registry: ghcr.io
59 username: ${{ github.actor }}
60 password: ${{ secrets.GITHUB_TOKEN }}
61
62 - name: Pull cached image
63 id: pull_cached
64 continue-on-error: true
Jens Geyerf8622a72026-03-22 12:35:23 +010065 timeout-minutes: 10
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080066 shell: pwsh
67 run: |
68 $needBuild = $true
69
Jens Geyerf8622a72026-03-22 12:35:23 +010070 Write-Host "Attempting to pull hash-based tag: $($env:DOCKER_IMAGE):$($env.IMAGE_TAG)"
71 $output = docker pull "$($env.DOCKER_IMAGE):$($env.IMAGE_TAG)" 2>&1
72 $output | Out-Host
73
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080074 if ($LASTEXITCODE -eq 0) {
75 Write-Host "Successfully pulled cached image with hash tag"
76 $needBuild = $false
Jens Geyerf8622a72026-03-22 12:35:23 +010077 } elseif ($output -match 'not found|does not exist|404') {
78 Write-Host "Image not found in registry, will build from scratch."
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080079 $needBuild = $true
Jens Geyerf8622a72026-03-22 12:35:23 +010080 } else {
81 Write-Host "##[error]Docker pull failed with unexpected error. Check logs above."
82 Write-Host "This may indicate an authentication issue, registry problem, or network error."
83 exit 1
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080084 }
85
86 Write-Host "Setting outputs: need_build=$needBuild"
87 "need_build=$needBuild" >> $env:GITHUB_OUTPUT
88
89 - name: Build Docker image
90 if: steps.pull_cached.outputs.need_build == 'true'
Jens Geyerf8622a72026-03-22 12:35:23 +010091 timeout-minutes: 60
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080092 shell: pwsh
93 run: |
94 Write-Host "Building with tag: $($env:DOCKER_IMAGE):$($env:IMAGE_TAG)"
Shaoyu Zhang3adaf0d2026-02-20 13:28:16 -080095 docker build -t "$($env:DOCKER_IMAGE):$($env:IMAGE_TAG)" -f build\docker\msvc\Dockerfile 'build\'
Shaoyu Zhang230d0a92025-11-12 00:08:50 -080096 if ($LASTEXITCODE -ne 0) {
97 Write-Error "Docker build failed"
98 exit 1
99 }
100 Write-Host "Verifying tags were created:"
101 docker images "$($env:DOCKER_IMAGE)"
102
103 - name: Push Docker image
104 if: github.event_name != 'pull_request' && steps.pull_cached.outputs.need_build == 'true'
Jens Geyerf8622a72026-03-22 12:35:23 +0100105 timeout-minutes: 20
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800106 shell: pwsh
107 run: |
108 Write-Host "Pushing hash-based tag only: $($env:DOCKER_IMAGE):$($env:IMAGE_TAG)"
109 docker push "$($env:DOCKER_IMAGE):$($env:IMAGE_TAG)"
110 if ($LASTEXITCODE -ne 0) {
111 Write-Error "Failed to push hash-based tag"
112 exit 1
113 }
114 Write-Host "Successfully pushed hash-tagged image"
115
116 - name: Build and test inside container
Jens Geyerf8622a72026-03-22 12:35:23 +0100117 timeout-minutes: 120
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800118 shell: pwsh
119 run: |
Shaoyu Zhang3adaf0d2026-02-20 13:28:16 -0800120 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 -0800121 if ($LASTEXITCODE -ne 0) {
122 Write-Error "Container build failed with exit code $LASTEXITCODE"
123 exit $LASTEXITCODE
124 }
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800125
126 - name: Check test results
127 if: always()
128 shell: pwsh
129 run: |
130 $logPath = Join-Path $env:THRIFT_BUILD_DIR 'Testing\Temporary\LastTest.log'
131 if (Test-Path $logPath) {
132 $content = Get-Content $logPath -Raw
133 if ($content -match 'Test Failed\.') {
134 Write-Error "Tests failed - check LastTest.log artifact for details"
135 exit 1
136 } else {
137 Write-Host "All tests passed"
138 }
139 } else {
Copilot1e09a042026-01-29 10:36:28 -0800140 Write-Error "LastTest.log not found at $logPath"
141 exit 1
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800142 }
143
144 - name: Upload LastTest log
145 if: always()
Jens Geyerf8622a72026-03-22 12:35:23 +0100146 uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800147 with:
Shaoyu Zhang3adaf0d2026-02-20 13:28:16 -0800148 name: msvc-LastTest-log
Shaoyu Zhang230d0a92025-11-12 00:08:50 -0800149 path: ${{ env.THRIFT_BUILD_DIR }}\Testing\Temporary\LastTest.log
150 if-no-files-found: warn