浏览代码

【维护】添加本地一键发布脚本

客户端插件无法在公共 runner 构建(缺少专有程序集),移除会在 tag 推送后
永久排队的自托管发行工作流,改为本地一条命令发布。

- 新增 scripts/release.sh:校验工作区与 tag 后,构建打包、打 tag、推送并创建带附件的 Release。
- 移除 .github/workflows/release.yml,仅保留 test.yml 运行纯逻辑单测。
- README 补充发布流程说明。
PJ568 1 月之前
父节点
当前提交
a23015ab3c
共有 3 个文件被更改,包括 72 次插入 和 29 次删除
  1. 0 27
      .github/workflows/release.yml
  2. 11 2
      README.md
  3. 61 0
      scripts/release.sh

+ 0 - 27
.github/workflows/release.yml

@@ -1,27 +0,0 @@
-# 发行:需要一台已安装 SPT 客户端的自托管 runner(客户端程序集为专有文件,无法在公共 runner 构建)。
-# 用法:在 Actions 页手动触发,或推送 v* 标签。
-name: 发行
-
-on:
-  workflow_dispatch:
-  push:
-    tags: ["v*"]
-
-jobs:
-  package:
-    runs-on: [self-hosted, linux, spt]
-    steps:
-      - uses: actions/checkout@v4
-      - name: 打包
-        run: scripts/package.sh
-        env:
-          SPT_DIR: ${{ vars.SPT_DIR }}
-      - uses: actions/upload-artifact@v4
-        with:
-          name: PerformanceScope
-          path: artifacts/*.zip
-      - name: 创建 Release
-        if: startsWith(github.ref, 'refs/tags/v')
-        uses: softprops/action-gh-release@v2
-        with:
-          files: artifacts/*.zip

+ 11 - 2
README.md

@@ -72,13 +72,22 @@ Release 构建会自动把 dll 复制到 `$SPT_DIR/BepInEx/plugins/PerformanceSc
 dotnet test tests/PerformanceScope.Tests/PerformanceScope.Tests.csproj
 ```
 
-## 打包
+## 打包与发布
 
 ```shellscript
+# 仅打包
 scripts/package.sh
 # 产物:artifacts/PerformanceScope-v{版本}.zip
+
+# 一键发布:构建 → 打包 → 打 tag → 推送 → 创建 GitHub Release
+scripts/release.sh
+# 预演(只构建打包并打印将执行的命令,需工作区干净)
+scripts/release.sh --dry-run
 ```
 
+发布前置:已安装并登录 GitHub CLI(`gh`),且仓库已配置 `remote origin`。
+`release.sh` 会校验工作区干净、tag 不存在,发布后自动创建带 zip 附件的 Release。
+
 ## 部署(本机)
 
 ```shellscript
@@ -117,7 +126,7 @@ scripts/package.sh
 - **镜内低分辨率下纹理锯齿会更明显**:镜内相机的 mipmap bias 只在 `Init()` 时设置一次,插件不做补偿。
 - **与其它改 `SetResolution` 的模组可能冲突**:若第三方 prefix 改写同一入参,插件检测到目标未生效后会暂停重试直至你更改目标值,避免每帧重建 RenderTexture。
 - **版本敏感**:依赖具体类型与方法,EFT 更新后可能失效。
-- **CI 限制**:公共 runner 无法构建客户端插件(缺少专有程序集),`test.yml` 只跑纯逻辑单测;发行包需在装有 SPT 的机器(或自托管 runner)上通过 `scripts/package.sh` 生成。
+- **CI 限制**:客户端插件必须引用专有程序集,公共 runner 无法构建,故仓库只保留 `test.yml`(跑纯逻辑单测);发行包用 `scripts/release.sh` 本地一键发布。
 
 ## 许可证
 

+ 61 - 0
scripts/release.sh

@@ -0,0 +1,61 @@
+#!/usr/bin/env bash
+# 本地一条命令发布:构建 → 打包 → 打 tag → 推送 → 创建 GitHub Release
+# 用法:scripts/release.sh [--dry-run]
+# 前置:已安装并登录 gh,且仓库已配置 remote origin
+set -euo pipefail
+
+ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
+cd "$ROOT"
+
+DRY_RUN=0
+if [ "${1:-}" = "--dry-run" ]; then
+  DRY_RUN=1
+fi
+
+VERSION="$(sed -n 's:.*<Version>\(.*\)</Version>.*:\1:p' src/PerformanceScope.Plugin/PerformanceScope.Plugin.csproj | head -1)"
+[ -n "$VERSION" ] || { echo "错误:未能从 csproj 读取 Version" >&2; exit 1; }
+TAG="v$VERSION"
+
+# 工作区必须干净,避免发布内容与提交不一致
+if [ -n "$(git status --porcelain)" ]; then
+  echo "错误:工作区有未提交改动,请先提交" >&2
+  git status --short
+  exit 1
+fi
+
+BRANCH="$(git rev-parse --abbrev-ref HEAD)"
+if [ "$BRANCH" = "HEAD" ]; then
+  echo "错误:处于游离 HEAD,无法发布" >&2
+  exit 1
+fi
+
+if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then
+  echo "错误:tag $TAG 已存在" >&2
+  exit 1
+fi
+
+echo "版本:$VERSION   标签:$TAG   分支:$BRANCH"
+
+# 构建并打包(--dry-run 也会执行,以校验构建与产物)
+bash scripts/package.sh
+ZIP="artifacts/PerformanceScope-v${VERSION}.zip"
+[ -f "$ZIP" ] || { echo "错误:未找到产物 $ZIP" >&2; exit 1; }
+
+if [ "$DRY_RUN" = "1" ]; then
+  echo "[dry-run] 将执行:"
+  echo "  git tag -a $TAG -m \"$TAG\""
+  echo "  git push origin $BRANCH"
+  echo "  git push origin $TAG"
+  echo "  gh release create $TAG $ZIP --generate-notes"
+  exit 0
+fi
+
+command -v gh >/dev/null 2>&1 || { echo "错误:未安装 GitHub CLI(gh)" >&2; exit 1; }
+git remote get-url origin >/dev/null 2>&1 || { echo "错误:未配置 git remote origin" >&2; exit 1; }
+
+git tag -a "$TAG" -m "PerformanceScope $TAG"
+git push origin "$BRANCH"
+git push origin "$TAG"
+gh release create "$TAG" "$ZIP" --title "PerformanceScope $TAG" --generate-notes
+
+echo "已发布 $TAG(产物:$ZIP)"