Allow releasing multiple variants, and use DefaultVariants that have ReleaseTo by default

This commit is contained in:
Steve Streeting 2020-10-08 14:59:25 +01:00
parent 691d68ddbe
commit eb1a74a1d2

View File

@ -1,12 +1,9 @@
[CmdletBinding()] # Fail on unknown args [CmdletBinding()] # Fail on unknown args
param ( param (
# Version to release # Version to release
[Parameter(Mandatory=$true)]
[string]$version, [string]$version,
# Variant name to release # Variant name(s) to release; if not specified release all DefaultVariants with ReleaseTo options
[Parameter(Mandatory=$true)] [array]$variants,
# Project folder (assumes current dir if not specified)
[string]$variant,
# Source folder, current dir if omitted # Source folder, current dir if omitted
[string]$src, [string]$src,
# Which service(s) to release on e.g. "steam": defaults to "ReleaseTo" services in packageconfig.json for variant # Which service(s) to release on e.g. "steam": defaults to "ReleaseTo" services in packageconfig.json for variant
@ -28,13 +25,13 @@ function Write-Usage {
Write-Output "Usage:" Write-Output "Usage:"
Write-Output " ue4-release.ps1 -version:ver -variant:var -services:steam,itch [-src:sourcefolder] [-dryrun]" Write-Output " ue4-release.ps1 -version:ver -variant:var -services:steam,itch [-src:sourcefolder] [-dryrun]"
Write-Output " " Write-Output " "
Write-Output " -version:ver : Version to release; must have been packaged already" Write-Output " -version:ver : Version to release; must have been packaged already"
Write-Output " -variant:var : Name of package variant to release" Write-Output " -variants:var1,var2 : Name of variants to release. Omit to use DefaultVariants"
Write-Output " -services:s1,s2 : Name of services to release to. Can omit and rely on ReleaseTo" Write-Output " -services:s1,s2 : Name of services to release to. Can omit and rely on ReleaseTo"
Write-Output " setting of variant in packageconfig.json " Write-Output " setting of variant in packageconfig.json "
Write-Output " -src : Source folder (current folder if omitted), must contain packageconfig.json" Write-Output " -src : Source folder (current folder if omitted), must contain packageconfig.json"
Write-Output " -dryrun : Don't perform any actual actions, just report what would happen" Write-Output " -dryrun : Don't perform any actual actions, just report what would happen"
Write-Output " -help : Print this help" Write-Output " -help : Print this help"
} }
$ErrorActionPreference = "Stop" $ErrorActionPreference = "Stop"
@ -49,6 +46,11 @@ if ($src.Length -eq 0) {
Write-Verbose "-src not specified, assuming current directory" Write-Verbose "-src not specified, assuming current directory"
} }
if (-not $version) {
Write-Output "Mandatory argument: version"
Exit 1
}
Write-Output "~-~-~ UE4 Release Helper Start ~-~-~" Write-Output "~-~-~ UE4 Release Helper Start ~-~-~"
try { try {
@ -56,55 +58,67 @@ try {
# Import config # Import config
$config = Read-Package-Config -srcfolder:$src $config = Read-Package-Config -srcfolder:$src
# Find variant (first match in case config has many) if ($variants) {
$variantConfig = $config.Variants | Where-Object { $_.Name -eq $variant } $variantConfigs = $config.Variants | Where-Object { $_.Name -in $variants }
if ($variantConfig -is [array]) { if ($variantConfigs.Count -ne $variants.Count) {
if ($variantConfig.Count > 1) { $unmatchedVariants = $variants | Where-Object { $_ -notin $variantConfigs.Name }
throw "More than one package variant called $variant in packageconfig.json, ambiguous!" Write-Warning "Variant(s) not found, ignoring: $($unmatchedVariants -join ", ")"
} else {
# Don't think this will happen but still
$variantConfig = $variantConfig[0]
}
}
# Get source dir
$sourcedir = Get-Package-Client-Dir -config:$config -versionNumber:$version -variantName:$variant
if (-not (Test-Path $sourcedir -PathType Container)) {
throw "Release folder $sourcedir does not exist"
}
# Find service(s)
if ($services) {
# Release to a subset of allowed services
$servicesFound = $services | Where-Object {$variantConfig.ReleaseTo -contains $_ }
if ($servicesFound.Count -ne $services.Count) {
$unmatchedServices = $services | Where-Object { $servicesFound -notcontains $_ }
Write-Warning "Services(s) not supported by $($variantConfig.Name): $($unmatchedServices -join ", ")"
} }
} else { } else {
$servicesFound = $variantConfig.ReleaseTo # Use default variants
$variantConfigs = $config.Variants | Where-Object { $_.Name -in $config.DefaultVariants }
} }
if (-not $servicesFound) { $hasErrors = $false
throw "No matching services to release $variant to" foreach ($variantConfig in $variantConfigs) {
}
Write-Output "" # Get source dir
Write-Output "Variant : $variant" $sourcedir = Get-Package-Client-Dir -config:$config -versionNumber:$version -variantName:$variantConfig.Name
Write-Output "Source Folder : $sourcedir"
Write-Output "Service(s) : $($servicesFound -join ", ")"
Write-Output ""
if (-not (Test-Path $sourcedir -PathType Container)) {
foreach ($service in $servicesFound) { Write-Error "Release folder $sourcedir does not exist, skipping"
if ($service -eq "steam") { $hasErrors = $true
Release-Steam -config:$config -variant:$variantConfig -sourcefolder:$sourcedir -version:$version -dryrun:$dryrun continue
} elseif ($service -eq "itch") {
Release-Itch -config:$config -variant:$variantConfig -sourcefolder:$sourcedir -version:$version -dryrun:$dryrun
} else {
throw "Unknown release service: $service"
} }
# Find service(s)
if ($services) {
# Release to a subset of allowed services
$servicesFound = $services | Where-Object {$variantConfig.ReleaseTo -contains $_ }
if ($servicesFound.Count -ne $services.Count) {
$unmatchedServices = $services | Where-Object { $servicesFound -notcontains $_ }
Write-Warning "Services(s) not supported by $($variantConfig.Name): $($unmatchedServices -join ", ")"
}
} else {
$servicesFound = $variantConfig.ReleaseTo
}
if (-not $servicesFound) {
Write-Verbose "Skipping $($variantConfig.Name), no matching release services"
continue
}
Write-Output ""
Write-Output "Variant : $($variantConfig.Name)"
Write-Output "Source Folder : $sourcedir"
Write-Output "Service(s) : $($servicesFound -join ", ")"
Write-Output ""
foreach ($service in $servicesFound) {
if ($service -eq "steam") {
Release-Steam -config:$config -variant:$variantConfig -sourcefolder:$sourcedir -version:$version -dryrun:$dryrun
} elseif ($service -eq "itch") {
Release-Itch -config:$config -variant:$variantConfig -sourcefolder:$sourcedir -version:$version -dryrun:$dryrun
} else {
throw "Unknown release service: $service"
}
}
}
if ($hasErrors) {
throw "Errors occurred, see above"
} }
} catch { } catch {