From 7e0d49ecc6e6e06d34216fa36e0876c3c313a9e1 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Wed, 27 Jan 2016 18:47:06 +0000 Subject: [PATCH] replace build number with branch, commit or tag --- appveyor.yml | 2 +- scripts/ps/appveyor_run.ps1 | 120 ++++++++++++++++++++++++++++-------- scripts/ps/publish.ps1 | 69 ++++++++++++++------- 3 files changed, 142 insertions(+), 49 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index ebc413671f..ae5bb97bfc 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -14,7 +14,7 @@ install: - ps: >- curl "http://nsis.sourceforge.net/mediawiki/images/5/53/KillProcDll%26FindProcDll.zip" -OutFile nsisxtra.zip - 7z x nsisxtra.zip + 7z x nsisxtra.zip > $null cp FindProcDLL.dll "C:\ProgramData\chocolatey\lib\nsis.portable\tools\nsis-3.0b1\Plugins\x86-ansi" build_script: diff --git a/scripts/ps/appveyor_run.ps1 b/scripts/ps/appveyor_run.ps1 index d69b8c128b..baab8d99bb 100644 --- a/scripts/ps/appveyor_run.ps1 +++ b/scripts/ps/appveyor_run.ps1 @@ -15,18 +15,61 @@ function Push-Build($file, $name, $version, $flavourId) "https://openrct2.org/altapi/?command=push-build" } +$server = "AppVeyor" + # Provide a short commit SHA1 too ${env:APPVEYOR_REPO_COMMIT_SHORT} = (${env:APPVEYOR_REPO_COMMIT}).Substring(0, 7) +# Current version +$version = "0.0.4.0" + +# Tagged builds will hide branch and commit SHA1 +$tag = $null +if (${env:APPVEYOR_REPO_TAG} -ne $null) +{ + $tag = ${env:APPVEYOR_REPO_TAG_NAME} +} + +# Enable code signing if password environment variable is set +$codeSign = $false +if (${env:CODE-SIGN-KEY-OPENRCT2.ORG.PFX.PASSWORD} -ne $null) +{ + $codeSign = $true +} + +# Enable pushing builds to OpenRCT2.org if token environment variable is set +$pushBuilds = $false +$installer = $false +if (${env:OPENRCT2.ORG_TOKEN} -ne $null) +{ + $pushBuilds = $true + $installer = $true +} + +# Write out summary of the build +Write-Host "AppVeyor CI Build" -ForegroundColor Green +if ($tag -ne $null) +{ + Write-Host " $version-$tag" -ForegroundColor Green +} +else +{ + Write-Host " $version-$env:APPVEYOR_REPO_BRANCH-$env:APPVEYOR_REPO_COMMIT_SHORT" -ForegroundColor Green +} +Write-Host " Signed: $codeSign" -ForegroundColor Green +Write-Host " Push : $pushBuilds" -ForegroundColor Green + # Install dependencies install -Quiet # Build OpenRCT2 publish build ` - -Server AppVeyor ` - -BuildNumber $env:APPVEYOR_BUILD_NUMBER ` - -GitBranch $env:APPVEYOR_REPO_BRANCH ` - -CodeSign + -Server $server ` + -GitTag $tag ` + -GitBranch $env:APPVEYOR_REPO_BRANCH ` + -GitSha1 $env:APPVEYOR_REPO_COMMIT ` + -GitSha1Short $env:APPVEYOR_REPO_COMMIT_SHORT ` + -CodeSign $codeSign if ($LASTEXITCODE -ne 0) { @@ -34,31 +77,54 @@ if ($LASTEXITCODE -ne 0) } # Create a Portable ZIP -publish package ` - -Server AppVeyor ` - -BuildNumber $env:APPVEYOR_BUILD_NUMBER ` - -GitBranch $env:APPVEYOR_REPO_BRANCH +publish package ` + -Server $server ` + -GitTag $tag ` + -GitBranch $env:APPVEYOR_REPO_BRANCH ` + -GitSha1 $env:APPVEYOR_REPO_COMMIT ` + -GitSha1Short $env:APPVEYOR_REPO_COMMIT_SHORT ` + -CodeSign $codeSign # Create an Installer -publish package ` - -Installer ` - -Server AppVeyor ` - -BuildNumber $env:APPVEYOR_BUILD_NUMBER ` - -GitBranch $env:APPVEYOR_REPO_BRANCH ` - -CodeSign +if ($installer) +{ + publish package ` + -Installer ` + -Server $server ` + -GitTag $tag ` + -GitBranch $env:APPVEYOR_REPO_BRANCH ` + -GitSha1 $env:APPVEYOR_REPO_COMMIT ` + -GitSha1Short $env:APPVEYOR_REPO_COMMIT_SHORT ` + -CodeSign $codeSign +} -$version = "0.0.4.0" -$pushFileName = "OpenRCT2-$version-windows-${env:APPVEYOR_REPO_COMMIT_SHORT}" +if ($pushBuilds) +{ + $versionExtension = "" + if ($tag -ne $null) + { + $versionExtension = "-$tag" + } + else + { + $versionExtension = "-${env:APPVEYOR_REPO_BRANCH}-${env:APPVEYOR_REPO_COMMIT_SHORT}" + } + $pushFileName = "OpenRCT2-${version}${versionExtension}-windows" -# Push portable zip -Write-Host "Sending portable zip to OpenRCT2.org" -ForegroundColor Cyan -Push-Build -file ".\artifacts\openrct2.zip" ` - -name "$pushFileName.zip" ` - -version $version ` - -flavourId 1 + # Push portable zip + Write-Host "Sending portable zip to OpenRCT2.org" -ForegroundColor Cyan + Push-Build -file ".\artifacts\openrct2.zip" ` + -name "$pushFileName.zip" ` + -version $version ` + -flavourId 1 -Write-Host "Sending installer to OpenRCT2.org" -ForegroundColor Cyan -Push-Build -file ".\artifacts\openrct2-install.exe" ` - -name "$pushFileName.exe" ` - -version $version ` - -flavourId 2 + # Push installer + if ($installer) + { + Write-Host "Sending installer to OpenRCT2.org" -ForegroundColor Cyan + Push-Build -file ".\artifacts\openrct2-install.exe" ` + -name "$pushFileName.exe" ` + -version $version ` + -flavourId 2 + } +} diff --git a/scripts/ps/publish.ps1 b/scripts/ps/publish.ps1 index bd70effaf9..a0e2a3532c 100644 --- a/scripts/ps/publish.ps1 +++ b/scripts/ps/publish.ps1 @@ -6,15 +6,33 @@ ######################################################### param ( [Parameter(Position = 1)] - [string]$Task = "all", + [string]$Task = "all", - [string]$Server = "", - [string]$BuildNumber = "", - [string]$GitBranch = "", - [switch]$Installer = $false, - [switch]$CodeSign = $false + [string]$Server = "", + [string]$GitTag = "", + [string]$GitBranch = "", + [string]$GitSha1 = "", + [string]$GitSha1Short = "", + [bool] $CodeSign = $false, + [switch]$Installer = $false ) +if ($GitTag -eq "") +{ + if ($GitBranch -eq $null) + { + $GitBranch = (git rev-parse --abbrev-ref HEAD) + } + if ($GitCommitSha1 -eq $null) + { + $GitCommitSha1 = (git rev-parse HEAD) + } + if ($GitCommitSha1Short -eq $null) + { + $GitCommitSha1Short = (git rev-parse --short HEAD) + } +} + # Setup $ErrorActionPreference = "Stop" $scriptsPath = Split-Path $Script:MyInvocation.MyCommand.Path @@ -27,19 +45,18 @@ $rootPath = Get-RootPath function Do-PrepareSource() { Write-Host "Setting build #defines..." -ForegroundColor Cyan - if ($GitBranch -eq "") - { - $GitBranch = (git rev-parse --abbrev-ref HEAD) - } - $GitCommitSha1 = (git rev-parse HEAD) - $GitCommitSha1Short = (git rev-parse --short HEAD) - $defines = @{ } - $defines["OPENRCT2_BUILD_NUMBER"] = $BuildNumber; - $defines["OPENRCT2_BUILD_SERVER"] = $Server; - $defines["OPENRCT2_BRANCH"] = $GitBranch; - $defines["OPENRCT2_COMMIT_SHA1"] = $GitCommitSha1; - $defines["OPENRCT2_COMMIT_SHA1_SHORT"] = $GitCommitSha1Short; + $defines["OPENRCT2_BUILD_SERVER"] = $Server; + if ($GitTag -ne "") + { + $defines["OPENRCT2_BRANCH"] = $GitTag; + } + else + { + $defines["OPENRCT2_BRANCH"] = $GitBranch; + $defines["OPENRCT2_COMMIT_SHA1"] = $GitCommitSha1; + $defines["OPENRCT2_COMMIT_SHA1_SHORT"] = $GitCommitSha1Short; + } $defineString = "" foreach ($key in $defines.Keys) { @@ -52,6 +69,7 @@ function Do-PrepareSource() # Set the environment variable which the msbuild project will use $env:OPENRCT2_DEFINES = $defineString; + return 0 } @@ -115,7 +133,7 @@ function Do-Package() return 1 } } - & $7zcmd a -tzip -mx9 $outZip "$tempDir\*" | Write-Host + & $7zcmd a -tzip -mx9 $outZip "$tempDir\*" > $null if ($LASTEXITCODE -ne 0) { Write-Host "Failed to create zip." -ForegroundColor Red @@ -137,9 +155,18 @@ function Do-Installer() # Create artifacts directory New-Item -Force -ItemType Directory $artifactsDir > $null + # Resolve version extension + $VersionExtra = "" + if ($GitTag -ne "") + { + $VersionExtra = "$GitTag" + } + else + { + $VersionExtra = "$GitBranch-$GitCommitSha1Short" + } + # Create installer - $GitCommitSha1Short = (git rev-parse --short HEAD) - $VersionExtra = "$GitBranch-$GitCommitSha1Short" & "$installerDir\build.ps1" -VersionExtra $VersionExtra if ($LASTEXITCODE -ne 0) {