Skip to content

Commit ffad5a0

Browse files
committed
Merge branch 'master' of https://github.com/ZXXX1999/MY
2 parents d5e283a + e67b26e commit ffad5a0

File tree

11 files changed

+389
-73
lines changed

11 files changed

+389
-73
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.github/ @tinymins

.github/workflows/lint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Lint
33
on:
44
push:
55
pull_request:
6+
workflow_dispatch:
67

78
jobs:
89
lint:

.github/workflows/publish.yml

Lines changed: 104 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@ on:
44
workflow_dispatch:
55
inputs:
66
version:
7-
description: '要发布的版本号'
7+
description: '要发布的版本号'
88
required: true
99
default: |
1010
0.0.0
1111
type: string
1212
changelog:
13-
description: '更新日志(子插件壹:更新内容|子插件贰:更新内容)'
13+
description: '更新日志(子插件壹:更新内容|子插件贰:更新内容)'
1414
required: true
1515
type: string
1616

1717
jobs:
1818
publish:
1919
runs-on: ubuntu-latest
20+
name: 🚀 自动化构建
2021
environment:
2122
name: Publish
2223
url: ${{ github.server_url }}/${{ github.repository }}/releases/tag/v${{ github.event.inputs.version }}
@@ -75,19 +76,68 @@ jobs:
7576
sed -i "s/\(local _VERSION_\)\( *\)\(=\) *'[^']*'/\1\2\3 '${VERSION}'/" MY_!Base/src/lib/Base.lua
7677
7778
- name: Update CHANGELOG.md
79+
id: update_changelog
7880
run: |
7981
VERSION="${{ github.event.inputs.version }}"
8082
CHANGELOG="${{ github.event.inputs.changelog }}"
8183
TMPFILE=$(mktemp)
82-
echo "# 更新日志" > $TMPFILE
84+
echo "# 更新日志" > $TMPFILE
8385
echo "" >> $TMPFILE
84-
echo "## 茗伊插件集 v${VERSION}" >> $TMPFILE
85-
echo "" >> $TMPFILE
86-
echo "$CHANGELOG" | tr '|' '\n' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | sed 's/^["""]//g' | sed 's/["""]$//g' | sed 's/[::]/] /g' | sed 's/^/* [/g' >> $TMPFILE
86+
87+
# 智能处理更新日志内容
88+
process_changelog() {
89+
local input="$1"
90+
91+
# 首先处理原始格式 * [插件] 内容,在 * 前面添加分隔符
92+
input=$(echo "$input" | sed 's/\([^|]\)\(\*[[:space:]]*\[\)/\1|\2/g')
93+
94+
# 按 | 分割每一行
95+
echo "$input" | tr '|' '\n' | while IFS= read -r line; do
96+
# 去掉首尾空格
97+
line=$(echo "$line" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
98+
99+
# 去掉首尾引号
100+
line=$(echo "$line" | sed 's/^["""]//;s/["""]$//')
101+
102+
# 跳过空行
103+
[ -z "$line" ] && continue
104+
105+
# 检查是否已经是 * [插件] 格式
106+
if echo "$line" | grep -q '^\*[[:space:]]*\['; then
107+
# 已经是正确格式,只需要格式化空格
108+
plugin=$(echo "$line" | sed 's/^\*[[:space:]]*\[\([^]]*\)\].*/\1/' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
109+
content=$(echo "$line" | sed 's/^\*[[:space:]]*\[[^]]*\][[:space:]]*//')
110+
echo "* [$plugin] $content"
111+
else
112+
# 转换 插件:内容 格式为 * [插件] 内容
113+
if echo "$line" | grep -q '[::]'; then
114+
plugin=$(echo "$line" | sed 's/\([^::]*\)[::].*/\1/' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | sed 's/^["""]//;s/["""]$//')
115+
content=$(echo "$line" | sed 's/[^::]*[::][[:space:]]*//' | sed 's/^["""]//;s/["""]$//')
116+
echo "* [$plugin] $content"
117+
else
118+
# 如果没有冒号,假设整行都是内容
119+
echo "* $line"
120+
fi
121+
fi
122+
done
123+
}
124+
125+
# 处理更新日志并保存到临时变量
126+
PROCESSED_CHANGELOG="## 茗伊插件集 v${VERSION}"$'\n\n'"$(process_changelog "$CHANGELOG")"
127+
128+
# 输出到 TMPFILE
129+
echo "$PROCESSED_CHANGELOG" >> $TMPFILE
87130
echo "" >> $TMPFILE
88131
tail -n +3 CHANGELOG.md >> $TMPFILE
89132
mv $TMPFILE CHANGELOG.md
90133
134+
# 设置步骤输出(用于后续步骤)
135+
{
136+
echo "changelog<<EOF"
137+
echo "$PROCESSED_CHANGELOG"
138+
echo "EOF"
139+
} >> $GITHUB_OUTPUT
140+
91141
- name: Write secret to file
92142
run: |
93143
cat > secret.jx3dat << 'EOF'
@@ -104,26 +154,60 @@ jobs:
104154
run: |
105155
python3 \!src-dist/ci.py
106156
107-
- name: Push commits
108-
run: |
109-
git push -f origin master:stable
110-
111-
- name: Create release branch and PR
112-
env:
113-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
157+
- name: Create Release Branch
114158
run: |
115159
VERSION="${{ github.event.inputs.version }}"
116160
BRANCH="release/v${VERSION}"
117-
git checkout -b $BRANCH
118-
git push -u origin $BRANCH -f
119-
gh pr create \
120-
--title "release: v${VERSION}" \
121-
--body "Automated release PR for version ${VERSION}" \
122-
--base master \
123-
--head $BRANCH || echo "PR already exists or failed to create, continuing..."
161+
git push -f origin master:stable
162+
git push -f origin master:$BRANCH
163+
164+
- name: Create Pull Request
165+
id: create_pr
166+
uses: peter-evans/create-pull-request@v5
167+
with:
168+
token: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
169+
title: "release: v${{ github.event.inputs.version }}"
170+
body: "Automated release PR for version ${{ github.event.inputs.version }}"
171+
base: master
172+
branch: "release/v${{ github.event.inputs.version }}"
124173

125174
- name: Upload Artifacts
175+
id: upload_artifacts
126176
uses: actions/upload-artifact@v4
127177
with:
128178
name: dist-archives-${{ github.run_number }}-${{ github.sha }}
129179
path: '\!src-dist/dist/*.7z'
180+
181+
- name: Output Summary
182+
if: steps.create_pr.outputs.pull-request-url
183+
run: |
184+
echo "# 🎉 构建成功!" >> $GITHUB_STEP_SUMMARY
185+
echo "" >> $GITHUB_STEP_SUMMARY
186+
187+
# 输出更新日志内容
188+
echo "## 📝 更新日志内容" >> $GITHUB_STEP_SUMMARY
189+
echo "" >> $GITHUB_STEP_SUMMARY
190+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
191+
echo "${{ steps.update_changelog.outputs.changelog }}" >> $GITHUB_STEP_SUMMARY
192+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
193+
echo "" >> $GITHUB_STEP_SUMMARY
194+
195+
# 输出 Pull Request 信息
196+
echo "## 🔗 Pull Request 信息" >> $GITHUB_STEP_SUMMARY
197+
echo "" >> $GITHUB_STEP_SUMMARY
198+
echo "📝 **Pull Request 已创建**: ${{ steps.create_pr.outputs.pull-request-url }}" >> $GITHUB_STEP_SUMMARY
199+
echo "" >> $GITHUB_STEP_SUMMARY
200+
echo "🎯 **版本**: v${{ github.event.inputs.version }}" >> $GITHUB_STEP_SUMMARY
201+
echo "" >> $GITHUB_STEP_SUMMARY
202+
203+
# 输出 Artifacts 信息
204+
echo "## 📦 构建产物" >> $GITHUB_STEP_SUMMARY
205+
echo "" >> $GITHUB_STEP_SUMMARY
206+
echo "📁 **Artifacts 名称**: \`dist-archives-${{ github.run_number }}-${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY
207+
echo "" >> $GITHUB_STEP_SUMMARY
208+
echo "🔗 **下载链接**: [${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> $GITHUB_STEP_SUMMARY
209+
echo "" >> $GITHUB_STEP_SUMMARY
210+
echo "💡 点击上面的链接可以在 Actions 页面中找到并下载构建产物" >> $GITHUB_STEP_SUMMARY
211+
212+
# 同时输出 notice
213+
echo "::notice title=📝 Pull Request 已生成::Pull Request created: ${{ steps.create_pr.outputs.pull-request-url }}"

.github/workflows/release.yml

Lines changed: 87 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@ on:
44
push:
55
branches:
66
- master
7-
pull_request:
8-
types: [closed]
97

108
jobs:
119
release:
1210
runs-on: ubuntu-latest
13-
if: |
14-
(github.event_name == 'push' && contains(github.event.head_commit.message, 'release')) ||
15-
(github.event_name == 'pull_request' && github.event.pull_request.merged == true)
11+
if: startsWith(github.event.head_commit.message, 'release:')
1612
strategy:
1713
max-parallel: 5
1814

@@ -21,6 +17,23 @@ jobs:
2117
with:
2218
fetch-depth: 0
2319

20+
- name: Validate release commit message format
21+
run: |
22+
COMMIT_MSG="${{ github.event.head_commit.message }}"
23+
echo "Commit message: $COMMIT_MSG"
24+
25+
# 使用正则表达式验证格式: release: x.x.x-xxx (其中 -xxx 是可选的)
26+
if echo "$COMMIT_MSG" | grep -qE "^release:\s*[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?(\s|$)"; then
27+
echo "✅ Commit message format is valid for release"
28+
else
29+
echo "❌ Commit message format is invalid. Expected format: 'release: x.x.x' or 'release: x.x.x-xxx'"
30+
echo "Examples:"
31+
echo " - release: 1.0.0"
32+
echo " - release: 2.1.3-alpha"
33+
echo " - release: 1.5.0-beta1"
34+
exit 1
35+
fi
36+
2437
- name: Set up Python 3.10
2538
uses: actions/setup-python@v3
2639
with:
@@ -54,8 +67,73 @@ jobs:
5467
run: |
5568
python3 \!src-dist/ci.py
5669
57-
- name: Upload Artifacts
58-
uses: actions/upload-artifact@v4
70+
- name: Get tag from Base.lua
71+
id: get_tag
72+
run: |
73+
VERSION=$(grep "local _VERSION_" "MY_!Base/src/lib/Base.lua" | sed -n "s/local _VERSION_.*= *['\"]\\([^'\"]*\\)['\"].*/\\1/p")
74+
if [ -z "$VERSION" ]; then
75+
echo "Error: Could not extract version from Base.lua"
76+
exit 1
77+
fi
78+
echo "tag=v$VERSION" >> $GITHUB_OUTPUT
79+
echo "Extracted version: $VERSION"
80+
81+
- name: Generate release notes
82+
id: release_notes
83+
run: |
84+
TAG="${{ steps.get_tag.outputs.tag }}"
85+
86+
# 获取tag的完整注释信息
87+
TAG_MESSAGE=$(git tag -l --format='%(contents)' "$TAG")
88+
89+
if [ -z "$TAG_MESSAGE" ]; then
90+
echo "Error: No tag message found for $TAG"
91+
echo "Please create tag with proper release notes"
92+
exit 1
93+
fi
94+
95+
echo "Found tag message for $TAG"
96+
# 提取从 "Release vX.X.X" 开始的所有内容作为release notes
97+
RELEASE_NOTES=$(echo "$TAG_MESSAGE" | sed -n '/^Release v/,$p')
98+
99+
if [ -z "$RELEASE_NOTES" ]; then
100+
# 如果没有找到 "Release v" 开头的内容,使用整个tag消息
101+
RELEASE_NOTES="$TAG_MESSAGE"
102+
fi
103+
104+
# 设置release notes(只使用tag内容)
105+
{
106+
echo "release_notes<<EOF"
107+
echo "$RELEASE_NOTES"
108+
echo "EOF"
109+
} >> $GITHUB_OUTPUT
110+
111+
- name: Create GitHub Release
112+
uses: actions/create-release@v1
113+
id: create_release
114+
env:
115+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59116
with:
60-
name: dist-archives-${{ github.run_number }}-${{ github.sha }}
61-
path: '\!src-dist/dist/*.7z'
117+
tag_name: ${{ steps.get_tag.outputs.tag }}
118+
release_name: Release ${{ steps.get_tag.outputs.tag }}
119+
body: ${{ steps.release_notes.outputs.release_notes }}
120+
draft: false
121+
prerelease: false
122+
123+
- name: Upload Release Assets
124+
run: |
125+
TAG="${{ steps.get_tag.outputs.tag }}"
126+
UPLOAD_URL="${{ steps.create_release.outputs.upload_url }}"
127+
128+
# 上传所有.7z文件到release
129+
for file in \!src-dist/dist/*.7z; do
130+
if [ -f "$file" ]; then
131+
filename=$(basename "$file")
132+
echo "Uploading $filename to release $TAG..."
133+
curl -X POST \
134+
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
135+
-H "Content-Type: application/octet-stream" \
136+
--data-binary @"$file" \
137+
"${UPLOAD_URL%\{*}?name=$filename"
138+
fi
139+
done

0 commit comments

Comments
 (0)