Repository navigation
144 lines (133 loc) · 4.94 KB
/
Copy pathai-release-notes.yml
File metadata and controls
144 lines (133 loc) · 4.94 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
name: AI Release Notes
on:
workflow_call:
inputs:
tag-name:
description: 'The tag that triggered the release (e.g. v1.2.3)'
required: true
type: string
secrets:
DEEPSEEK_API_KEY:
required: true
DEEPSEEK_BASE_URL:
required: true
DEEPSEEK_MODEL:
required: true
outputs:
release-notes-path:
description: 'Path to the generated release notes markdown file'
value: /tmp/release_notes.md
permissions:
contents: read
pull-requests: read
jobs:
generate-notes:
name: Generate AI Release Notes
runs-on: ubuntu-latest
outputs:
release-notes-path: /tmp/release_notes.md
steps:
- name: Checkout Caller Repo
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Checkout Shared Workflows
uses: actions/checkout@v7
with:
repository: RimWorld-RimMind-Mod/Workflows
path: .shared-workflows
- name: Determine Git Range
id: git-range
run: |
CURRENT_TAG="${{ inputs.tag-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 }}
DEEPSEEK_MODEL: ${{ secrets.DEEPSEEK_MODEL }}
run: |
python .shared-workflows/scripts/analyze_release.py \
--tag "${{ steps.git-range.outputs.current }}" \
--prs-file /tmp/prs.json \
--commits-txt /tmp/commits.txt
- name: Upload Release Notes
uses: actions/upload-artifact@v7
with:
name: release-notes
path: /tmp/release_notes.md
retention-days: 1