Repository navigation
196 lines (168 loc) · 6.72 KB
/
Copy pathrelease.yml
File metadata and controls
196 lines (168 loc) · 6.72 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
name: Generate Tag Release
run-name: ${{ github.ref_name }}
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'
- 'V[0-9]+.[0-9]+.[0-9]+*'
permissions:
contents: write
pull-requests: read
jobs:
release:
name: Generate Release & Package Mod
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v6
with:
dotnet-version: '10.0.x'
- name: Build Core Dependency
run: |
git clone --depth 1 https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Core.git ../RimMind-Core
dotnet build ../RimMind-Core/Source/RimMindCore.csproj --configuration Release
- name: Build Mod
run: dotnet build Source/RimMindMemory.csproj --configuration Release
- name: Determine Git Range
id: git-range
run: |
CURRENT_TAG="${{ github.ref_name }}"
PREVIOUS_TAG=$(git describe --tags --abbrev=0 "${CURRENT_TAG}^" 2>/dev/null || echo "")
echo "::group::[Debug] Tag 计算结果"
echo "当前 Tag: $CURRENT_TAG"
if [ -z "$PREVIOUS_TAG" ]; then
echo "未找到上一个 Tag,将获取全部历史"
else
echo "上一个 Tag: $PREVIOUS_TAG"
echo "对比区间: ${PREVIOUS_TAG}...${CURRENT_TAG}"
fi
echo "::endgroup::"
echo "current=$CURRENT_TAG" >> $GITHUB_OUTPUT
echo "base=$PREVIOUS_TAG" >> $GITHUB_OUTPUT
- name: Collect Raw Commits
run: |
BASE="${{ steps.git-range.outputs.base }}"
HEAD="${{ steps.git-range.outputs.current }}"
if [ -z "$BASE" ]; then
git log --pretty=format:"* %h - %s (%an)" "$HEAD" > /tmp/commits.txt
else
git log --pretty=format:"* %h - %s (%an)" "${BASE}..${HEAD}" > /tmp/commits.txt
fi
echo "::group::[Debug] 原始 Commit 列表"
cat /tmp/commits.txt
echo "::endgroup::"
- name: Collect PR Data
uses: actions/github-script@v9
with:
script: |
const base = '${{ steps.git-range.outputs.base }}';
const head = '${{ steps.git-range.outputs.current }}';
const compareOptions = {
owner: context.repo.owner,
repo: context.repo.repo,
head: head
};
if (base) compareOptions.base = base;
const { data: compare } = await github.rest.repos.compareCommits(compareOptions);
console.log(`::notice::共检测到 ${compare.commits.length} 个 Commits`);
const prNumbers = new Set();
for (const commit of compare.commits) {
const message = commit.commit.message;
const mergeMatch = message.match(/Merge pull request #(\d+)/);
if (mergeMatch) prNumbers.add(parseInt(mergeMatch[1]));
const suffixMatch = message.match(/\(#(\d+)\)$/);
if (suffixMatch) prNumbers.add(parseInt(suffixMatch[1]));
const fixMatch = message.match(/(?:fixes|closes|resolves) #(\d+)/i);
if (fixMatch) prNumbers.add(parseInt(fixMatch[1]));
}
const prDetails = [];
for (const num of prNumbers) {
try {
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: num
});
prDetails.push({
number: pr.number,
title: pr.title,
body: pr.body,
author: pr.user.login,
labels: pr.labels.map(l => l.name)
});
} catch (e) {
console.log(`::warning::获取 PR #${num} 失败: ${e.message}`);
}
}
const fs = require('fs');
fs.writeFileSync('/tmp/prs.json', JSON.stringify(prDetails, null, 2));
- name: Setup Python
uses: actions/setup-python@v7
with:
python-version: '3.11'
- name: Install Dependencies
run: pip install openai
- name: Generate AI Release Notes
env:
DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }}
DEEPSEEK_BASE_URL: ${{ secrets.DEEPSEEK_BASE_URL || 'https://api.deepseek.com' }}
run: |
python .github/scripts/analyze_release.py \
--tag "${{ steps.git-range.outputs.current }}" \
--prs-file /tmp/prs.json \
--commits-txt /tmp/commits.txt
- name: Package Mod
id: package
run: |
TAG="${{ steps.git-range.outputs.current }}"
if [ -f "About/About.xml" ]; then
MOD_NAME=$(grep -oP '(?<=<name>)[^<]+' About/About.xml | head -1)
MOD_SAFE=$(echo "$MOD_NAME" | sed 's/[^a-zA-Z0-9 ]//g' | sed 's/ /-/g' | sed 's/-\+/-/g')
else
MOD_SAFE="${{ github.event.repository.name }}"
fi
[ -z "$MOD_SAFE" ] && MOD_SAFE="mod"
echo "mod_safe=$MOD_SAFE" >> $GITHUB_OUTPUT
# 打包:排除开发相关文件,只保留玩家需要的内容
mkdir -p "/tmp/${MOD_SAFE}"
rsync -av --delete \
--exclude='.git/' \
--exclude='.github/' \
--exclude='Source/' \
--exclude='Tests/' \
--exclude='.claude/' \
--exclude='.trae/' \
--exclude='docs/' \
--exclude='*.csproj' \
--exclude='*.sln' \
--exclude='.gitignore' \
--exclude='.gitattributes' \
--exclude='*.md' \
"./" "/tmp/${MOD_SAFE}/"
cd /tmp
zip -r "${MOD_SAFE}-${TAG}.zip" "${MOD_SAFE}/"
echo "::notice::打包完成: ${MOD_SAFE}-${TAG}.zip"
- name: Check Prerelease
id: prerelease
run: |
TAG="${{ steps.git-range.outputs.current }}"
if echo "$TAG" | grep -qiE 'alpha|beta|rc|preview'; then
echo "is_prerelease=true" >> $GITHUB_OUTPUT
else
echo "is_prerelease=false" >> $GITHUB_OUTPUT
fi
- name: Publish GitHub Release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ steps.git-range.outputs.current }}
name: Release ${{ steps.git-range.outputs.current }}
body_path: /tmp/release_notes.md
prerelease: ${{ steps.prerelease.outputs.is_prerelease == 'true' }}
files: /tmp/${{ steps.package.outputs.mod_safe }}-${{ steps.git-range.outputs.current }}.zip
generate_release_notes: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}