Skip to content

Commit 23596a3

Browse files
KuronekoKuroneko
authored andcommitted
chore(ci): 废弃旧的硬编码发布工作流并新增多项目支持文档
- 在 main.yml、SPNORE.yml 和 SyncPatchNotesonReleaseEdit.yml 文件中添加废弃标记 - 新增完整 CI/CD 指南文档 CI-CD-GUIDE.md,详细说明多项目独立发布流程 - 说明新 Tag 命名规范和自动构建原理,替代旧的手动创建 Release 模式 - 介绍快速开始、详细操作流程、常见问题及迁移指南 - 提供完整的文档体系,包含示例、注意事项及最佳实践 - 实现向后兼容旧工作流,确保平滑过渡期间的使用稳定性
1 parent 78f7174 commit 23596a3

13 files changed

Lines changed: 3232 additions & 3 deletions

.github/workflows/SPNORE.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
name: Sync Patch Notes on Release Edit
1+
# ⚠️ DEPRECATED: 此文件已被 sync-patch-notes.yml 替代
2+
# 保留仅供参考,将在未来删除
3+
4+
name: Sync Patch Notes on Release Edit (DEPRECATED)
25

36
permissions:
47
contents: write

.github/workflows/SyncPatchNotesonReleaseEdit.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
name: Sync Patch Notes on Release Edit
1+
# ⚠️ DEPRECATED: 此文件已被 sync-patch-notes.yml 替代
2+
# 保留仅供参考,将在未来删除
3+
4+
name: Sync Patch Notes on Release Edit (DEPRECATED)
25

36
permissions:
47
contents: write

.github/workflows/main.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
name: Build on Release
1+
# ⚠️ DEPRECATED: 此文件已被 release.yml 替代
2+
# 保留仅供参考,将在未来删除
3+
# 请使用新的 tag 格式: project-name/v1.2.3
4+
# 参见: docs/CI-CD-GUIDE.md
5+
6+
name: Build on Release (DEPRECATED)
27
permissions:
38
contents: write
49

