112 lines
6.3 KiB
PowerShell
112 lines
6.3 KiB
PowerShell
<#
|
|
Updates the Steam Workshop item from the command line, through the running Steam client: no password,
|
|
no game window, no dev mode. RimWorld may stay open.
|
|
|
|
.\Tools\workshop-upload.ps1 dry run: builds, stages a clean copy, checks the item and
|
|
that this Steam account owns it. Uploads nothing.
|
|
.\Tools\workshop-upload.ps1 -Publish uploads the staged copy. The change note is the CHANGELOG.md
|
|
entry for the version in About.xml.
|
|
-DescriptionFile docs\workshop-description.txt also replaces the Workshop description (BBCode)
|
|
|
|
-Publish refuses unless the shipped files are committed and pushed, the top CHANGELOG.md entry matches
|
|
About.xml's modVersion, and the last Tests\run-tests.ps1 run passed after the last build.
|
|
-SkipChecks skips those checks. The in-game button (Tools\workshop-stage.ps1) still works as a fallback.
|
|
#>
|
|
param(
|
|
[string]$RimWorldDir = 'E:\SteamLibrary\steamapps\common\RimWorld',
|
|
[switch]$Publish,
|
|
[string]$DescriptionFile,
|
|
[string]$TestResults = (Join-Path $env:TEMP 'BlaxSlavesTest\BlaxSlavesTestResults.txt'),
|
|
[switch]$SkipChecks
|
|
)
|
|
$ErrorActionPreference = 'Stop'
|
|
$repo = Split-Path -Parent $PSScriptRoot
|
|
$ship = 'About', '1.7', 'Defs', 'Patches', 'Languages', 'Textures', 'Sounds'
|
|
$toolProj = Join-Path $PSScriptRoot 'WorkshopUpload\WorkshopUpload.csproj'
|
|
$toolExe = Join-Path $PSScriptRoot 'WorkshopUpload\bin\Release\WorkshopUpload.exe'
|
|
|
|
$itemId = (Get-Content -LiteralPath (Join-Path $repo 'About\PublishedFileId.txt') -Raw).Trim()
|
|
$about = [xml](Get-Content -LiteralPath (Join-Path $repo 'About\About.xml') -Raw -Encoding UTF8)
|
|
$packageId = $about.ModMetaData.packageId.Trim()
|
|
$modVersion = "$($about.ModMetaData.modVersion)".Trim()
|
|
# Same tags the in-game uploader sets: "Mod" plus Major.Minor of every supported version.
|
|
$tags = @('Mod') + @($about.ModMetaData.supportedVersions.li | ForEach-Object { $v = [version]"$_".Trim(); "$($v.Major).$($v.Minor)" })
|
|
|
|
# Change note: every CHANGELOG.md entry newer than the last version published from here
|
|
# (Tools\workshop-published.txt, written after each successful -Publish).
|
|
$publishedFile = Join-Path $PSScriptRoot 'workshop-published.txt'
|
|
$lastPublished = if (Test-Path $publishedFile) { [version](Get-Content -LiteralPath $publishedFile -Raw).Trim() } else { [version]'0.0' }
|
|
$sections = [ordered]@{}
|
|
$current = $null
|
|
foreach ($line in Get-Content -LiteralPath (Join-Path $repo 'CHANGELOG.md') -Encoding UTF8) {
|
|
if ($line -match '^##\s+(.+)$') { $current = $Matches[1].Trim(); $sections[$current] = New-Object System.Collections.ArrayList; continue }
|
|
if ($current -and $line.Trim()) { [void]$sections[$current].Add($line.TrimEnd()) }
|
|
}
|
|
if ($sections.Count -eq 0) { throw 'CHANGELOG.md has no "## <version>" entry.' }
|
|
$topVersion = @($sections.Keys)[0]
|
|
$noteLines = @()
|
|
foreach ($v in $sections.Keys) {
|
|
if ([version]$v -le $lastPublished) { break }
|
|
if ($noteLines) { $noteLines += '' }
|
|
$noteLines += @("$($about.ModMetaData.name) $v") + $sections[$v]
|
|
}
|
|
if (-not $noteLines) { $noteLines = @("$($about.ModMetaData.name) $topVersion") + $sections[$topVersion] }
|
|
$note = ($noteLines -join "`n").Trim()
|
|
|
|
foreach ($proj in Get-ChildItem (Join-Path $repo 'Source\*\*.csproj')) {
|
|
& dotnet build $proj.FullName -c Release -nologo -v q "-p:RimWorldDir=$RimWorldDir"
|
|
if ($LASTEXITCODE -ne 0) { throw "build failed: $($proj.Name)" }
|
|
}
|
|
& dotnet build $toolProj -c Release -nologo -v q "-p:RimWorldDir=$RimWorldDir"
|
|
if ($LASTEXITCODE -ne 0) { throw 'build failed: WorkshopUpload' }
|
|
|
|
if ($Publish -and -not $SkipChecks) {
|
|
$problems = @()
|
|
if ($topVersion -ne $modVersion) { $problems += "CHANGELOG.md's top entry is $topVersion, About.xml says $modVersion." }
|
|
$dirty = & git -C $repo status --porcelain -- $ship
|
|
if ($dirty) { $problems += "Uncommitted changes in shipped files:`n$($dirty -join "`n")" }
|
|
$ahead = & git -C $repo rev-list --count '@{u}..HEAD' 2>$null
|
|
if ($LASTEXITCODE -ne 0) { $problems += 'The branch has no upstream to compare with.' }
|
|
elseif ([int]$ahead -gt 0) { $problems += "$ahead commit(s) not pushed yet, so the Workshop would ship code the repo doesn't show." }
|
|
$dll = Get-ChildItem (Join-Path $repo '1.7\Assemblies\*.dll') | Sort-Object LastWriteTime -Descending | Select-Object -First 1
|
|
if (-not (Test-Path $TestResults)) { $problems += "No test results at $TestResults. Run .\Tests\run-tests.ps1 first." }
|
|
else {
|
|
$res = Get-Item $TestResults
|
|
$lines = Get-Content -LiteralPath $TestResults -Encoding UTF8
|
|
if (-not ($lines -match '^END$') -or ($lines -match '^FAIL ')) { $problems += 'The last test run failed or did not finish.' }
|
|
elseif ($dll -and $res.LastWriteTime -lt $dll.LastWriteTime) { $problems += "The last test run ($($res.LastWriteTime)) is older than the build ($($dll.LastWriteTime)). Run .\Tests\run-tests.ps1 again." }
|
|
}
|
|
if ($problems) { throw ("Not publishing:`n- " + ($problems -join "`n- ")) }
|
|
}
|
|
|
|
# Clean copy outside the repo: only what players need, no PDBs. TEMP has no spaces in its path.
|
|
$root = Join-Path $env:TEMP 'BlaxWorkshopUpload'
|
|
$stage = Join-Path $root $packageId
|
|
if (Test-Path $stage) { Remove-Item $stage -Recurse -Force }
|
|
New-Item -ItemType Directory $stage -Force | Out-Null
|
|
foreach ($name in $ship) {
|
|
$src = Join-Path $repo $name
|
|
if (Test-Path $src) { Copy-Item $src (Join-Path $stage $name) -Recurse }
|
|
}
|
|
Get-ChildItem $stage -Recurse -File -Filter *.pdb | Remove-Item
|
|
$noteFile = Join-Path $root "$packageId.note.txt"
|
|
[IO.File]::WriteAllText($noteFile, $note, (New-Object Text.UTF8Encoding $false))
|
|
|
|
$toolArgs = @('--item', $itemId, '--content', $stage, '--note-file', $noteFile, '--tags', ($tags -join ','))
|
|
if ($DescriptionFile) { $toolArgs += @('--description-file', (Resolve-Path $DescriptionFile).Path) }
|
|
if ($Publish) { $toolArgs += '--publish' }
|
|
|
|
# steam_api writes status lines to stderr; under 'Stop' PowerShell 5.1 would turn them into errors.
|
|
$ErrorActionPreference = 'Continue'
|
|
Push-Location (Split-Path $toolExe)
|
|
try {
|
|
& $toolExe @toolArgs 2>&1 | ForEach-Object { "$_" } | Where-Object { $_ -notmatch '^(Setting breakpad|SteamInternal_)' }
|
|
$code = $LASTEXITCODE
|
|
}
|
|
finally { Pop-Location }
|
|
if ($Publish -and $code -eq 0) {
|
|
[IO.File]::WriteAllText($publishedFile, "$topVersion`n")
|
|
Write-Host "Recorded $topVersion in Tools\workshop-published.txt. Commit it."
|
|
}
|
|
exit $code
|