tools: description-only Workshop updates, refuse description images Steam can't load

This commit is contained in:
Fabian @ Blax Software 2026-11-29 11:48:43 +01:00
parent 88fe75414b
commit f6662f96dc
3 changed files with 82 additions and 33 deletions

View File

@ -76,7 +76,7 @@ RimWorld 1.7 no longer runs on Unity/Mono. It runs on .NET 10 (CoreCLR) with Lud
It stages only what players need (About, 1.7, Defs, Patches, Languages) in `%TEMP%`, sets the tags the game would (Mod plus the supported versions), and writes every CHANGELOG.md entry since the version in `Tools/workshop-published.txt` as the change note. `-Publish` refuses unless the shipped files are committed and pushed, the top CHANGELOG entry matches `modVersion`, and the last test run passed after the last build. It leaves the title and preview alone; the game's uploader resets the title from About.xml and never updates the description. The in-game route still works: `Tools/workshop-stage.ps1` swaps the junction for a clean copy, upload from Mods > Blax Slaves > More actions (dev mode), then `workshop-stage.ps1 -Done`. It stages only what players need (About, 1.7, Defs, Patches, Languages) in `%TEMP%`, sets the tags the game would (Mod plus the supported versions), and writes every CHANGELOG.md entry since the version in `Tools/workshop-published.txt` as the change note. `-Publish` refuses unless the shipped files are committed and pushed, the top CHANGELOG entry matches `modVersion`, and the last test run passed after the last build. It leaves the title and preview alone; the game's uploader resets the title from About.xml and never updates the description. The in-game route still works: `Tools/workshop-stage.ps1` swaps the junction for a clean copy, upload from Mods > Blax Slaves > More actions (dev mode), then `workshop-stage.ps1 -Done`.
The Workshop description is `docs/workshop-description.txt` (Steam BBCode). Its images load from this repo's `docs/art/` over Forgejo's raw URLs, so push them before you upload a description that uses them. `Source/Art/README.md` has the render commands. The Workshop description is `docs/workshop-description.txt` (Steam BBCode); `-DescriptionOnly -DescriptionFile docs\workshop-description.txt` replaces just the text, with no build, no content upload and no change note. Steam loads description images as cross-origin requests, so every `[img]` host must send an `Access-Control-Allow-Origin` header or the image shows broken; the script checks each one and `-Publish` refuses otherwise. Forgejo's raw URLs send no such header. `Source/Art/README.md` has the render commands for the art in `docs/art/`.
### Tests ### Tests

View File

