-
Notifications
You must be signed in to change notification settings - Fork 0
210 lines (178 loc) · 7.52 KB
/
Copy pathrelease.yml
File metadata and controls
210 lines (178 loc) · 7.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
name: Release
on:
workflow_dispatch:
push:
branches:
- master
permissions:
contents: write
jobs:
release:
name: Generate Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # 必须获取完整历史以获取 tag 范围
- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- name: Extract version from Gradle
id: version
run: |
VERSION=$(grep -E '^version\s*=' build.gradle.kts | head -n1 | sed -E 's/.*"(.+)"$/\1/')
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
- name: Check if release commit
id: check_release
run: |
COMMIT_MSG=$(git log -1 --pretty=%B)
echo "Last commit message: $COMMIT_MSG"
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "Manual trigger: should_release=true"
echo "should_release=true" >> $GITHUB_OUTPUT
elif echo "$COMMIT_MSG" | grep -qE '\bv[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?\b'; then
echo "Release commit detected: $COMMIT_MSG"
echo "should_release=true" >> $GITHUB_OUTPUT
else
echo "No release commit detected. Skipping."
echo "should_release=false" >> $GITHUB_OUTPUT
fi
- name: Stop if not release
if: steps.check_release.outputs.should_release == 'false'
run: echo "Not a release commit, skipping job."
- name: Build project
if: steps.check_release.outputs.should_release == 'true'
run: |
chmod +x ./gradlew
./gradlew clean buildPlugin -x miraiPrepareMetadata
- name: Ensure tag exists (auto create if missing)
if: steps.check_release.outputs.should_release == 'true'
run: |
git fetch --tags
CURRENT_TAG="v${{ env.VERSION }}"
if ! git tag | grep -q "^$CURRENT_TAG$"; then
echo "Tag $CURRENT_TAG not found, creating it now."
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "$CURRENT_TAG"
git push origin "$CURRENT_TAG"
else
echo "Tag $CURRENT_TAG already exists."
fi
- name: Create Mirai Plugin Package
if: steps.check_release.outputs.should_release == 'true'
run: |
VERSION="${{ env.VERSION }}"
PLUGIN_NAME="GuessCS2ProPlayer"
# 创建临时目录结构
mkdir -p temp_package/plugins
mkdir -p temp_package/data/org.bcz.guesscs2proplayer
# 复制插件本体到plugins目录
cp build/libs/*.jar temp_package/plugins/
# 复制resource目录下的资源文件到data目录
if [ -d "resource" ]; then
echo "Copying resource files..."
cp -r resource/* temp_package/data/org.bcz.guesscs2proplayer/
echo "Resource files copied successfully"
else
echo "Warning: resource directory not found"
fi
# 显示打包内容
echo "Package contents:"
find temp_package -type f
# 创建最终的zip包
cd temp_package
zip -r "../${PLUGIN_NAME}-${VERSION}.zip" .
cd ..
# 清理临时目录
rm -rf temp_package
echo "Created package: ${PLUGIN_NAME}-${VERSION}.zip"
- name: Generate Changelog
if: steps.check_release.outputs.should_release == 'true'
id: changelog
run: |
echo "## 🎮 CS2 猜职业选手小游戏 - v${{ env.VERSION }}" > release_notes.md
echo "" >> release_notes.md
echo "### �� 发布包信息" >> release_notes.md
echo "- **插件本体**: 位于 `plugins/` 目录" >> release_notes.md
echo "- **资源文件**: 位于 `data/org.bcz.guesscs2proplayer/` 目录" >> release_notes.md
echo "" >> release_notes.md
echo "## 🎨 Changelog" >> release_notes.md
echo "" >> release_notes.md
git fetch --tags
CURRENT_TAG="v${{ env.VERSION }}"
ALL_TAGS=($(git tag --list "v*" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+' | sort -V))
# Find index of CURRENT_TAG
CUR_INDEX=-1
for ((i=0; i<${#ALL_TAGS[@]}; i++)); do
if [[ "${ALL_TAGS[$i]}" == "$CURRENT_TAG" ]]; then
CUR_INDEX=$i
break
fi
done
if [[ $CUR_INDEX -eq -1 ]]; then
echo "Current tag $CURRENT_TAG not found in tag list: ${ALL_TAGS[*]}"
exit 1
fi
if [[ $CUR_INDEX -eq 0 ]]; then
# First tag, show all commits up to this tag
RANGE=""
echo "No previous tag found, using all commits up to $CURRENT_TAG"
else
PREV_TAG="${ALL_TAGS[$((CUR_INDEX-1))]}"
RANGE="$PREV_TAG..$CURRENT_TAG"
echo "Previous tag: $PREV_TAG"
fi
COMMITS=$(git log --pretty=format:"%s (%an)" $RANGE | grep -v 'dependabot')
# 分类处理
NEW=""
FIXED=""
REFACTOR=""
DOCS=""
IMPROVED=""
OTHER=""
while IFS= read -r line; do
if [[ "$line" == feat:* ]]; then
NEW+=$'- '"${line#feat: }"$'\n'
elif [[ "$line" == fix:* ]]; then
FIXED+=$'- '"${line#fix: }"$'\n'
elif [[ "$line" == refactor:* ]]; then
REFACTOR+=$'- '"${line#refactor: }"$'\n'
elif [[ "$line" == docs:* ]]; then
DOCS+=$'- '"${line#docs: }"$'\n'
elif [[ "$line" == style:* || "$line" == perf:* ]]; then
IMPROVED+=$'- '"${line#*: }"$'\n'
else
OTHER+=$'- '"${line}"$'\n'
fi
done <<< "$COMMITS"
[[ -n "$NEW" ]] && echo -e "### ✅ New Features\n$NEW" >> release_notes.md
[[ -n "$FIXED" ]] && echo -e "### ️ Bug Fixes\n$FIXED" >> release_notes.md
[[ -n "$REFACTOR" ]] && echo -e "### 🧽 Refactoring\n$REFACTOR" >> release_notes.md
[[ -n "$DOCS" ]] && echo -e "### 📚 Documentation\n$DOCS" >> release_notes.md
[[ -n "$IMPROVED" ]] && echo -e "### 🚀 Improvements\n$IMPROVED" >> release_notes.md
[[ -n "$OTHER" ]] && echo -e "### 🔄 Other Changes\n$OTHER" >> release_notes.md
echo "" >> release_notes.md
echo "## 🚀 安装说明" >> release_notes.md
echo "1. 下载并解压 `GuessCS2ProPlayer-${{ env.VERSION }}.zip`" >> release_notes.md
echo "2. 将 `plugins/目录下的jar文件放入Mirai Console的plugins目录" >> release_notes.md
echo "3. 将 data/org.bcz.guesscs2proplayer/ 目录放入Mirai Console的data目录" >> release_notes.md
echo "4. 重启Mirai Console即可使用" >> release_notes.md
cat release_notes.md
- name: Create GitHub Release
if: steps.check_release.outputs.should_release == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ env.VERSION }}
name: "v${{ env.VERSION }}"
body_path: release_notes.md
files: |
GuessCS2ProPlayer-${{ env.VERSION }}.zip
build/libs/*.jar
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}