blob: deb08c3e3f3912e5c758255b2f08f4f9d09827be [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
9permissions:
10 contents: read
11 packages: write
12
13jobs:
14 build:
15 runs-on: windows-2022
16 env:
17 THRIFT_BUILD_DIR: C:\thrift-build
18
19 steps:
20 - name: Checkout
21 uses: actions/checkout@v4
22
23 - name: Ensure expected workspace path
24 shell: pwsh
25 run: |
26 if (-not (Test-Path 'C:\src')) { New-Item -Path 'C:\src' -ItemType Directory | Out-Null }
27 if (Test-Path 'C:\src\thrift') { Remove-Item 'C:\src\thrift' -Recurse -Force }
28 cmd /c mklink /J C:\src\thrift $env:GITHUB_WORKSPACE
29
30 - name: Configure build output directory
31 shell: pwsh
32 run: |
33 New-Item -Path $env:THRIFT_BUILD_DIR -ItemType Directory -Force | Out-Null
34
35 - name: Set Docker image name
36 shell: pwsh
37 env:
38 OWNER: ${{ github.repository_owner }}
39 run: |
40 $image = "ghcr.io/{0}/thrift-build" -f $env:OWNER.ToLower()
41 "DOCKER_IMAGE=$image" | Out-File -FilePath $env:GITHUB_ENV -Append
42
43 - name: Compute Docker image tag
44 shell: pwsh
45 run: |
46 $hash = (Get-FileHash -Algorithm SHA256 'build/docker/msvc2017/Dockerfile').Hash.ToLower().Substring(0, 12)
47 "IMAGE_TAG=msvc2017-$hash" | Out-File -FilePath $env:GITHUB_ENV -Append
48
49 - name: Log in to GHCR
50 uses: docker/login-action@v3
51 with:
52 registry: ghcr.io
53 username: ${{ github.actor }}
54 password: ${{ secrets.GITHUB_TOKEN }}
55
56 - name: Pull cached image
57 id: pull_cached
58 continue-on-error: true
59 shell: pwsh
60 run: |
61 $needBuild = $true
62
63 Write-Host "Attempting to pull hash-based tag: $($env:DOCKER_IMAGE):$($env:IMAGE_TAG)"
64 docker pull "$($env:DOCKER_IMAGE):$($env:IMAGE_TAG)" 2>&1 | Out-Host
65 if ($LASTEXITCODE -eq 0) {
66 Write-Host "Successfully pulled cached image with hash tag"
67 $needBuild = $false
68 } else {
69 Write-Host "Hash tag not found, no fallback configured. Will build from scratch."
70 $needBuild = $true
71 }
72
73 Write-Host "Setting outputs: need_build=$needBuild"
74 "need_build=$needBuild" >> $env:GITHUB_OUTPUT
75
76 - name: Build Docker image
77 if: steps.pull_cached.outputs.need_build == 'true'
78 shell: pwsh
79 run: |
80 Write-Host "Building with tag: $($env:DOCKER_IMAGE):$($env:IMAGE_TAG)"
81 docker build -t "$($env:DOCKER_IMAGE):$($env:IMAGE_TAG)" -f build\docker\msvc2017\Dockerfile 'build\'
82 if ($LASTEXITCODE -ne 0) {
83 Write-Error "Docker build failed"
84 exit 1
85 }
86 Write-Host "Verifying tags were created:"
87 docker images "$($env:DOCKER_IMAGE)"
88
89 - name: Push Docker image
90 if: github.event_name != 'pull_request' && steps.pull_cached.outputs.need_build == 'true'
91 shell: pwsh
92 run: |
93 Write-Host "Pushing hash-based tag only: $($env:DOCKER_IMAGE):$($env:IMAGE_TAG)"
94 docker push "$($env:DOCKER_IMAGE):$($env:IMAGE_TAG)"
95 if ($LASTEXITCODE -ne 0) {
96 Write-Error "Failed to push hash-based tag"
97 exit 1
98 }
99 Write-Host "Successfully pushed hash-tagged image"
100
101 - name: Build and test inside container
102 shell: pwsh
103 run: |
104 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\msvc2017\build.bat
105
106 - name: Check test results
107 if: always()
108 shell: pwsh
109 run: |
110 $logPath = Join-Path $env:THRIFT_BUILD_DIR 'Testing\Temporary\LastTest.log'
111 if (Test-Path $logPath) {
112 $content = Get-Content $logPath -Raw
113 if ($content -match 'Test Failed\.') {
114 Write-Error "Tests failed - check LastTest.log artifact for details"
115 exit 1
116 } else {
117 Write-Host "All tests passed"
118 }
119 } else {
120 Write-Warning "LastTest.log not found at $logPath"
121 }
122
123 - name: Upload LastTest log
124 if: always()
125 uses: actions/upload-artifact@v4
126 with:
127 name: msvc2017-LastTest-log
128 path: ${{ env.THRIFT_BUILD_DIR }}\Testing\Temporary\LastTest.log
129 if-no-files-found: warn