.github/workflows/release.yml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Build & Release on Tag
2+
permissions:
3+
contents: write
4+
5+
on:
6+
push:
7+
tags:
8+
- '**/v*' # 匹配格式: project-name/v1.2.3
9+
10+
jobs:
11+
parse-and-build:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Parse project name and version from tag
21+
id: parse-tag
22+
run: |
23+
TAG_NAME=${GITHUB_REF#refs/tags/}
24+
PROJECT_NAME=$(echo $TAG_NAME | cut -d'/' -f1)
25+
VERSION=$(echo $TAG_NAME | cut -d'/' -f2)
26+
27+
echo "PROJECT_NAME=$PROJECT_NAME" >> $GITHUB_OUTPUT
28+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
29+
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_OUTPUT
30+
31+
echo "📦 解析结果:"
32+
echo " 项目名称: $PROJECT_NAME"
33+
echo " 版本号: $VERSION"
34+
echo " 完整Tag: $TAG_NAME"
35+
36+
- name: Validate project exists
37+
run: |
38+
if [ ! -d "projects/${{ steps.parse-tag.outputs.PROJECT_NAME }}" ]; then
39+
echo "❌ 错误: 项目 ${{ steps.parse-tag.outputs.PROJECT_NAME }} 不存在"
40+
echo "💡 可用项目列表:"
41+
ls -1 projects/
42+
exit 1
43+
fi
44+
echo "✅ 项目 ${{ steps.parse-tag.outputs.PROJECT_NAME }} 存在"
45+
46+
- name: Setup Node.js
47+
uses: actions/setup-node@v4
48+
with:
49+
node-version: '22'
50+
51+
- name: Install root dependencies
52+
run: npm install
53+
54+
- name: Install project dependencies
55+
working-directory: projects/${{ steps.parse-tag.outputs.PROJECT_NAME }}
56+
run: npm install
57+
58+
- name: Build project
59+
run: npm run build:${{ steps.parse-tag.outputs.PROJECT_NAME }}
60+
61+
- name: Verify build output
62+
run: |
63+
if [ ! -d "projects/${{ steps.parse-tag.outputs.PROJECT_NAME }}/dist" ]; then
64+
echo "❌ 构建产物不存在"
65+
exit 1
66+
fi
67+
echo "✅ 构建产物已生成:"
68+
ls -lh projects/${{ steps.parse-tag.outputs.PROJECT_NAME }}/dist/
69+
70+
- name: Get release info
71+
id: release-info
72+
uses: actions/github-script@v7
73+
with:
74+
script: |
75+
const tagName = '${{ steps.parse-tag.outputs.TAG_NAME }}';
76+
const version = '${{ steps.parse-tag.outputs.VERSION }}';
77+
78+
// 尝试获取 release 信息
79+
try {
80+
const { data: release } = await github.rest.repos.getReleaseByTag({
81+
owner: context.repo.owner,
82+
repo: context.repo.repo,
83+
tag: tagName
84+
});
85+
86+
core.setOutput('release_body', release.body || '');
87+
core.setOutput('release_name', release.name || version);
88+
} catch (e) {
89+
core.setOutput('release_body', '');
90+
core.setOutput('release_name', version);
91+
}
92+
93+
- name: Create GitHub Release
94+
uses: softprops/action-gh-release@v2
95+
with:
96+
tag_name: ${{ steps.parse-tag.outputs.TAG_NAME }}
97+
name: ${{ steps.parse-tag.outputs.PROJECT_NAME }} ${{ steps.parse-tag.outputs.VERSION }}
98+
body: ${{ steps.release-info.outputs.release_body }}
99+
files: projects/${{ steps.parse-tag.outputs.PROJECT_NAME }}/dist/**
100+
draft: false
101+
prerelease: false
102+
103+
- name: Trigger GreasyFork Webhook
104+
if: success()
105+
run: |
106+
echo "🚀 Triggering GreasyFork sync for ${{ steps.parse-tag.outputs.PROJECT_NAME }}..."
107+
curl -f -X POST \
108+
-H "Content-Type: application/json" \
109+
--data '{
110+
"action": "published",
111+
"project": "${{ steps.parse-tag.outputs.PROJECT_NAME }}",
112+
"version": "${{ steps.parse-tag.outputs.VERSION }}",
113+
"tag": "${{ steps.parse-tag.outputs.TAG_NAME }}",
114+
"release_url": "${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ steps.parse-tag.outputs.TAG_NAME }}"
115+
}' \
116+
"${{ secrets.GREASYFORK_WEBHOOK_URL }}"
117+
echo "✅ GreasyFork webhook triggered successfully"
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Sync Patch Notes on Release Edit
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
release:
8+
types: [edited]
9+
10+
jobs:
11+
sync-patch-notes:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout default branch
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 1
19+
20+
- name: Parse project name from tag
21+
id: parse-tag
22+
run: |
23+
TAG_NAME="${{ github.event.release.tag_name }}"
24+
PROJECT_NAME=$(echo "$TAG_NAME" | cut -d'/' -f1)
25+
echo "PROJECT_NAME=$PROJECT_NAME" >> $GITHUB_OUTPUT
26+
echo "Parsed project name: $PROJECT_NAME from tag: $TAG_NAME"
27+
28+
- name: Checkout patch-notes branch
29+
uses: actions/checkout@v4
30+
with:
31+
ref: patch-notes
32+
fetch-depth: 0
33+
token: ${{ secrets.GITHUB_TOKEN }}
34+
path: patch-notes-workdir
35+
36+
- name: Create project-specific patch notes
37+
run: |
38+
PROJECT_NAME="${{ steps.parse-tag.outputs.PROJECT_NAME }}"
39+
TAG_NAME="${{ github.event.release.tag_name }}"
40+
RELEASE_BODY='${{ github.event.release.body }}'
41+
42+
# 如果 body 为空,使用默认值
43+
if [ -z "$RELEASE_BODY" ]; then
44+
RELEASE_BODY="No release notes provided."
45+
fi
46+
47+
# 创建项目特定的 patch notes 文件
48+
printf '%s\n' "## ${PROJECT_NAME} - ${TAG_NAME}" > "patch-notes-workdir/patch-notes-${PROJECT_NAME}.html"
49+
printf '%s\n' "" >> "patch-notes-workdir/patch-notes-${PROJECT_NAME}.html"
50+
printf '%s\n' "${RELEASE_BODY}" >> "patch-notes-workdir/patch-notes-${PROJECT_NAME}.html"
51+
printf '%s\n' "" >> "patch-notes-workdir/patch-notes-${PROJECT_NAME}.html"
52+
printf '%s\n' "---" >> "patch-notes-workdir/patch-notes-${PROJECT_NAME}.html"
53+
printf '%s\n' "*Updated at: $(date -u +"%Y-%m-%dT%H:%M:%SZ")*" >> "patch-notes-workdir/patch-notes-${PROJECT_NAME}.html"
54+
55+
echo "✅ Created patch-notes-${PROJECT_NAME}.html"
56+
57+
- name: Commit & push
58+
uses: stefanzweifel/git-auto-commit-action@v5
59+
with:
60+
repository: patch-notes-workdir
61+
commit_message: "chore: sync patch-notes for ${{ steps.parse-tag.outputs.PROJECT_NAME }} (${{ github.event.release.tag_name }})"
62+
file_pattern: patch-notes-*.html
63+
branch: patch-notes
64+
create_branch: true
65+
commit_user_name: github-actions[bot]
66+
commit_user_email: 41898282+github-actions[bot]@users.noreply.github.com
67+
commit_author: Kane-Kuroneko <40685018+Kane-Kuroneko@users.noreply.github.com>
68+
push_options: '--force-with-lease'

0 commit comments

Comments
 (0)