| 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 |
| Jens Geyer | caa4e78 | 2026-03-22 22:49:43 +0100 | [diff] [blame^] | 19 | if: false # currently broken -> see THRIFT-5936 |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 20 | env: |
| 21 | THRIFT_BUILD_DIR: C:\thrift-build |
| 22 | |
| 23 | steps: |
| 24 | - name: Checkout |
| Jens Geyer | f8622a7 | 2026-03-22 12:35:23 +0100 | [diff] [blame] | 25 | uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 26 | |
| 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 Zhang | 3adaf0d | 2026-02-20 13:28:16 -0800 | [diff] [blame] | 50 | $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 Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 52 | |
| 53 | - name: Log in to GHCR |
| Jens Geyer | f8622a7 | 2026-03-22 12:35:23 +0100 | [diff] [blame] | 54 | if: github.event_name != 'pull_request' |
| Jens Geyer | f8622a7 | 2026-03-22 12:35:23 +0100 | [diff] [blame] | 55 | uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 56 | 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 Geyer | f8622a7 | 2026-03-22 12:35:23 +0100 | [diff] [blame] | 64 | timeout-minutes: 10 |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 65 | shell: pwsh |
| 66 | run: | |
| 67 | $needBuild = $true |
| 68 | |
| Jens Geyer | f8622a7 | 2026-03-22 12:35:23 +0100 | [diff] [blame] | 69 | 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 Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 73 | if ($LASTEXITCODE -eq 0) { |
| 74 | Write-Host "Successfully pulled cached image with hash tag" |
| 75 | $needBuild = $false |
| Jens Geyer | f8622a7 | 2026-03-22 12:35:23 +0100 | [diff] [blame] | 76 | } elseif ($output -match 'not found|does not exist|404') { |
| 77 | Write-Host "Image not found in registry, will build from scratch." |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 78 | $needBuild = $true |
| Jens Geyer | f8622a7 | 2026-03-22 12:35:23 +0100 | [diff] [blame] | 79 | } 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 Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 83 | } |
| 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 Geyer | f8622a7 | 2026-03-22 12:35:23 +0100 | [diff] [blame] | 90 | timeout-minutes: 60 |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 91 | shell: pwsh |
| 92 | run: | |
| 93 | Write-Host "Building with tag: $($env:DOCKER_IMAGE):$($env:IMAGE_TAG)" |
| Shaoyu Zhang | 3adaf0d | 2026-02-20 13:28:16 -0800 | [diff] [blame] | 94 | 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] | 95 | 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 Geyer | f8622a7 | 2026-03-22 12:35:23 +0100 | [diff] [blame] | 104 | timeout-minutes: 20 |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 105 | 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 Geyer | f8622a7 | 2026-03-22 12:35:23 +0100 | [diff] [blame] | 116 | timeout-minutes: 120 |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 117 | shell: pwsh |
| 118 | run: | |
| Shaoyu Zhang | 3adaf0d | 2026-02-20 13:28:16 -0800 | [diff] [blame] | 119 | 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] | 120 | if ($LASTEXITCODE -ne 0) { |
| 121 | Write-Error "Container build failed with exit code $LASTEXITCODE" |
| 122 | exit $LASTEXITCODE |
| 123 | } |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 124 | |
| 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 { |
| Copilot | 1e09a04 | 2026-01-29 10:36:28 -0800 | [diff] [blame] | 139 | Write-Error "LastTest.log not found at $logPath" |
| 140 | exit 1 |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | - name: Upload LastTest log |
| 144 | if: always() |
| Jens Geyer | f8622a7 | 2026-03-22 12:35:23 +0100 | [diff] [blame] | 145 | uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 146 | with: |
| Shaoyu Zhang | 3adaf0d | 2026-02-20 13:28:16 -0800 | [diff] [blame] | 147 | name: msvc-LastTest-log |
| Shaoyu Zhang | 230d0a9 | 2025-11-12 00:08:50 -0800 | [diff] [blame] | 148 | path: ${{ env.THRIFT_BUILD_DIR }}\Testing\Temporary\LastTest.log |
| 149 | if-no-files-found: warn |