@ -96,9 +96,10 @@ internal static class Program
return 0; return 0;
} }
if (o.Content == null || note == null) bool descriptionOnly = o.Content == null && note == null && description != null;
if (!descriptionOnly && (o.Content == null || note == null))
{ {
Console.Error.WriteLine("--publish needs --content and --note-file."); Console.Error.WriteLine("--publish needs --content and --note-file, or only --description-file.");
return 64; return 64;
} }
return Submit(item, o, note, description); return Submit(item, o, note, description);
@ -107,7 +108,8 @@ internal static class Program
private static int Submit(PublishedFileId_t item, Options o, string note, string description) private static int Submit(PublishedFileId_t item, Options o, string note, string description)
{ {
UGCUpdateHandle_t h = SteamUGC.StartItemUpdate(new AppId_t(RimWorldAppId), item); UGCUpdateHandle_t h = SteamUGC.StartItemUpdate(new AppId_t(RimWorldAppId), item);
if (!SteamUGC.SetItemContent(h, o.Content)) return Fail("SetItemContent refused the content folder."); // Description-only updates send no content and no change note (null), so Steam lists no new change note.
if (o.Content != null && !SteamUGC.SetItemContent(h, o.Content)) return Fail("SetItemContent refused the content folder.");
if (o.Tags != null && !SteamUGC.SetItemTags(h, o.Tags)) return Fail("SetItemTags refused the tags."); if (o.Tags != null && !SteamUGC.SetItemTags(h, o.Tags)) return Fail("SetItemTags refused the tags.");
if (description != null && !SteamUGC.SetItemDescription(h, description)) return Fail("SetItemDescription refused the text."); if (description != null && !SteamUGC.SetItemDescription(h, description)) return Fail("SetItemDescription refused the text.");
@ -230,7 +232,8 @@ internal static class Program
public const string Usage = public const string Usage =
"Usage: WorkshopUpload --item <publishedFileId> [--content <dir>] [--note-file <file>] [--tags Mod,1.7]\n" + "Usage: WorkshopUpload --item <publishedFileId> [--content <dir>] [--note-file <file>] [--tags Mod,1.7]\n" +
" [--description-file <file>] [--timeout <seconds>] [--publish]\n" + " [--description-file <file>] [--timeout <seconds>] [--publish]\n" +
"Without --publish it only reads the item and checks ownership."; "Without --publish it only reads the item and checks ownership. With only --description-file it\n" +
"replaces the description and nothing else.";
public ulong Item; public ulong Item;
public string Content, NoteFile, DescriptionFile; public string Content, NoteFile, DescriptionFile;

View File

@ -7,6 +7,12 @@ no game window, no dev mode. RimWorld may stay open.
.\Tools\workshop-upload.ps1 -Publish uploads the staged copy. The change note is the CHANGELOG.md .\Tools\workshop-upload.ps1 -Publish uploads the staged copy. The change note is the CHANGELOG.md
entry for the version in About.xml. entry for the version in About.xml.
-DescriptionFile docs\workshop-description.txt also replaces the Workshop description (BBCode) -DescriptionFile docs\workshop-description.txt also replaces the Workshop description (BBCode)
-DescriptionOnly with -DescriptionFile: replaces only the description. No build,
no content upload, no change note.
Every [img] in the description must load with an Access-Control-Allow-Origin header: Steam loads
description images as cross-origin requests and shows a broken image otherwise. -Publish refuses
when one doesn't.
-Publish refuses unless the shipped files are committed and pushed, the top CHANGELOG.md entry matches -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. About.xml's modVersion, and the last Tests\run-tests.ps1 run passed after the last build.
@ -16,6 +22,7 @@ param(
[string]$RimWorldDir = 'E:\SteamLibrary\steamapps\common\RimWorld', [string]$RimWorldDir = 'E:\SteamLibrary\steamapps\common\RimWorld',
[switch]$Publish, [switch]$Publish,
[string]$DescriptionFile, [string]$DescriptionFile,
[switch]$DescriptionOnly,
[string]$TestResults = (Join-Path $env:TEMP 'BlaxSlavesTest\BlaxSlavesTestResults.txt'), [string]$TestResults = (Join-Path $env:TEMP 'BlaxSlavesTest\BlaxSlavesTestResults.txt'),
[switch]$SkipChecks [switch]$SkipChecks
) )
@ -24,6 +31,26 @@ $repo = Split-Path -Parent $PSScriptRoot
$ship = 'About', '1.7', 'Defs', 'Patches', 'Languages', 'Textures', 'Sounds' $ship = 'About', '1.7', 'Defs', 'Patches', 'Languages', 'Textures', 'Sounds'
$toolProj = Join-Path $PSScriptRoot 'WorkshopUpload\WorkshopUpload.csproj' $toolProj = Join-Path $PSScriptRoot 'WorkshopUpload\WorkshopUpload.csproj'
$toolExe = Join-Path $PSScriptRoot 'WorkshopUpload\bin\Release\WorkshopUpload.exe' $toolExe = Join-Path $PSScriptRoot 'WorkshopUpload\bin\Release\WorkshopUpload.exe'
if ($DescriptionOnly -and -not $DescriptionFile) { throw '-DescriptionOnly needs -DescriptionFile.' }
# Steam adds crossorigin to description images, so a host without Access-Control-Allow-Origin shows a broken image.
function Test-DescriptionImages([string]$file) {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$found = @()
$text = [IO.File]::ReadAllText((Resolve-Path $file).Path, [Text.Encoding]::UTF8)
foreach ($m in [regex]::Matches($text, '\[img\](.*?)\[/img\]')) {
$url = $m.Groups[1].Value.Trim()
try {
$r = Invoke-WebRequest -Uri $url -UseBasicParsing -Headers @{ Origin = 'https://steamcommunity.com' }
$type = "$($r.Headers['Content-Type'])"
$acao = "$($r.Headers['Access-Control-Allow-Origin'])"
if ($type -notlike 'image/*') { $found += "$url is not an image ($type)." }
elseif ($acao -ne '*' -and $acao -ne 'https://steamcommunity.com') { $found += "$url sends no Access-Control-Allow-Origin header; Steam would show it broken." }
}
catch { $found += "$url does not load: $($_.Exception.Message)" }
}
$found
}
$itemId = (Get-Content -LiteralPath (Join-Path $repo 'About\PublishedFileId.txt') -Raw).Trim() $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) $about = [xml](Get-Content -LiteralPath (Join-Path $repo 'About\About.xml') -Raw -Encoding UTF8)
@ -53,21 +80,34 @@ foreach ($v in $sections.Keys) {
if (-not $noteLines) { $noteLines = @("$($about.ModMetaData.name) $topVersion") + $sections[$topVersion] } if (-not $noteLines) { $noteLines = @("$($about.ModMetaData.name) $topVersion") + $sections[$topVersion] }
$note = ($noteLines -join "`n").Trim() $note = ($noteLines -join "`n").Trim()
if (-not $DescriptionOnly) {
foreach ($proj in Get-ChildItem (Join-Path $repo 'Source\*\*.csproj')) { foreach ($proj in Get-ChildItem (Join-Path $repo 'Source\*\*.csproj')) {
& dotnet build $proj.FullName -c Release -nologo -v q "-p:RimWorldDir=$RimWorldDir" & dotnet build $proj.FullName -c Release -nologo -v q "-p:RimWorldDir=$RimWorldDir"
if ($LASTEXITCODE -ne 0) { throw "build failed: $($proj.Name)" } if ($LASTEXITCODE -ne 0) { throw "build failed: $($proj.Name)" }
} }
}
& dotnet build $toolProj -c Release -nologo -v q "-p:RimWorldDir=$RimWorldDir" & dotnet build $toolProj -c Release -nologo -v q "-p:RimWorldDir=$RimWorldDir"
if ($LASTEXITCODE -ne 0) { throw 'build failed: WorkshopUpload' } if ($LASTEXITCODE -ne 0) { throw 'build failed: WorkshopUpload' }
$imageProblems = @()
if ($DescriptionFile) {
$imageProblems = @(Test-DescriptionImages $DescriptionFile)
foreach ($p in $imageProblems) { Write-Warning $p }
}
if ($Publish -and -not $SkipChecks) { if ($Publish -and -not $SkipChecks) {
$problems = @() $problems = @() + $imageProblems
$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 show what the repo doesn't." }
if ($DescriptionOnly) {
$dirty = & git -C $repo status --porcelain -- (Resolve-Path $DescriptionFile).Path
if ($dirty) { $problems += "The description file has uncommitted changes: $dirty" }
}
else {
if ($topVersion -ne $modVersion) { $problems += "CHANGELOG.md's top entry is $topVersion, About.xml says $modVersion." } if ($topVersion -ne $modVersion) { $problems += "CHANGELOG.md's top entry is $topVersion, About.xml says $modVersion." }
$dirty = & git -C $repo status --porcelain -- $ship $dirty = & git -C $repo status --porcelain -- $ship
if ($dirty) { $problems += "Uncommitted changes in shipped files:`n$($dirty -join "`n")" } 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 $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." } if (-not (Test-Path $TestResults)) { $problems += "No test results at $TestResults. Run .\Tests\run-tests.ps1 first." }
else { else {
@ -76,9 +116,14 @@ if ($Publish -and -not $SkipChecks) {
if (-not ($lines -match '^END$') -or ($lines -match '^FAIL ')) { $problems += 'The last test run failed or did not finish.' } 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." } 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- ")) } if ($problems) { throw ("Not publishing:`n- " + ($problems -join "`n- ")) }
} }
if ($DescriptionOnly) {
$toolArgs = @('--item', $itemId, '--description-file', (Resolve-Path $DescriptionFile).Path)
}
else {
# Clean copy outside the repo: only what players need, no PDBs. TEMP has no spaces in its path. # Clean copy outside the repo: only what players need, no PDBs. TEMP has no spaces in its path.
$root = Join-Path $env:TEMP 'BlaxWorkshopUpload' $root = Join-Path $env:TEMP 'BlaxWorkshopUpload'
$stage = Join-Path $root $packageId $stage = Join-Path $root $packageId
@ -94,6 +139,7 @@ $noteFile = Join-Path $root "$packageId.note.txt"
$toolArgs = @('--item', $itemId, '--content', $stage, '--note-file', $noteFile, '--tags', ($tags -join ',')) $toolArgs = @('--item', $itemId, '--content', $stage, '--note-file', $noteFile, '--tags', ($tags -join ','))
if ($DescriptionFile) { $toolArgs += @('--description-file', (Resolve-Path $DescriptionFile).Path) } if ($DescriptionFile) { $toolArgs += @('--description-file', (Resolve-Path $DescriptionFile).Path) }
}
if ($Publish) { $toolArgs += '--publish' } if ($Publish) { $toolArgs += '--publish' }
# steam_api writes status lines to stderr; under 'Stop' PowerShell 5.1 would turn them into errors. # steam_api writes status lines to stderr; under 'Stop' PowerShell 5.1 would turn them into errors.
@ -104,7 +150,7 @@ try {
$code = $LASTEXITCODE $code = $LASTEXITCODE
} }
finally { Pop-Location } finally { Pop-Location }
if ($Publish -and $code -eq 0) { if ($Publish -and $code -eq 0 -and -not $DescriptionOnly) {
[IO.File]::WriteAllText($publishedFile, "$topVersion`n") [IO.File]::WriteAllText($publishedFile, "$topVersion`n")
Write-Host "Recorded $topVersion in Tools\workshop-published.txt. Commit it." Write-Host "Recorded $topVersion in Tools\workshop-published.txt. Commit it."
} }