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