chore: fix publish script

This commit is contained in:
soarqin committed 2026-10-18 22:55:30 +08:00
1 parent 7e7d91e5b2
commit 3c157d2675
4 files changed
+60 -14

No files matched your search

+17 -6
View File
@@ -28,7 +28,7 @@ Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop' $ErrorActionPreference = 'Stop'
function Invoke-PublishDotNet { function Invoke-PublishDotNet {
param([string[]]$Arguments, [switch]$Capture, [string]$Secret) param([string[]]$Arguments, [switch]$Capture, [string]$Secret, [int[]]$SuccessExitCodes = @(0))
$previousOutputEncoding = [Console]::OutputEncoding $previousOutputEncoding = [Console]::OutputEncoding
try { try {
@@ -46,7 +46,7 @@ function Invoke-PublishDotNet {
if ($Capture) { $lines.Add($line) } else { Write-Host $line } if ($Capture) { $lines.Add($line) } else { Write-Host $line }
} }
$commandExit = $LASTEXITCODE $commandExit = $LASTEXITCODE
if ($commandExit -ne 0) { if ($commandExit -notin $SuccessExitCodes) {
if ($Capture) { foreach ($line in $lines) { Write-Host $line } } if ($Capture) { foreach ($line in $lines) { Write-Host $line } }
throw "dotnet $($Arguments[0]) failed (exit $commandExit). No further publishing steps were run." throw "dotnet $($Arguments[0]) failed (exit $commandExit). No further publishing steps were run."
} }
@@ -54,6 +54,20 @@ function Invoke-PublishDotNet {
} finally { [Console]::OutputEncoding = $previousOutputEncoding } } finally { [Console]::OutputEncoding = $previousOutputEncoding }
} }
function Assert-PublishTcli {
try {
# tcli 0.2.4 returns 1 for --version because its parser treats it as an
# unparsed command. Accept it only here, with a recognizable version.
$versionOutput = Invoke-PublishDotNet -Capture -Arguments @('tool', 'run', 'tcli', '--', '--version') -SuccessExitCodes @(0, 1)
if ($versionOutput -notmatch '(?m)^tcli [0-9]+\.[0-9]+\.[0-9]+(?:[-+][0-9A-Za-z.-]+)?\s*$') {
throw 'The version check did not return a recognizable tcli version.'
}
Write-Host $versionOutput
} catch {
throw "Cannot verify the pinned tcli tool. Run dotnet tool restore in the repository root, then dotnet tool run tcli -- --version to inspect startup diagnostics. $($_.Exception.Message)"
}
}
function Get-PublishJsonProperty { function Get-PublishJsonProperty {
param($Object, [string]$Name) param($Object, [string]$Name)
if ($null -ne $Object) { if ($null -ne $Object) {
@@ -282,10 +296,7 @@ function Invoke-ModPublish {
Push-Location -LiteralPath $RepositoryRoot Push-Location -LiteralPath $RepositoryRoot
try { try {
$null = Get-Command dotnet -CommandType Application -ErrorAction Stop $null = Get-Command dotnet -CommandType Application -ErrorAction Stop
if (-not $DryRun) { if (-not $DryRun) { Assert-PublishTcli }
try { Invoke-PublishDotNet -Arguments @('tool', 'run', 'tcli', '--', '--version') }
catch { throw 'The pinned tcli tool cannot run. Run dotnet tool restore in the repository root and check its required .NET runtime.' }
}
$metadata = Get-PublishProject $projectPath $metadata = Get-PublishProject $projectPath
$properties = $metadata.Properties $properties = $metadata.Properties
if (-not [string]::IsNullOrEmpty($properties.PackPreloaderTargetDir)) { throw 'Select a main mod; this project is a preloader or helper.' } if (-not [string]::IsNullOrEmpty($properties.PackPreloaderTargetDir)) { throw 'Select a main mod; this project is a preloader or helper.' }
+2 -2
View File
@@ -3,7 +3,7 @@
## Changlog ## Changlog
* 1.6.2 - Unrelease * 1.6.2
* `Increase maximum power usage in Logistic Stations and Advanced Mining Machines`: Fix zero or corrupted mining speeds when adjusting an Advanced Mining Machine's speed slider with the option enabled. * `Increase maximum power usage in Logistic Stations and Advanced Mining Machines`: Fix zero or corrupted mining speeds when adjusting an Advanced Mining Machine's speed slider with the option enabled.
* `Tweak building buffers`: Restore the Ray Receiver Graviton Lens buffer setting on DSP 0.10.35.29104 and later, and correct the displayed native buffer value to 2. * `Tweak building buffers`: Restore the Ray Receiver Graviton Lens buffer setting on DSP 0.10.35.29104 and later, and correct the displayed native buffer value to 2.
* `Drag building power poles`: Fix invalid alternating previews when enabling the option after loading a save, and restore original spacing when disabling it. * `Drag building power poles`: Fix invalid alternating previews when enabling the option after loading a save, and restore original spacing when disabling it.
@@ -434,7 +434,7 @@
## 更新日志 ## 更新日志
* 1.6.2 - Unreleased * 1.6.2
* `提升物流塔和大型采矿机的最大功耗`:修复启用后调整大型采矿机开采速度时出现 0% 或异常速度的问题。 * `提升物流塔和大型采矿机的最大功耗`:修复启用后调整大型采矿机开采速度时出现 0% 或异常速度的问题。
* `调整建筑输入缓冲`:修复 DSP 0.10.35.29104 及后续版本中射线接收器透镜缓冲设置不生效的问题,并将显示的游戏原始值更正为 2。 * `调整建筑输入缓冲`:修复 DSP 0.10.35.29104 及后续版本中射线接收器透镜缓冲设置不生效的问题,并将显示的游戏原始值更正为 2。
* `拖建电线杆`:修复载入存档后才启用功能时交替放置的预览异常,并在关闭时恢复原有间距。 * `拖建电线杆`:修复载入存档后才启用功能时交替放置的预览异常,并在关闭时恢复原有间距。
+5 -3
View File
@@ -52,9 +52,9 @@ Target Windows PowerShell 5.1 and PowerShell 7. The existing packaging targets i
1. Resolve the named project within the repository. Require `<Project>/<Project>.csproj`, `package/manifest.json`, `package/icon.png`, and `README.md`. Reject traversal, wildcard input, helpers, and projects with `PackPreloaderTargetDir` set. Validate `-Namespace` and the manifest's `name` before building. 1. Resolve the named project within the repository. Require `<Project>/<Project>.csproj`, `package/manifest.json`, `package/icon.png`, and `README.md`. Reject traversal, wildcard input, helpers, and projects with `PackPreloaderTargetDir` set. Validate `-Namespace` and the manifest's `name` before building.
2. Evaluate Release MSBuild properties instead of guessing output paths or parsing only literal XML: `Version`, `ProjectName`, `TargetPath`, `PackHasChangelog`, `PackUsePluginsLayout`, and `PackPreloaderTargetDir`. Read evaluated `ProjectReference` items to find bundled preloaders. MSBuild 17.8 or newer provides the required `-getProperty` and `-getItem` JSON output. 2. Evaluate Release MSBuild properties instead of guessing output paths or parsing only literal XML: `Version`, `ProjectName`, `TargetPath`, `PackHasChangelog`, `PackUsePluginsLayout`, and `PackPreloaderTargetDir`. Read evaluated `ProjectReference` items to find bundled preloaders. MSBuild 17.8 or newer provides the required `-getProperty` and `-getItem` JSON output.
3. For a real publish, resolve the token before changing to the repository's build directory and check the pinned local tcli tool before the expensive build. For `-DryRun`, neither a token nor an installed tcli tool is required. Restore project NuGet assets when missing, then use `--no-restore` for packaging. 3. For a real publish, resolve the token before changing to the repository's build directory and check the pinned local tcli tool before the expensive build. tcli 0.2.4 returns exit code 1 even when `--version` successfully prints its version: accept 0 or 1 only for this check, and require recognizable version output. For `-DryRun`, neither a token nor an installed tcli tool is required. Restore project NuGet assets when missing, then use `--no-restore` for packaging.
4. For each referenced preloader whose evaluated `PackPreloaderTargetDir` belongs to the selected mod's package, run `CopyToParentPackage` in Release before packaging the main mod. This refreshes Dustbin's bundled preloader even if an old DLL already exists under `package/patchers`. Do not upload preloaders or referenced mods separately. 4. For each referenced preloader whose evaluated `PackPreloaderTargetDir` belongs to the selected mod's package, run `CopyToParentPackage` in Release before packaging the main mod. This refreshes Dustbin's bundled preloader even if an old DLL already exists under `package/patchers`. Do not upload preloaders or referenced mods separately.
5. Run `dotnet build <Project>/<Project>.csproj -t:ZipMod -c Release --no-restore`. Every native command must have its exit code checked; stop immediately on a nonzero result. Retain the existing warning policy. 5. Run `dotnet build <Project>/<Project>.csproj -t:ZipMod -c Release --no-restore`. Check every native command's exit code; builds and publication must stop immediately on a nonzero result. Retain the existing warning policy.
6. Select the exact ZIP path defined by the existing target: `<Project>/package/<ProjectName>-<Version>.zip`. Do not select the newest ZIP by timestamp or a wildcard. Read the ZIP and check its root manifest identity and version, required root files, 256x256 PNG icon, expected DLL layout, and optional changelog. Compare bundled main/preloader DLLs with the current evaluated build outputs. When a separate changelog is included, require its latest English and Chinese headings to match the project version. Do not change any version automatically. 6. Select the exact ZIP path defined by the existing target: `<Project>/package/<ProjectName>-<Version>.zip`. Do not select the newest ZIP by timestamp or a wildcard. Read the ZIP and check its root manifest identity and version, required root files, 256x256 PNG icon, expected DLL layout, and optional changelog. Compare bundled main/preloader DLLs with the current evaluated build outputs. When a separate changelog is included, require its latest English and Chinese headings to match the project version. Do not change any version automatically.
7. Write a generated, non-secret tcli configuration under `<Project>/obj/thunderstore-publish/<run-id>/thunderstore.toml`. Print the project, Team, Package Name, version, community, ZIP path, and category-preservation behavior. In `-DryRun`, stop successfully here and retain the ZIP for inspection. 7. Write a generated, non-secret tcli configuration under `<Project>/obj/thunderstore-publish/<run-id>/thunderstore.toml`. Print the project, Team, Package Name, version, community, ZIP path, and category-preservation behavior. In `-DryRun`, stop successfully here and retain the ZIP for inspection.
8. Before a real upload, query the exact package-version endpoint using the supplied namespace, manifest package name, and evaluated project version. If the version exists, stop without uploading. Treat only HTTP 404 as an absent version; authentication, network, server, and response-format errors must remain errors. Do not automatically increment versions or retry a publish with an uncertain result. 8. Before a real upload, query the exact package-version endpoint using the supplied namespace, manifest package name, and evaluated project version. If the version exists, stop without uploading. Treat only HTTP 404 as an absent version; authentication, network, server, and response-format errors must remain errors. Do not automatically increment versions or retry a publish with an uncertain result.
@@ -131,6 +131,7 @@ The pinned tcli version has a Windows-specific behavior: it reads the persisted
| Missing project, malformed metadata, missing/empty/invalid namespace, preloader/helper selection, or traversal input | Stops before publication and identifies the invalid input. | | Missing project, malformed metadata, missing/empty/invalid namespace, preloader/helper selection, or traversal input | Stops before publication and identifies the invalid input. |
| Explicit `-EnvFile`, default caller-directory `.env`, and process token are all available | Uses the explicit file first; without it, uses the caller's `.env`; without either file, uses the process variable. Repository-local `.env` files are supported. | | Explicit `-EnvFile`, default caller-directory `.env`, and process token are all available | Uses the explicit file first; without it, uses the caller's `.env`; without either file, uses the process variable. Repository-local `.env` files are supported. |
| Missing token, missing explicit file, malformed selected file, or conflicting Windows User-scoped token | Stops without exposing credentials or changing persisted environment variables. | | Missing token, missing explicit file, malformed selected file, or conflicting Windows User-scoped token | Stops without exposing credentials or changing persisted environment variables. |
| tcli version check prints a version with exit code 1, returns no version, or cannot start | Accepts the documented version-output case only; missing/invalid output and startup failures stop before building or publication. |
| Failed restore/build/pack or invalid ZIP | Never invokes tcli publication and never falls back to an older ZIP. | | Failed restore/build/pack or invalid ZIP | Never invokes tcli publication and never falls back to an older ZIP. |
| Generated configuration | Contains only `dyson-sphere-program`, explicitly empty categories, and no credential values. Check the parsed tcli metadata as well as the TOML text. | | Generated configuration | Contains only `dyson-sphere-program`, explicitly empty categories, and no credential values. Check the parsed tcli metadata as well as the TOML text. |
| Existing remote version, unexpected HTTP failure, tcli failure, or uncertain timeout | Returns a nonzero result and provides an appropriate next step; no automatic republish or version bump. | | Existing remote version, unexpected HTTP failure, tcli failure, or uncertain timeout | Returns a nonzero result and provides an appropriate next step; no automatic republish or version bump. |
@@ -140,12 +141,13 @@ Use focused command stubs for publication/error-path checks with a synthetic tok
## Verified upstream behavior ## Verified upstream behavior
Sources checked on 2026-10-17: Sources checked on 2026-10-17; command entry point checked on 2026-10-18:
- [tcli publishing and authentication documentation](https://github.com/thunderstore-io/thunderstore-cli/wiki): `TCLI_AUTH_TOKEN`, namespace, and publishing an existing ZIP with `--file`. - [tcli publishing and authentication documentation](https://github.com/thunderstore-io/thunderstore-cli/wiki): `TCLI_AUTH_TOKEN`, namespace, and publishing an existing ZIP with `--file`.
- [NuGet tcli versions](https://api.nuget.org/v3-flatcontainer/tcli/index.json): currently available tool versions. - [NuGet tcli versions](https://api.nuget.org/v3-flatcontainer/tcli/index.json): currently available tool versions.
- [MSBuild property and item evaluation](https://learn.microsoft.com/en-us/visualstudio/msbuild/evaluate-items-and-properties): evaluated metadata and JSON output in MSBuild 17.8 and newer. - [MSBuild property and item evaluation](https://learn.microsoft.com/en-us/visualstudio/msbuild/evaluate-items-and-properties): evaluated metadata and JSON output in MSBuild 17.8 and newer.
- [tcli 0.2.4 configuration model](https://github.com/thunderstore-io/thunderstore-cli/blob/0.2.4/ThunderstoreCLI/Models/ThunderstoreProject.cs) and [upload metadata](https://github.com/thunderstore-io/thunderstore-cli/blob/0.2.4/ThunderstoreCLI/Configuration/Config.cs): category defaults, the empty-array mapping, and publishing metadata. - [tcli 0.2.4 configuration model](https://github.com/thunderstore-io/thunderstore-cli/blob/0.2.4/ThunderstoreCLI/Models/ThunderstoreProject.cs) and [upload metadata](https://github.com/thunderstore-io/thunderstore-cli/blob/0.2.4/ThunderstoreCLI/Configuration/Config.cs): category defaults, the empty-array mapping, and publishing metadata.
- [tcli 0.2.4 environment provider](https://github.com/thunderstore-io/thunderstore-cli/blob/0.2.4/ThunderstoreCLI/Configuration/EnvironmentConfig.cs): Windows User-scope precedence. - [tcli 0.2.4 environment provider](https://github.com/thunderstore-io/thunderstore-cli/blob/0.2.4/ThunderstoreCLI/Configuration/EnvironmentConfig.cs): Windows User-scope precedence.
- [tcli 0.2.4 command entry point](https://github.com/thunderstore-io/thunderstore-cli/blob/0.2.4/ThunderstoreCLI/Program.cs): parser results, including version/help output, return exit code 1.
- [Thunderstore upload form](https://github.com/thunderstore-io/Thunderstore/blob/685b2743035e0ac0786180d10813d67b72fcdc2d/django/thunderstore/repository/package_upload.py) and [listing update behavior](https://github.com/thunderstore-io/Thunderstore/blob/685b2743035e0ac0786180d10813d67b72fcdc2d/django/thunderstore/repository/models/package.py): empty submitted categories retain existing listing categories. - [Thunderstore upload form](https://github.com/thunderstore-io/Thunderstore/blob/685b2743035e0ac0786180d10813d67b72fcdc2d/django/thunderstore/repository/package_upload.py) and [listing update behavior](https://github.com/thunderstore-io/Thunderstore/blob/685b2743035e0ac0786180d10813d67b72fcdc2d/django/thunderstore/repository/models/package.py): empty submitted categories retain existing listing categories.
- [Thunderstore manifest serializer](https://github.com/thunderstore-io/Thunderstore/blob/685b2743035e0ac0786180d10813d67b72fcdc2d/django/thunderstore/repository/package_manifest.py): standard manifest fields and duplicate-version validation. - [Thunderstore manifest serializer](https://github.com/thunderstore-io/Thunderstore/blob/685b2743035e0ac0786180d10813d67b72fcdc2d/django/thunderstore/repository/package_manifest.py): standard manifest fields and duplicate-version validation.
+36 -3
View File
@@ -77,6 +77,7 @@ function New-PublishFixture {
$script:requests = New-Object 'System.Collections.Generic.List[string]' $script:requests = New-Object 'System.Collections.Generic.List[string]'
$script:layout = $false $script:layout = $false
$script:failStep = '' $script:failStep = ''
$script:tcliVersionOutput = 'tcli 0.2.4+synthetic'
$script:badArchive = '' $script:badArchive = ''
$script:remoteState = 'available' $script:remoteState = 'available'
$script:expectedNamespace = 'AnotherTeam' $script:expectedNamespace = 'AnotherTeam'
@@ -86,8 +87,13 @@ function New-PublishFixture {
} }
function Invoke-PublishDotNet { function Invoke-PublishDotNet {
param([string[]]$Arguments, [switch]$Capture, [string]$Secret) param([string[]]$Arguments, [switch]$Capture, [string]$Secret, [int[]]$SuccessExitCodes = @(0))
$script:calls.Add(($Arguments -join '|')) $script:calls.Add(($Arguments -join '|'))
if ($Arguments -contains '--version') {
Assert-Check ($Capture -and $SuccessExitCodes.Count -eq 2 -and 0 -in $SuccessExitCodes -and 1 -in $SuccessExitCodes) 'The tcli version check did not account for its nonstandard exit code.'
if ($script:failStep -eq 'tool') { throw 'Synthetic tool startup failure' }
return $script:tcliVersionOutput
}
if ($Arguments[0] -eq 'msbuild') { if ($Arguments[0] -eq 'msbuild') {
if ($script:failStep -eq 'evaluate') { return 'not JSON' } if ($script:failStep -eq 'evaluate') { return 'not JSON' }
$isPreloader = $Arguments[1] -like '*FixturePreloader.csproj' $isPreloader = $Arguments[1] -like '*FixturePreloader.csproj'
@@ -151,6 +157,7 @@ function Invoke-PublishDotNet {
return return
} }
if ($Arguments -contains 'publish') { if ($Arguments -contains 'publish') {
Assert-Check ($SuccessExitCodes.Count -eq 1 -and $SuccessExitCodes[0] -eq 0) 'Publication accepted a nonzero exit code.'
Assert-Check ($Secret -ceq $script:syntheticToken) 'The output-redaction token is incorrect.' Assert-Check ($Secret -ceq $script:syntheticToken) 'The output-redaction token is incorrect.'
Assert-Check ([Environment]::GetEnvironmentVariable('TCLI_AUTH_TOKEN', 'Process') -ceq $script:syntheticToken) 'The child process token is incorrect.' Assert-Check ([Environment]::GetEnvironmentVariable('TCLI_AUTH_TOKEN', 'Process') -ceq $script:syntheticToken) 'The child process token is incorrect.'
Assert-Check (-not ($Arguments -contains '--token')) 'A token was put in the command line.' Assert-Check (-not ($Arguments -contains '--token')) 'A token was put in the command line.'
@@ -239,7 +246,12 @@ try {
try { $smallIcon.Save((Join-Path $script:fixturePackage 'icon.png'), [Drawing.Imaging.ImageFormat]::Png) } finally { $smallIcon.Dispose() } try { $smallIcon.Save((Join-Path $script:fixturePackage 'icon.png'), [Drawing.Imaging.ImageFormat]::Png) } finally { $smallIcon.Dispose() }
Assert-CheckThrows { Invoke-ModPublish $script:fixtureRoot Fixture AnotherTeam -DryRun } '*256x256 PNG*' Assert-CheckThrows { Invoke-ModPublish $script:fixtureRoot Fixture AnotherTeam -DryRun } '*256x256 PNG*'
foreach ($failure in @('evaluate', 'restore', 'preloader', 'build')) { New-PublishFixture
$script:tcliVersionOutput = 'Synthetic tool startup error without a version'
Assert-CheckThrows { Invoke-ModPublish $script:fixtureRoot Fixture AnotherTeam $externalTokenFile } '*recognizable tcli version*'
Assert-Check (-not $script:published -and $script:requests.Count -eq 0 -and $script:calls.Count -eq 1) 'An invalid tool version fell through to the build or publication.'
foreach ($failure in @('tool', 'evaluate', 'restore', 'preloader', 'build')) {
New-PublishFixture New-PublishFixture
$script:failStep = $failure $script:failStep = $failure
if ($failure -eq 'restore') { [IO.File]::Delete($script:fixtureAssets) } if ($failure -eq 'restore') { [IO.File]::Delete($script:fixtureAssets) }
@@ -328,14 +340,35 @@ try {
# Exercise redaction and nonzero exits without starting another process. # Exercise redaction and nonzero exits without starting another process.
$script:nativeExit = 0 $script:nativeExit = 0
$script:nativeOutput = "Synthetic tool output: $script:syntheticToken"
function dotnet { function dotnet {
param([Parameter(ValueFromRemainingArguments = $true)][string[]]$Arguments) param([Parameter(ValueFromRemainingArguments = $true)][string[]]$Arguments)
$global:LASTEXITCODE = $script:nativeExit $global:LASTEXITCODE = $script:nativeExit
return "Synthetic tool output: $script:syntheticToken" return $script:nativeOutput
} }
try { try {
$redacted = & $script:realInvokeDotNet -Capture -Arguments @('stub') -Secret $script:syntheticToken $redacted = & $script:realInvokeDotNet -Capture -Arguments @('stub') -Secret $script:syntheticToken
Assert-Check ($redacted.Contains('[REDACTED]') -and -not $redacted.Contains($script:syntheticToken)) 'Native output exposed the token.' Assert-Check ($redacted.Contains('[REDACTED]') -and -not $redacted.Contains($script:syntheticToken)) 'Native output exposed the token.'
# Exercise the actual preflight helper through the real exit-code wrapper.
$stubInvokeDotNet = ${function:Invoke-PublishDotNet}
try {
Set-Item -LiteralPath Function:Invoke-PublishDotNet -Value $script:realInvokeDotNet
$script:nativeOutput = 'tcli 0.2.4+synthetic'
foreach ($versionExit in @(0, 1)) {
$script:nativeExit = $versionExit
Assert-PublishTcli 6>$null
Assert-Check ($true) "The version check rejected tcli exit code $versionExit."
}
$script:nativeExit = 1
$script:nativeOutput = 'Synthetic tool restore failure'
Assert-CheckThrows { Assert-PublishTcli } '*recognizable tcli version*'
$script:nativeOutput = 'tcli 0.2.4+synthetic'
$script:nativeExit = 150
Assert-CheckThrows { Assert-PublishTcli } '*exit 150*'
$script:nativeExit = 1
Assert-CheckThrows { & $script:realInvokeDotNet -Capture -Arguments @('tool', 'run', 'tcli', '--', 'publish') } '*exit 1*'
} finally { Set-Item -LiteralPath Function:Invoke-PublishDotNet -Value $stubInvokeDotNet }
$script:nativeOutput = "Synthetic tool output: $script:syntheticToken"
$script:nativeExit = 17 $script:nativeExit = 17
Assert-CheckThrows { & $script:realInvokeDotNet -Arguments @('stub') -Secret $script:syntheticToken } '*exit 17*' Assert-CheckThrows { & $script:realInvokeDotNet -Arguments @('stub') -Secret $script:syntheticToken } '*exit 17*'
Assert-CheckThrows { & $script:realInvokeDotNet -Capture -Arguments @('stub') -Secret $script:syntheticToken } '*exit 17*' Assert-CheckThrows { & $script:realInvokeDotNet -Capture -Arguments @('stub') -Secret $script:syntheticToken } '*exit 17*'