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: | |
# - Ubuntu | |
- Visual Studio 2017 | |
platform: x64 | |
configuration: | |
- Debug | |
# - Release | |
environment: | |
VCPKG_ROOT: | |
"%APPVEYOR_BUILD_FOLDER%/vcpkg" | |
CoverityScan_Enabled: | |
true | |
CoverityScanToken: | |
secure: R5iKcUqFlDHXEM5mD8NMvlRqKF2yIEQH+0ZvrsLBrOE= | |
CoverityScanEmail: | |
secure: MhbF2+Iukp8Z+ltTigOZbgG5564cfXoWpsHp2mLypEs= | |
# Preserve contents of selected directories and files across project builds | |
cache: | |
# Set dependency on "appveyor.yml" and invalidate cache on change | |
'%vcpkgCachePath% -> appveyor.yml' | |
# Scripts that are called at very beginning, before repo cloning | |
init: | |
- ps: | | |
################################################ | |
# Helper functions | |
################################################ | |
# Write out a Script Module to a file | |
Set-Content -Path "../$AppveyorCI_Functions.psm1" -Value ` | |
@' | |
function Get-CannonicalPath | |
{ | |
# Process parameters | |
param ( | |
[Parameter (Mandatory=$true)] | |
#[ValidatePattern ("^(?!\s*$).+", ErrorMessage = "A non-empty string is required.")] | |
[string] $FullPathName | |
) | |
$newPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($FullPathName) | |
$root = [System.IO.Path]::GetPathRoot($newPath) | |
# Handle root directory | |
if ($newPath -eq $root) | |
{ | |
return $root | |
} | |
return $newPath.Replace("\", "/") | |
} | |
function Invoke-Executable | |
{ | |
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 | |
} | |
function Stop-AppveyorBuild | |
{ | |
# Process parameters | |
param ( | |
[Parameter (Mandatory=$true)] | |
#[ValidatePattern ("^(?!\s*$).+", ErrorMessage = "A non-empty string is required.")] | |
[string] $ErrorMessage | |
) | |
$env:APPVEYOR_SKIP_FINALIZE_ON_EXIT = $true | |
Write-Host $ErrorMessage | |
Exit-AppveyorBuild | |
} | |
function Write-ArrayElements | |
{ | |
param ( | |
[Parameter (Mandatory=$true)] | |
#[ValidatePattern ("^(?!\s*$).+", ErrorMessage = "A non-empty string is required.")] | |
[string] $ArrayName, | |
[Parameter (Mandatory=$true)] | |
[array] $Array | |
) | |
Write-Host "Array element list $ArrayName =" | |
foreach ($element in $Array) | |
{ | |
$element = [System.Environment]::ExpandEnvironmentVariables($element) | |
Write-Host " $element," | |
} | |
} | |
function Write-EnvVariables | |
{ | |
Write-Host "Environment variables:" | |
Write-Host " - CMake command line options" | |
Write-Host " `$env:option_CheckGraphicsApiCalls = $env:option_CheckGraphicsApiCalls" | |
Write-Host " - Platform & Target variables" | |
Write-Host " `$env:Generator = $env:Generator" | |
Write-Host " `$env:TargetPlatform = $env:TargetPlatform" | |
Write-Host " `$env:vcpkgTriplet = $env:vcpkgTriplet" | |
Write-Host " - Path variables" | |
Write-Host " `$env:ArchivePath = $env:ArchivePath" | |
Write-Host " `$env:BuildPath = $env:BuildPath" | |
Write-Host " `$env:InstallPath = $env:InstallPath" | |
Write-Host " `$env:vcpkgCachePath = $env:vcpkgCachePath" | |
Write-Host " - Date & Version variables" | |
Write-Host " `$env:BuildVersion = $env:BuildVersion" | |
Write-Host " - Archive names" | |
Write-Host " `$env:ArchiveName = $env:ArchiveName" | |
Write-Host " `$env:CoverityScanArchiveName = $env:CoverityScanArchiveName" | |
} | |
Export-ModuleMember -Function Get-CannonicalPath | |
Export-ModuleMember -Function Invoke-Executable | |
Export-ModuleMember -Function Stop-AppveyorBuild | |
Export-ModuleMember -Function Write-ArrayElements | |
Export-ModuleMember -Function Write-EnvVariables | |
'@ | |
################################################ | |
# Include common functions | |
################################################ | |
Import-Module "../$AppveyorCI_Functions.psm1" | |
################################################ | |
# Set environment variables | |
################################################ | |
# CMake command line options | |
if ("Debug" -eq $env:CONFIGURATION) | |
{ | |
$env:option_CheckGraphicsApiCalls = "YES" | |
} | |
else | |
{ | |
$env:option_CheckGraphicsApiCalls = "NO" | |
} | |
# Platform & Target variables | |
if ("x64" -eq $env:PLATFORM) | |
{ | |
if ("Visual Studio 2017" -eq $env:APPVEYOR_BUILD_WORKER_IMAGE) | |
{ | |
$env:Generator = "Ninja" | |
#$env:Generator = "Visual Studio 15 2017 Win64" | |
$env:TargetPlatform = "Windows" | |
} | |
elseif ("Ubuntu" -eq $env:APPVEYOR_BUILD_WORKER_IMAGE) | |
{ | |
$env:Generator = "Ninja" | |
$env:TargetPlatform = "Linux" | |
} | |
else | |
{ | |
return Stop-AppveyorBuild "Unknown worker image: $env:APPVEYOR_BUILD_WORKER_IMAGE" | |
} | |
$env:vcpkgTriplet = "x64" | |
} | |
else | |
{ | |
return Stop-AppveyorBuild "Unknown target platform: $PLATFORM" | |
} | |
$env:vcpkgTriplet = "$env:vcpkgTriplet-$env:TargetPlatform".ToLower() | |
# Path variables | |
$archivePath = "$env:APPVEYOR_BUILD_FOLDER/__archive-output/$env:vcpkgTriplet-$env:CONFIGURATION" | |
$buildPath = "$env:APPVEYOR_BUILD_FOLDER/__build-output/$env:vcpkgTriplet-$env:CONFIGURATION" | |
$installPath = "$env:APPVEYOR_BUILD_FOLDER/__install-output/$env:vcpkgTriplet-$env:CONFIGURATION" | |
$vcpkgCachePath = "$env:VCPKG_ROOT/installed" | |
$env:ArchivePath = Get-CannonicalPath -FullPathName $archivePath | |
$env:BuildPath = Get-CannonicalPath -FullPathName $buildPath | |
$env:InstallPath = Get-CannonicalPath -FullPathName $installPath | |
$env:vcpkgCachePath = Get-CannonicalPath -FullPathName $vcpkgCachePath | |
# Date & Version variables | |
Set-TimeZone -Name "FLE Standard Time" | |
# Get a sortable timestamp: | |
# https://docs.microsoft.com/en-us/dotnet/api/system.globalization.datetimeformatinfo?view=netframework-4.7.2 | |
$timestamp = Get-Date -format s | foreach {$_ -replace ":", "-"} | |
$env:BuildVersion = "$env:APPVEYOR_BUILD_VERSION-D$timestamp" | |
# Archive names | |
$env:ArchiveName = "$env:APPVEYOR_PROJECT_NAME-$env:CONFIGURATION-$env:BuildVersion.zip" | |
$env:CoverityScanArchiveName = "CoverityScan-$env:ArchiveName" | |
Write-EnvVariables | |
# Scripts that run after cloning a repository | |
install: | |
- ps: | | |
if ("Ninja" -eq $env:Generator) | |
{ | |
$env:PIP_DISABLE_PIP_VERSION_CHECK = 1 | |
pip install ninja | |
ninja --version | |
} | |
# Custom build scripts that run instead of automatic MSBuild | |
build_script: | |
- ps: | | |
################################################ | |
# Include common functions | |
################################################ | |
Import-Module "../$AppveyorCI_Functions.psm1" | |
################################################ | |
# Install packages | |
if (-not (Test-Path $env:vcpkgCachePath)) | |
{ | |
# Update vcpkg | |
git clone -q https://github.com/Microsoft/vcpkg.git | |
# Uncomment to rebuild vcpkg | |
cd $env:VCPKG_ROOT | |
if ("Windows" -eq $env:TargetPlatform) | |
{ | |
./bootstrap-vcpkg.bat | |
} | |
elseif ("Linux" -eq $env:TargetPlatform) | |
{ | |
./bootstrap-vcpkg.sh | |
} | |
else | |
{ | |
return Stop-AppveyorBuild "Unknown target platform: $env:TargetPlatform" | |
} | |
vcpkg install --recurse --triplet $env:vcpkgTriplet freetype sdl2 | |
cd $env:APPVEYOR_BUILD_FOLDER | |
} | |
# Setup build environment | |
if (("Windows" -eq $env:TargetPlatform) ` | |
-and ("Ninja" -eq $env:Generator)) | |
{ | |
# 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 | |
# Set CMake arguments | |
$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"' | |
) | |
$cmakeArgumentList = [System.Environment]::ExpandEnvironmentVariables($cmakeArguments) | |
# Configure CMake project | |
Write-Host "`nCMake configuration started...`n" | |
cmake --version | |
Invoke-Executable -FilePath "cmake" -ArgumentList $cmakeArgumentList | |
Write-Host "`nCMake configuration completed...`n" | |
# Run Coverity Scan on forced builds (via the "New Build" option) | |
if (($true -eq $env:CoverityScan_Enabled) ` | |
-and ($true -eq $env:APPVEYOR_FORCED_BUILD)) | |
{ | |
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 | |
$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' | |
) | |
$curlArgumentList = [System.Environment]::ExpandEnvironmentVariables($curlArguments) | |
Invoke-Executable -FilePath "curl" -ArgumentList $curlArgumentList | |
return Stop-AppveyorBuild "CoverityScan build completed..." | |
} | |
# Build artifacts | |
cmake --build . | |
cmake --build . --target install | |
# Deploy build artifact | |
$archivePushLocation = "$env:ArchivePath/$env:ArchiveName" | |
Add-Type -AssemblyName "System.IO.Compression.FileSystem" | |
[IO.Compression.ZipFile]::CreateFromDirectory( | |
"$env:InstallPath", | |
"$archivePushLocation", | |
[IO.Compression.CompressionLevel]::Optimal, | |
$false | |
) | |
Push-AppveyorArtifact $archivePushLocation | |
# Scripts that run after build success/failure | |
on_finish: | |
# Uncomment to enable a Remote Desktop session | |
#- pwsh: $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