Add support for nightly builds with gitref suffix, custom output folder

This commit is contained in:
Steve Streeting 2023-09-18 17:08:25 +01:00
parent 5492f9c588
commit 7527cc4922
3 changed files with 145 additions and 82 deletions

View File

@ -9,14 +9,16 @@ in the root of your Unreal project. Please see the [Package Config File docs](Pa
for a full description of this file.
```
ue-package.ps1 [-src:sourcefolder] [-major|-minor|-patch|-hotfix] [-keepversion] [-variant=VariantName] [-test] [-dryrun]
ue-package.ps1 [-src:sourcefolder] [-out:folder] [-major|-minor|-patch|-hotfix] [-keepversion] [-variant=VariantName] [-test] [-dryrun]
-src : Source folder (current folder if omitted), must contain packageconfig.json
-out : Overrides OutputDir in packageconfig.json
-major : Increment major version i.e. [x++].0.0.0
-minor : Increment minor version i.e. x.[x++].0.0
-patch : Increment patch version i.e. x.x.[x++].0 (default)
-hotfix : Increment hotfix version i.e. x.x.x.[x++]
-keepversion : Keep current version number, doesn't tag
-keepversion : Keep current version number, doesn't tag unless -forcetag
-nightly : Nightly build, doesn't tag, doesn't commit, re-uses same nightly folder, appends git rev version
-variants Name1,Name2,Name3
: Build only named variants instead of DefaultVariants from packageconfig.json
-test : Testing mode, separate builds, allow dirty working copy

View File

@ -18,6 +18,86 @@ function Get-Project-Version {
return $gameIni["/Script/EngineSettings.GeneralProjectSettings"].ProjectVersion
}
function Get-ProjectVersionComponents {
param (
[string]$srcfolder
)
$versionString = Get-Project-Version $srcfolder
# Regex features:
# - Can read 2-4 version components but will pad with 0s up to 4 when writing
# - captures pre- and post-fix text and retains
$regex = "([^\d]*)(\d+)\.(\d+)(?:\.(\d+))?(?:\.(\d+))?(.*)"
$matches = $versionString | Select-String -Pattern $regex
# 1 = prefix
# 2-5 = version number components
# 6 = postfix
if (($matches.Matches.Count -gt 0) -and ($matches.Matches[0].Groups.Count -eq 7)) {
$prefix = $matches.Matches[0].Groups[1].Value
$postfix = $matches.Matches[0].Groups[6].Value
$intversions = $matches.Matches[0].Groups[2..5] | ForEach-Object {
if ($_.Value -ne "") {
[int]$_.Value
} else {
# We fill in the version numbers to 4 digits always
0
}
}
return New-Object PsObject -Property @{prefix=$prefix ; postfix=$postfix; digits=$intversions}
} else {
return New-Object PsObject -Property @{prefix="" ; postfix=""; digits=@(1,0,0,0)}
}
}
function Write-ProjectVersionFromObject {
param (
[string]$srcfolder,
[object]$versionObj,
[bool]$dryrun = $false
)
$newver = "$($versionObj.prefix)$($versionObj.digits[0]).$($versionObj.digits[1]).$($versionObj.digits[2]).$($versionObj.digits[3])$($versionObj.postfix)"
Write-Project-Version -srcfolder:$srcfolder -newversion:$newver -dryrun:$dryrun
}
function Write-Project-Version {
param (
[string]$srcfolder,
[string]$newversion,
[bool]$dryrun = $false
)
$gameIniFile = Get-Project-Version-Ini-Filename $srcfolder
if ($dryrun) {
Write-Verbose "[version] dryrun: would have set $gameIniFile version: $newversion"
} else {
# We don't use PsIni to write, because it can screw up some nested non-trivial properties :(
#$gameIni["/Script/EngineSettings.GeneralProjectSettings"].ProjectVersion = $newver
#Out-IniFile -Force -InputObject $gameIni -FilePath $gameIniFile
$verlineregex = "ProjectVersion=.*"
$matches = Select-String -Path "$gameIniFile" -Pattern $verlineregex
if ($matches.Matches.Count -gt 0) {
$origline = $matches.Matches[0].Value
$newline = "ProjectVersion=$newversion"
(Get-Content "$gameIniFile").replace($origline, $newline) | Set-Content "$gameIniFile"
Write-Verbose "[version++] Success! Version is now $newversion"
} else {
throw "[version++] Error: unable to substitute current version, unable to find '$verlineregex'"
}
}
}
function Increment-Project-Version {
@ -34,8 +114,9 @@ function Increment-Project-Version {
throw "Can't set more than one of major/minor/patch/hotfix at the same time!"
}
$versionobj = Get-ProjectVersionComponents $srcfolder
$gameIniFile = Get-Project-Version-Ini-Filename $srcfolder
$gameIni = Get-IniContent $gameIniFile
Write-Verbose "[version++] M:$major m:$minor p:$patch h:$hotfix"
@ -46,78 +127,30 @@ function Increment-Project-Version {
# Bump the version number of the build
Write-Verbose "[inc_version] Updating $gameIniFile"
$versionString = $gameIni["/Script/EngineSettings.GeneralProjectSettings"].ProjectVersion
Write-Verbose "[version++] Current version is $versionString"
Write-Verbose "[version++] Current version is $($versionObj.digits[0]).$($versionObj.digits[1]).$($versionObj.digits[2]).$($versionObj.digits[3])"
# Regex features:
# - Can read 2-4 version components but will pad with 0s up to 4 when writing
# - captures pre- and post-fix text and retains
$regex = "([^\d]*)(\d+)\.(\d+)(?:\.(\d+))?(?:\.(\d+))?(.*)"
$matches = $versionString | Select-String -Pattern $regex
# 1 = prefix
# 2-5 = version number components
# 6 = postfix
if (($matches.Matches.Count -gt 0) -and ($matches.Matches[0].Groups.Count -eq 7)) {
$prefix = $matches.Matches[0].Groups[1].Value
$postfix = $matches.Matches[0].Groups[6].Value
$intversions = $matches.Matches[0].Groups[2..5] | ForEach-Object {
if ($_.Value -ne "") {
[int]$_.Value
} else {
# We fill in the version numbers to 4 digits always
0
}
}
$versionDigit = 2;
if ($major) {
$versionDigit = 0
} elseif ($minor) {
$versionDigit = 1
} elseif ($patch) {
$versionDigit = 2
} elseif ($hotfix) {
$versionDigit = 3
}
# increment then zero anything after
$intversions[$versionDigit]++
for ($d = $versionDigit + 1; $d -lt $intversions.Length; $d++) {
$intversions[$d] = 0
}
$newver = "$prefix$($intversions[0]).$($intversions[1]).$($intversions[2]).$($intversions[3])$postfix"
Write-Verbose "[version++] Bumping version to $newver"
if ($dryrun) {
Write-Verbose "[version++] dryrun: not changing $gameIniFile"
} else {
# We don't use PsIni to write, because it can screw up some nested non-trivial properties :(
#$gameIni["/Script/EngineSettings.GeneralProjectSettings"].ProjectVersion = $newver
#Out-IniFile -Force -InputObject $gameIni -FilePath $gameIniFile
$verlineregex = "ProjectVersion=$regex"
$matches = Select-String -Path "$gameIniFile" -Pattern $verlineregex
if ($matches.Matches.Count -gt 0) {
$origline = $matches.Matches[0].Value
$newline = "ProjectVersion=$newver"
(Get-Content "$gameIniFile").replace($origline, $newline) | Set-Content "$gameIniFile"
Write-Verbose "[version++] Success! Version is now $newver"
} else {
throw "[version++] Error: unable to substitute current version, unable to find '$verlineregex'"
}
}
return "$newver"
} else {
throw "[version++] Error: unable to read current version"
$versionDigit = 2;
if ($major) {
$versionDigit = 0
} elseif ($minor) {
$versionDigit = 1
} elseif ($patch) {
$versionDigit = 2
} elseif ($hotfix) {
$versionDigit = 3
}
# increment then zero anything after
$versionObj.digits[$versionDigit]++
for ($d = $versionDigit + 1; $d -lt $versionObj.digits.Length; $d++) {
$versionObj.digits[$d] = 0
}
$newver = "$($versionObj.prefix)$($versionObj.digits[0]).$($versionObj.digits[1]).$($versionObj.digits[2]).$($versionObj.digits[3])$($versionObj.postfix)"
Write-Verbose "[version++] Bumping version to $newver"
Write-Project-Version -srcfolder:$srcfolder -newversion:$newver -dryrun:$dryrun
return "$newver"
}

View File

@ -5,11 +5,13 @@
[CmdletBinding()] # Fail on unknown args
param (
[string]$src,
[string]$out,
[switch]$major = $false,
[switch]$minor = $false,
[switch]$patch = $false,
[switch]$hotfix = $false,
# Don't incrememnt version
[switch]$nightly = $false,
# Don't increment version
[switch]$keepversion = $false,
# Name of variant to build (optional, uses DefaultVariants from packageconfig.json if unspecified)
[array]$variants,
@ -33,14 +35,16 @@ param (
function Write-Usage {
Write-Output "Steve's Unreal packaging tool"
Write-Output "Usage:"
Write-Output " ue-package.ps1 [-src:sourcefolder] [-major|-minor|-patch|-hotfix] [-keepversion] [-force] [-variant=VariantName] [-test] [-dryrun]"
Write-Output " ue-package.ps1 [-src:sourcefolder] [-out:folder] [-major|-minor|-patch|-hotfix] [-keepversion] [-force] [-variant=VariantName] [-test] [-dryrun]"
Write-Output " "
Write-Output " -src : Source folder (current folder if omitted), must contain packageconfig.json"
Write-OUtput " -out : Overrides OutputDir in packageconfig.json"
Write-Output " -major : Increment major version i.e. [x++].0.0.0"
Write-Output " -minor : Increment minor version i.e. x.[x++].0.0"
Write-Output " -patch : Increment patch version i.e. x.x.[x++].0 (default)"
Write-Output " -hotfix : Increment hotfix version i.e. x.x.x.[x++]"
Write-Output " -keepversion : Keep current version number, doesn't tag unless -forcetag"
Write-Output " -nightly : Nightly build, doesn't tag, doesn't commit, re-uses same nightly folder, appends git rev version"
Write-Output " -variants Name1,Name2,Name3"
Write-Output " : Build only named variants instead of DefaultVariants from packageconfig.json"
Write-Output " -test : Testing mode, separate builds, allow dirty working copy"
@ -144,11 +148,16 @@ try {
$mapsdesc = $maps ? $maps -join ", " : "Default (Project Settings)"
Write-Output ""
Write-Output "Project File : $projfile"
Write-Output "UE Version : $ueVersion"
Write-Output "UE Install : $ueinstall"
Write-Output "Output Folder : $($config.OutputDir)"
if ($out.Length -eq 0) {
Write-Output "Output Folder : $($config.OutputDir)"
} else {
Write-Output "Output Folder : $out"
}
Write-Output "Zipped Folder : $($config.ZipDir)"
Write-Output ""
Write-Output "Chosen Variants : $chosenVariantNames"
@ -165,7 +174,20 @@ try {
$patch = $true
}
$versionNumber = $null
if ($keepversion) {
if ($nightly) {
$versionNumber = "nightly"
if ($isGit)
{
# Add the git ref to the version number in the project ONLY (not our folder)
$tempverobj = Get-ProjectVersionComponents $src
$gitref = $(git rev-parse --short HEAD)
$tempverobj.postfix = "-$gitref"
Write-Output "Packaging nightly-$gitref"
Write-ProjectVersionFromObject -srcfolder:$src -versionObj:$tempverobj -dryrun:$dryrun
}
} elseif ($keepversion) {
$versionNumber = Get-Project-Version $src
} else {
# Bump up version, passthrough options
@ -196,7 +218,7 @@ try {
# For tagging release
# We only need to grab the main version once
if (-not $keepversion) {
if (-not $keepversion -and -not $nightly) {
if (-not $test -and -not $dryrun -and $isGit) {
if ($src -ne ".") { Push-Location $src }
@ -213,7 +235,11 @@ try {
foreach ($var in $chosenVariants) {
$outDir = Get-Package-Dir -config:$config -versionNumber:$versionNumber -variantName:$var.Name
if ($out.Length -gt 0) {
$outDir = Join-Path $out "$($var.Name)-$($versionNumber)"
} else {
$outDir = Get-Package-Dir -config:$config -versionNumber:$versionNumber -variantName:$var.Name
}
# Delete previous
Remove-Item -Path $outDir -Recurse -Force -ErrorAction SilentlyContinue
@ -346,4 +372,6 @@ catch {
Exit 9
}
# Revert any remaining temp changes
git checkout .
Write-Output "~-~-~ Unreal Packaging Helper Completed OK ~-~-~"