| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 1 | name: MSVC Build |
| 2 | |
| 3 | on: |
| 4 | push: |
| 5 | branches: [ '*' ] |
| 6 | pull_request: |
| 7 | branches: [ '*' ] |
| 8 | |
| Jens Geyer | f8622a7 | 2026-03-22 12:35:23 +0100 | [diff] [blame] | 9 | concurrency: |
| 10 | group: ${{ github.workflow }}-${{ github.ref }} |
| 11 | cancel-in-progress: true |
| 12 | |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 13 | permissions: |
| 14 | contents: read |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 15 | |
| 16 | jobs: |
| 17 | build: |
| Shaoyu Zhang | 3adaf0d | 2026-02-20 13:28:16 -0800 | [diff] [blame] | 18 | runs-on: windows-2025 |
| Shaoyu Zhang | 43d7495 | 2026-03-25 21:01:51 +0000 | [diff] [blame] | 19 | permissions: |
| 20 | contents: read |
| 21 | packages: write |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 22 | env: |
| 23 | THRIFT_BUILD_DIR: C:\thrift-build |
| 24 | |
| 25 | steps: |
| 26 | - name: Checkout |
| Jens Geyer | f8622a7 | 2026-03-22 12:35:23 +0100 | [diff] [blame] | 27 | uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 28 | |
| 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 Zhang | 43d7495 | 2026-03-25 21:01:51 +0000 | [diff] [blame] | 41 | - 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 Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 55 | - 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 Zhang | 3adaf0d | 2026-02-20 13:28:16 -0800 | [diff] [blame] | 66 | $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 Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 68 | |
| 69 | - name: Log in to GHCR |
| Jens Geyer | f8622a7 | 2026-03-22 12:35:23 +0100 | [diff] [blame] | 70 | if: github.event_name != 'pull_request' |
| Shaoyu Zhang | 43d7495 | 2026-03-25 21:01:51 +0000 | [diff] [blame] | 71 | 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 Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 81 | |
| 82 | - name: Pull cached image |
| 83 | id: pull_cached |
| 84 | continue-on-error: true |
| Shaoyu Zhang | 43d7495 | 2026-03-25 21:01:51 +0000 | [diff] [blame] | 85 | timeout-minutes: 40 |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 86 | shell: pwsh |
| 87 | run: | |
| 88 | $needBuild = $true |
| 89 | |
| Shaoyu Zhang | 43d7495 | 2026-03-25 21:01:51 +0000 | [diff] [blame] | 90 | 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 Geyer | f8622a7 | 2026-03-22 12:35:23 +0100 | [diff] [blame] | 97 | $output | Out-Host |
| 98 | |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 99 | if ($LASTEXITCODE -eq 0) { |
| 100 | Write-Host "Successfully pulled cached image with hash tag" |
| 101 | $needBuild = $false |
| Jens Geyer | f8622a7 | 2026-03-22 12:35:23 +0100 | [diff] [blame] | 102 | } elseif ($output -match 'not found|does not exist|404') { |
| 103 | Write-Host "Image not found in registry, will build from scratch." |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 104 | $needBuild = $true |
| Jens Geyer | f8622a7 | 2026-03-22 12:35:23 +0100 | [diff] [blame] | 105 | } 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 Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 109 | } |
| 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 Geyer | f8622a7 | 2026-03-22 12:35:23 +0100 | [diff] [blame] | 116 | timeout-minutes: 60 |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 117 | shell: pwsh |
| 118 | run: | |
| 119 | Write-Host "Building with tag: $($env:DOCKER_IMAGE):$($env:IMAGE_TAG)" |
| Shaoyu Zhang | 3adaf0d | 2026-02-20 13:28:16 -0800 | [diff] [blame] | 120 | docker build -t "$($env:DOCKER_IMAGE):$($env:IMAGE_TAG)" -f build\docker\msvc\Dockerfile 'build\' |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 121 | 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 Geyer | f8622a7 | 2026-03-22 12:35:23 +0100 | [diff] [blame] | 130 | timeout-minutes: 20 |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 131 | 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 Geyer | f8622a7 | 2026-03-22 12:35:23 +0100 | [diff] [blame] | 142 | timeout-minutes: 120 |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 143 | shell: pwsh |
| 144 | run: | |
| Shaoyu Zhang | 3adaf0d | 2026-02-20 13:28:16 -0800 | [diff] [blame] | 145 | 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 |
| Copilot | 1e09a04 | 2026-01-29 10:36:28 -0800 | [diff] [blame] | 146 | if ($LASTEXITCODE -ne 0) { |
| 147 | Write-Error "Container build failed with exit code $LASTEXITCODE" |
| 148 | exit $LASTEXITCODE |
| 149 | } |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 150 | |
| 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 { |
| Copilot | 1e09a04 | 2026-01-29 10:36:28 -0800 | [diff] [blame] | 165 | Write-Error "LastTest.log not found at $logPath" |
| 166 | exit 1 |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | - name: Upload LastTest log |
| 170 | if: always() |
| Jens Geyer | f8622a7 | 2026-03-22 12:35:23 +0100 | [diff] [blame] | 171 | uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 172 | with: |
| Shaoyu Zhang | 3adaf0d | 2026-02-20 13:28:16 -0800 | [diff] [blame] | 173 | name: msvc-LastTest-log |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 174 | path: ${{ env.THRIFT_BUILD_DIR }}\Testing\Temporary\LastTest.log |
| 175 | if-no-files-found: warn |
| Shaoyu Zhang | 43d7495 | 2026-03-25 21:01:51 +0000 | [diff] [blame] | 176 | |
| 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 | } |