feat(publish): add local Thunderstore publishing script

This commit is contained in:
soarqin committed 2026-10-18 18:08:25 +08:00
1 parent e876db396a
commit 9f48923166
6 files changed
+951

No files matched your search

+52
View File
@@ -68,3 +68,55 @@ Some functions and patches for better user experience
## [LiveStreamAssist](LiveStreamAssist)
Keeps the statistics window active for live streams by switching between the Production Statistics and Dyson Sphere tabs every 15 to 30 seconds.
## Publishing to Thunderstore
Use Windows PowerShell 5.1 or PowerShell 7, a .NET SDK with MSBuild 17.8 or newer, and the repository's normal game references and build prerequisites. Restore the pinned local tcli tool once from the repository root:
```powershell
dotnet tool restore
```
Select a single main mod with `-Project` and supply its Thunderstore Team with the required `-Namespace` parameter. Package Name comes from `<Project>/package/manifest.json`; version comes from the project file. Preview the build and package without a token or upload:
```powershell
.\Publish-Mod.ps1 -Project UXAssist -Namespace soarqin -DryRun
```
To publish, put a Team service-account token in a UTF-8 `.env` file in the directory where the command is invoked, then run the same command without `-DryRun`. If `.env` is absent, the script reads the process environment variable `TCLI_AUTH_TOKEN`. To select another file, pass `-EnvFile`:
```powershell
.\Publish-Mod.ps1 -Project Dustbin -Namespace soarqin -EnvFile "$env:USERPROFILE\.config\DSP_Mods\thunderstore.env"
```
The file accepts one `TCLI_AUTH_TOKEN=...` assignment, optional quotes, blank lines, and full-line comments. Token selection follows this order: explicit `-EnvFile`, the caller directory's `.env`, then the process variable. A selected file with an invalid or missing token is an error. `.env` and `.env.*` are ignored by Git; keep real tokens out of version control and shell command history. tcli 0.2.4 prioritizes a persisted Windows User-scoped token over the process token; if the values conflict, the script stops so that the stale setting can be reconciled.
The script always uses Release builds and the existing `ZipMod` target. It refreshes bundled preloaders before packaging, validates the exact ZIP, rejects an already published version, and uploads only the selected main mod. `-DryRun` still creates normal build/package outputs but skips remote version checks and uploads. Publication always targets **Dyson Sphere Program** (`dyson-sphere-program`) with empty Category input, preserving the existing listing's categories; a first release starts without categories. Versions are never bumped automatically. After an interrupted or failed submission, check the printed version page before retrying because the release may already exist.
Run the focused script checks with `powershell.exe -NoProfile -File tools/tests/Test-PublishMod.ps1` or `pwsh -NoProfile -File tools/tests/Test-PublishMod.ps1`. They use synthetic credentials and stubbed network/publication commands; scratch files stay under `UXAssist/obj/publish-mod-check`.
## 发布到 Thunderstore
使用 Windows PowerShell 5.1 或 PowerShell 7,并安装包含 MSBuild 17.8 或更新版本的 .NET SDK。游戏引用和其他构建依赖与正常编译一致。首次使用时,在仓库根目录还原固定版本的本地 tcli 工具:
```powershell
dotnet tool restore
```
通过 `-Project` 选择一个主 mod,通过必填参数 `-Namespace` 指定 Thunderstore Team。Package Name 读取 `<Project>/package/manifest.json`,版本读取项目文件。可以先预览构建和打包,无需 token,也不会上传:
```powershell
.\Publish-Mod.ps1 -Project UXAssist -Namespace soarqin -DryRun
```
正式发布时,将 Team 服务账号的 token 写入调用目录下的 UTF-8 `.env` 文件,再去掉 `-DryRun` 执行。如果 `.env` 不存在,脚本会读取进程环境变量 `TCLI_AUTH_TOKEN`。也可以通过 `-EnvFile` 指定其他文件:
```powershell
.\Publish-Mod.ps1 -Project Dustbin -Namespace soarqin -EnvFile "$env:USERPROFILE\.config\DSP_Mods\thunderstore.env"
```
文件允许一条 `TCLI_AUTH_TOKEN=...` 赋值,以及可选的引号、空行和整行注释。token 的读取优先级为:显式 `-EnvFile`、调用目录下的 `.env`、进程环境变量。选中的文件缺少 token 或格式无效时,脚本会报错。`.env` 和 `.env.*` 已加入 Git 忽略规则;真实 token 不应提交到版本控制,也不要写入 shell 命令历史。tcli 0.2.4 会优先读取 Windows 持久化的用户级 token;如果它与本次选定的 token 不同,脚本会停止,需先处理旧设置。
脚本始终使用 Release 构建和现有的 `ZipMod` 目标。它会在打包前更新附带的 preloader,检查本次生成的确切 ZIP,拒绝重复发布已有版本,并且只上传选定的主 mod。`-DryRun` 仍会生成正常的构建和打包产物,但跳过远程版本检查和上传。发布社区固定为 **Dyson Sphere Program**(`dyson-sphere-program`);Category 输入留空,保留已有条目的分类,首次发布则不设置分类。脚本不会自动修改版本号。提交中断或失败后,应先检查输出的版本页面,再决定是否重试,因为该版本可能已经发布成功。
可以运行 `powershell.exe -NoProfile -File tools/tests/Test-PublishMod.ps1` 或 `pwsh -NoProfile -File tools/tests/Test-PublishMod.ps1` 检查脚本。测试使用虚构的凭据,以及模拟的网络和发布命令;临时文件保存在 `UXAssist/obj/publish-mod-check` 下。