Skip to content

Commit c607204

Browse files
author
dompl
committed
update
1 parent 0824711 commit c607204

File tree

1 file changed

+31
-50
lines changed

1 file changed

+31
-50
lines changed

.github/workflows/build-release.yml

Lines changed: 31 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,42 @@ jobs:
103103
chmod +x scripts/build-tipa.sh
104104
./scripts/build-tipa.sh
105105
106-
# 5. 复制 release 文件夹到本项目
107-
- name: Copy Build Artifacts to Release Repository
106+
# 5. 复制 release 文件夹到本项目 + 提交 latest.tipa 到当前分支
107+
- name: Copy Build Artifacts and Commit latest.tipa
108+
env:
109+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} # 参考步骤8的环境变量配置
108110
run: |
111+
# 第一步:复制构建产物到本项目
109112
mkdir -p release
110113
cp -r TrollScript-Private/release/* release/
111114
112115
echo "📦 Build artifacts:"
113116
ls -la release/
117+
118+
# 第二步:检查 latest.tipa 文件是否存在
119+
LATEST_TIPA_FILE="./release/TrollScript_latest.tipa"
120+
if [ ! -f "$LATEST_TIPA_FILE" ]; then
121+
echo "❌ Error: $LATEST_TIPA_FILE not found!"
122+
exit 1
123+
fi
124+
125+
# 第三步:配置git(极简配置,仅为提交需要)
126+
git config --global user.name "github-actions[bot]"
127+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
128+
129+
# 第四步:添加并提交 latest.tipa(仅提交该文件)
130+
git add "$LATEST_TIPA_FILE"
131+
# 检查是否有变更,避免空提交
132+
if git diff --staged --quiet; then
133+
echo "ℹ️ No changes to latest.tipa, skip commit"
134+
else
135+
git commit -m "Update latest.tipa - $(date +'%Y-%m-%d %H:%M:%S CST')"
136+
# 第五步:推送到当前分支(使用GH_TOKEN认证)
137+
git push origin HEAD:${{ github.ref }}
138+
echo "✅ Successfully committed and pushed latest.tipa to current branch!"
139+
fi
140+
141+
ls -la release/
114142
115143
# 6. 获取私有仓库最后 tag 的 commit 信息
116144
- name: Get Version Info from Private Repository
@@ -177,53 +205,6 @@ jobs:
177205
name: TrollScript-${{ steps.version.outputs.release_tag }}
178206
path: release/*.tipa
179207
retention-days: 30
180-
181-
# 7.5 将构建产物提交到 release 分支(覆盖模式)
182-
- name: Commit Build Artifacts to release Branch
183-
env:
184-
GH_TOKEN: ${{ secrets.GH_TOKEN }}
185-
REPO: ${{ github.repository }}
186-
RELEASE_TAG: ${{ steps.version.outputs.release_tag }}
187-
run: |
188-
set -e
189-
git config user.name "github-actions[bot]"
190-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
191-
192-
# 使用 token 更新 origin URL 以便推送
193-
git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${REPO}.git"
194-
git fetch origin --prune
195-
196-
# 若远程已有 release 分支则基于远程分支检出并替换为本地 HEAD,否则创建孤儿分支
197-
if git ls-remote --heads origin release | grep -q refs/heads/release; then
198-
git checkout -B release origin/release
199-
else
200-
git checkout --orphan release
201-
git rm -rf . || true
202-
git clean -fdx || true
203-
fi
204-
205-
# 查找非 latest 的 TIPA 文件,并更新 latest 复制
206-
TIPA_FILE=$(find ./release -name "*.tipa" ! -name "*_latest.tipa" 2>/dev/null | head -1 || echo "")
207-
LATEST_FILE=./TrollScript_latest.tipa
208-
209-
if [ -n "$TIPA_FILE" ]; then
210-
echo "📦 Found tipa: $TIPA_FILE — updating $LATEST_FILE"
211-
cp -f "$TIPA_FILE" "$LATEST_FILE"
212-
else
213-
if [ -f "$LATEST_FILE" ]; then
214-
echo "ℹ️ No new tipa found, using existing $LATEST_FILE"
215-
else
216-
echo "❌ No tipa file found to mark as latest" >&2
217-
exit 1
218-
fi
219-
fi
220-
221-
# 强制添加并提交 latest TIPA(覆盖模式)
222-
git add -f "$LATEST_FILE"
223-
git commit -m "chore(release): update TrollScript_latest.tipa" || echo "No changes to commit"
224-
225-
# 强制推送覆盖远程 release 分支
226-
git push -f origin release
227208

228209
# 8. 在本项目创建 Tag 并提交到 Release
229210
- name: Create GitHub Release
@@ -278,4 +259,4 @@ jobs:
278259
--draft=false \
279260
--prerelease=false
280261
281-
echo "✅ Latest release updated!"
262+
echo "✅ Latest release updated!"

0 commit comments

Comments
 (0)