-
Notifications
You must be signed in to change notification settings - Fork 57
234 lines (215 loc) · 10.5 KB
/
Copy pathwindows-build.yml
File metadata and controls
234 lines (215 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
name: windows-build
on:
push:
pull_request:
permissions:
contents: read
jobs:
build:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
include:
- arch: x64
cmake_platform: x64
configuration: Release
cmake_extra_args: ""
vcpkg_triplet: x64-windows
- arch: x86
cmake_platform: Win32
configuration: Release
cmake_extra_args: -DWITH_ASM=OFF
vcpkg_triplet: x86-windows
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Select Visual Studio generator
id: vs_generator
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$vswhere = Join-Path ${env:ProgramFiles(x86)} "Microsoft Visual Studio\Installer\vswhere.exe"
$vsInstances = & $vswhere -latest -products * -format json | ConvertFrom-Json
$vsInstance = @($vsInstances)[0]
if ($null -eq $vsInstance) {
Write-Error "No Visual Studio installation was found."
exit 1
}
$vsVersion = [string]$vsInstance.installationVersion
if ([string]::IsNullOrWhiteSpace($vsVersion)) {
Write-Error "Visual Studio installation did not report a version."
exit 1
}
$vcToolsVersionFile = Join-Path $vsInstance.installationPath "VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt"
if (-not (Test-Path $vcToolsVersionFile)) {
Write-Error "Visual Studio was found, but C++ tools were not found at $vcToolsVersionFile."
exit 1
}
$major = [int]($vsVersion.Split(".")[0])
if ($major -ge 18) {
$generator = "Visual Studio 18 2026"
} elseif ($major -eq 17) {
$generator = "Visual Studio 17 2022"
} else {
Write-Error "Unsupported Visual Studio version: $vsVersion"
exit 1
}
$cmake = Get-Command cmake -ErrorAction SilentlyContinue
if ($null -eq $cmake) {
Write-Error "CMake was not found on PATH."
exit 1
}
$cmakeHelp = & $cmake.Source --help | Out-String
if (-not $cmakeHelp.Contains($generator)) {
Write-Error "The installed CMake does not support the '$generator' generator."
exit 1
}
"cmake_generator=$generator" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
"vs_major=$major" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
Write-Host "Using CMake generator: $generator"
- name: Cache vcpkg
uses: actions/cache@v4
with:
path: |
C:\vcpkg\downloads
C:\vcpkg\archives
C:\vcpkg\buildtrees
C:\vcpkg\packages
C:\vcpkg\binarycache
key: ${{ runner.os }}-${{ matrix.arch }}-vs${{ steps.vs_generator.outputs.vs_major }}-vcpkg-${{ hashFiles('vcpkg.json', 'vcpkg-configuration.json') }}
- name: Install FFmpeg (vcpkg)
shell: pwsh
run: |
$vcpkgRoot = "C:\vcpkg"
if (-not (Test-Path $vcpkgRoot)) {
git clone https://github.com/microsoft/vcpkg $vcpkgRoot
}
& "$vcpkgRoot\bootstrap-vcpkg.bat"
$env:VCPKG_BINARY_SOURCES = "clear;files,C:\vcpkg\binarycache,readwrite"
Push-Location $env:GITHUB_WORKSPACE
& "$vcpkgRoot\vcpkg.exe" install --triplet ${{ matrix.vcpkg_triplet }}
Pop-Location
- name: Cache CMake deps
uses: actions/cache@v4
with:
path: Projects/VS/_deps
key: ${{ runner.os }}-${{ matrix.arch }}-vs${{ steps.vs_generator.outputs.vs_major }}-cmake-deps-${{ hashFiles('CMakeLists.txt') }}
- name: Configure
run: cmake -S . -B Projects/VS -G "${{ steps.vs_generator.outputs.cmake_generator }}" -A ${{ matrix.cmake_platform }} ${{ matrix.cmake_extra_args }} -DOPENFODDER_ENABLE_FFMPEG=ON -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=${{ matrix.vcpkg_triplet }}
- name: Build
run: cmake --build Projects/VS --config ${{ matrix.configuration }}
- name: Test
shell: pwsh
run: |
$runDir = "$env:GITHUB_WORKSPACE\Run"
$stashDir = "$env:RUNNER_TEMP\openfodder-runtime"
$ffmpegBin = "$env:GITHUB_WORKSPACE\vcpkg_installed\${{ matrix.vcpkg_triplet }}\bin"
if (-not (Test-Path $ffmpegBin)) {
$ffmpegBin = "C:\vcpkg\installed\${{ matrix.vcpkg_triplet }}\bin"
}
New-Item -ItemType Directory -Path $stashDir -Force | Out-Null
Copy-Item "$runDir\openfodder.exe" -Destination $stashDir -Force -ErrorAction SilentlyContinue
Copy-Item "$runDir\SDL3.dll" -Destination $stashDir -Force -ErrorAction SilentlyContinue
Copy-Item "$runDir\SDL3_mixer.dll" -Destination $stashDir -Force -ErrorAction SilentlyContinue
$dataRepoDir = "$env:RUNNER_TEMP\openfodder-data"
if (Test-Path $dataRepoDir) { Remove-Item $dataRepoDir -Recurse -Force }
git clone --single-branch https://github.com/OpenFodder/data.git $dataRepoDir
if (Test-Path $runDir) { Remove-Item $runDir -Recurse -Force }
New-Item -ItemType Directory -Path $runDir -Force | Out-Null
Copy-Item "$dataRepoDir\*" $runDir -Recurse -Force
Copy-Item "$stashDir\openfodder.exe" -Destination $runDir -Force -ErrorAction SilentlyContinue
Copy-Item "$stashDir\SDL3.dll" -Destination $runDir -Force -ErrorAction SilentlyContinue
Copy-Item "$stashDir\SDL3_mixer.dll" -Destination $runDir -Force -ErrorAction SilentlyContinue
if (Test-Path "$runDir/Tests") { Remove-Item "$runDir/Tests" -Recurse -Force }
git clone https://github.com/OpenFodder/tests.git $runDir/Tests
Copy-Item "$ffmpegBin\avcodec*.dll" -Destination $runDir -Force
Copy-Item "$ffmpegBin\avformat*.dll" -Destination $runDir -Force
Copy-Item "$ffmpegBin\avutil*.dll" -Destination $runDir -Force
Copy-Item "$ffmpegBin\swscale*.dll" -Destination $runDir -Force
Copy-Item "$ffmpegBin\swresample*.dll" -Destination $runDir -Force
Push-Location $runDir
.\openfodder.exe --appveyor --unit-test-headless
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
Pop-Location
- name: Package
shell: pwsh
run: |
$archive = "OpenFodder-${{ matrix.arch }}-${{ matrix.configuration }}-latest.zip"
$ffmpegBin = "$env:GITHUB_WORKSPACE\vcpkg_installed\${{ matrix.vcpkg_triplet }}\bin"
if (-not (Test-Path $ffmpegBin)) {
$ffmpegBin = "C:\vcpkg\installed\${{ matrix.vcpkg_triplet }}\bin"
}
if (-not (Test-Path $ffmpegBin)) {
Write-Error "FFmpeg binaries not found in vcpkg_installed or C:\vcpkg\installed for ${{ matrix.vcpkg_triplet }}."
exit 1
}
$ffmpegDlls = Get-ChildItem $ffmpegBin -Filter *.dll | Where-Object {
$_.Name -match "^(avcodec|avformat|avutil|swscale|swresample)"
} | Select-Object -ExpandProperty FullName
$items = @(
"$env:GITHUB_WORKSPACE\Run\openfodder.exe",
"$env:GITHUB_WORKSPACE\Run\SDL3.dll",
"$env:GITHUB_WORKSPACE\Run\SDL3_mixer.dll",
"$env:GITHUB_WORKSPACE\README.md",
"$env:GITHUB_WORKSPACE\COPYING",
"$env:GITHUB_WORKSPACE\openfodder.ini.example"
) + $ffmpegDlls
if (Test-Path $archive) { Remove-Item $archive -Force }
Compress-Archive -Path $items -DestinationPath $archive
- name: Upload artifact
uses: actions/upload-artifact@v4
id: upload_artifact
with:
name: OpenFodder-${{ matrix.arch }}-${{ matrix.configuration }}-latest
path: OpenFodder-${{ matrix.arch }}-${{ matrix.configuration }}-latest.zip
- name: Configure AWS credentials
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION || 'us-east-1' }}
- name: Upload build zip to S3
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
shell: pwsh
run: |
$zipName = "OpenFodder-${{ matrix.arch }}-${{ matrix.configuration }}-latest.zip"
aws s3 cp "$zipName" "s3://openfodder-builds/$zipName" --acl public-read
- name: Discord notification
if: always() && github.event_name == 'push' && github.ref == 'refs/heads/master'
shell: pwsh
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
run: |
if ([string]::IsNullOrWhiteSpace($env:DISCORD_WEBHOOK_URL)) { exit 0 }
$status = if ("${{ job.status }}" -eq "success") { "Success" } else { "Failure" }
$color = if ("${{ job.status }}" -eq "success") { 3066993 } else { 15158332 }
$title = "OpenFodder Windows build $status (${{ matrix.arch }})"
$runUrl = "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
$artifactUrl = "https://s3.amazonaws.com/openfodder-builds/OpenFodder-${{ matrix.arch }}-${{ matrix.configuration }}-latest.zip"
$event = Get-Content $env:GITHUB_EVENT_PATH -Raw | ConvertFrom-Json
$commitMessage = $event.head_commit.message
if (-not $commitMessage) { $commitMessage = $event.pull_request.title }
if (-not $commitMessage) { $commitMessage = "N/A" }
$payload = @{
username = "GitHub Actions"
embeds = @(
@{
title = $title
url = $runUrl
color = $color
fields = @(
@{ name = "Commit"; value = "${{ github.sha }}"; inline = $true }
@{ name = "Branch"; value = "${{ github.ref_name }}"; inline = $true }
@{ name = "Config"; value = "${{ matrix.configuration }}"; inline = $true }
@{ name = "Commit Message"; value = $commitMessage; inline = $false }
@{ name = "Download"; value = $artifactUrl; inline = $false }
)
}
)
} | ConvertTo-Json -Depth 5
Invoke-RestMethod -Method Post -Uri $env:DISCORD_WEBHOOK_URL -ContentType "application/json" -Body $payload