Last active
December 24, 2021 20:12
-
-
Save Zingam/48fd980e5ef35335282a6c8203a45d03 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Version format | |
version: 1.0.0.{build} | |
image: Visual Studio 2017 | |
platform: x64 | |
configuration: | |
- Debug | |
# - Release | |
environment: | |
VCPKG_ROOT: c:/tools/vcpkg | |
CoverityScanToken: | |
secure: R5iKcUqFlDHXEM5mD8NMvlRqKF2yIEQH+0ZvrsLBrOE= | |
CoverityScanEmail: | |
secure: MhbF2+Iukp8Z+ltTigOZbgG5564cfXoWpsHp2mLypEs= | |
# scripts that are called at very beginning, before repo cloning | |
init: | |
- ps: | | |
# Set environment variables | |
If ($env:PLATFORM -eq "x64") | |
{ | |
$env:vcpkgTriplet = "x64-windows" | |
$env:Generator = "Ninja" | |
#$env:Generator = "Visual Studio 15 2017 Win64" | |
} | |
If ( $env:CONFIGURATION -eq "Debug" ) | |
{ | |
$env:option_CheckGraphicsApiCalls = "YES" | |
} | |
else | |
{ | |
$env:option_CheckGraphicsApiCalls = "NO" | |
} | |
# Path variables | |
$env:ArchivePath = "$env:APPVEYOR_BUILD_FOLDER/__archive-output/$env:vcpkgTriplet-$env:CONFIGURATION" | |
$env:BuildPath = "$env:APPVEYOR_BUILD_FOLDER/__build-output/$env:vcpkgTriplet-$env:CONFIGURATION" | |
$env:InstallPath = "$env:APPVEYOR_BUILD_FOLDER/__install-output/$env:vcpkgTriplet-$env:CONFIGURATION" | |
$env:vcpkgCachePath = "C:/tools/vcpkg/installed" | |
function Get-CannonicalPath | |
{ | |
param ($Path) | |
$newPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($path) | |
$root = [System.IO.Path]::GetPathRoot($newPath) | |
# Handle root directory | |
If ($newPath -eq $root) | |
{ | |
return $root | |
} | |
return $newPath.Replace("\", "/") | |
} | |
$env:ArchivePath = Get-CannonicalPath -Path $env:ArchivePath | |
$env:BuildPath = Get-CannonicalPath -Path $env:BuildPath | |
$env:InstallPath = Get-CannonicalPath -Path $env:InstallPath | |
$env:vcpkgCachePath = Get-CannonicalPath -Path $env:vcpkgCachePath | |
# Date & Version | |
# Get a sortable timestamp | |
# https://docs.microsoft.com/en-us/dotnet/api/system.globalization.datetimeformatinfo?view=netframework-4.7.2 | |
$env:timestamp = Get-Date -format s | foreach {$_ -replace ":", "."} | |
$env:BuildVersion = "$env:APPVEYOR_BUILD_VERSION-$env:timestamp" | |
# Archive names | |
$env:ArchiveName = "$env:APPVEYOR_PROJECT_NAME-$env:CONFIGURATION-$env:BuildVersion.zip" | |
$env:CoverityScanArchiveName = "CoverityScan-$env:ArchiveName" | |
install: | |
- ps: | | |
If ("$env:Generator" -eq "Ninja") | |
{ | |
$env:PIP_DISABLE_PIP_VERSION_CHECK = 1 | |
pip install ninja | |
ninja --version | |
} | |
# Preserve contents of selected directories and files across project builds | |
cache: | |
# Invalidate cache on "appveyor.yml" change | |
# - C:/tools/vcpkg/installed -> appveyor.yml | |
- C:/tools/vcpkg/installed | |
build_script: | |
- ps: | | |
# Install packages | |
If (-Not (Test-Path $env:vcpkgCachePath)) | |
{ | |
# Update vcpkg | |
cd "C:/Tools/vcpkg" | |
git pull | |
# Uncomment to rebuild vcpkg | |
#./bootstrap-vcpkg.bat | |
cd %APPVEYOR_BUILD_FOLDER% | |
vcpkg install --recurse --triplet $env:vcpkgTriplet freetype sdl2 | |
} | |
# Setup build environment | |
If ("$env:Generator" -eq "Ninja") | |
{ | |
# Store the environment variables from the Batch script to a temporary file | |
cmd.exe /c "call `"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat`" && set > %APPVEYOR_BUILD_FOLDER%\vcvars64.txt" | |
# Set the environment variables from the temporary file in PowerShell | |
Get-Content "$env:APPVEYOR_BUILD_FOLDER\vcvars64.txt" | ForEach-Object -Process ` | |
{ | |
If ($_ -match "^(.*?)=(.*)$") | |
{ | |
Set-Item -Force -Path "env:\$($matches[1])" -Value $matches[2] | |
} | |
} | |
} | |
# Create output paths | |
mkdir $env:ArchivePath | |
mkdir $env:BuildPath | |
mkdir $env:InstallPath | |
cd $env:BuildPath | |
function Execute-Command { | |
param ([string]$FilePath, [string]$ArgumentList) | |
$psInfo = New-Object System.Diagnostics.ProcessStartInfo | |
$psInfo.FileName = $FilePath | |
$psInfo.Arguments = $ArgumentList | |
$psInfo.WorkingDirectory = Get-Location | |
$psInfo.RedirectStandardError = $true | |
$psInfo.RedirectStandardOutput = $true | |
$psInfo.UseShellExecute = $false | |
$ps = New-Object System.Diagnostics.Process | |
$ps.StartInfo = $psInfo | |
$ps.Start() | Out-Null | |
$ps.WaitForExit() | |
$stdout = $ps.StandardOutput.ReadToEnd() | |
$stderr = $ps.StandardError.ReadToEnd() | |
Write-Host "$stdout" | |
Write-Host "$stderr" | |
Write-Host "[$FilePath] Process exited with code: " $ps.ExitCode | |
} | |
# Set CMake arguments | |
$env:cmakeArguments = @( | |
'-G"%Generator%"', | |
'-D"CMAKE_BUILD_TYPE:STRING=%CONFIGURATION%"', | |
'-D"option_EngineLibraryAs_SHARED:BOOL=YES"', | |
'-D"option_CheckGraphicsApiCalls:BOOL=%option_CheckGraphicsApiCalls%"', | |
'-D"CMAKE_INSTALL_PREFIX:STRING=%InstallPath%"', | |
'"../../GunBox"' | |
) | |
$env:cmakeArgumentList = [System.Environment]::ExpandEnvironmentVariables("$env:cmakeArguments") | |
# Configure CMake project | |
Write-Host "`nCMake configuration started...`n" | |
cmake --version | |
Execute-Command -FilePath "cmake" -ArgumentList "$env:cmakeArgumentList" | |
Write-Host "`nCMake configuration completed...`n" | |
# Run Coverity Scan on forced builds (via the "New Build" option) | |
If ($env:APPVEYOR_FORCED_BUILD -eq "True") | |
{ | |
cov-build --dir cov-int/ cmake --build . | |
# Compress scan results recursively | |
7z a -r "$env:ArchivePath/$env:CoverityScanArchiveName" cov-int/ | |
# Deploy build artifact | |
Push-AppveyorArtifact "$env:ArchivePath/$env:CoverityScanArchiveName" | |
# Publish results for analysis | |
$env:curlArguments = @( | |
'--form token=%CoverityScanToken%', | |
'--form email=%CoverityScanEmail%', | |
'--form file=@%ArchivePath%/%CoverityScanArchiveName%', | |
'--form version="%BuildVersion%"', | |
'--form description="GunBox"', | |
'https://scan.coverity.com/builds?project=Zingam%2FGunBox' | |
) | |
$env:curlArgumentList = [System.Environment]::ExpandEnvironmentVariables("$env:curlArguments") | |
Write-Host "env:curlArgumentList = $env:curlArgumentList" | |
Execute-Command -FilePath "curl" -ArgumentList "$env:curlArgumentList" | |
return | |
} | |
# Build artifacts | |
cmake --build . | |
cmake --build . --target install | |
# Deploy build artifact | |
$env:archivePushLocation = "$env:ArchivePath/$env:ArchiveName" | |
Add-Type -AssemblyName "System.IO.Compression.FileSystem" | |
[IO.Compression.ZipFile]::CreateFromDirectory( | |
"$env:InstallPath", | |
"$env:archivePushLocation", | |
[IO.Compression.CompressionLevel]::Optimal, | |
$false | |
) | |
Push-AppveyorArtifact "$env:archivePushLocation" | |
on_finish: | |
# Uncomment to enable a Remote Desktop session | |
#- ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Version 3.0: https://gist.github.com/Zingam/48fd980e5ef35335282a6c8203a45d03/3c47427162dfe7cb2b7b709af18d08f26db40ed4
Version 2.3: https://gist.github.com/Zingam/48fd980e5ef35335282a6c8203a45d03/ab6a6d5bb6fcdbc011af0a5ceb6cdf66431ba622
Version 2.2: https://gist.github.com/Zingam/48fd980e5ef35335282a6c8203a45d03/433ac47efa51d14a9371748a4bc92eb9a31c3551
Version 2.1: https://gist.github.com/Zingam/48fd980e5ef35335282a6c8203a45d03/fd36385c23816f233d900299d70dd3d448db30a6
Version 2.0: https://gist.github.com/Zingam/48fd980e5ef35335282a6c8203a45d03/c8fad7d1a0c189d1c11e4ddd2fe69b3911ee4fb6
Version 1.1: https://gist.github.com/Zingam/48fd980e5ef35335282a6c8203a45d03/7e61308a83ad2ba7eea673cd8e3753909847c5e7
Version 1.0: https://gist.github.com/Zingam/48fd980e5ef35335282a6c8203a45d03/2c5bb9c6fe6bd980417119b6311fe22e3cba14a6