-
Notifications
You must be signed in to change notification settings - Fork 33
184 lines (156 loc) · 7.01 KB
/
release-changelog.yml
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
name: Auto Changelog PR
on:
release:
types: [published]
jobs:
changelog:
runs-on: ubuntu-latest
steps:
- name: Checkout the Beta9 repo
uses: actions/checkout@v3
- name: Fetch the latest release data
id: release
uses: actions/github-script@v7
with:
script: |
function formatDate(dateString) {
const date = new Date(dateString);
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const year = String(date.getFullYear()).slice(-2);
return `${month}-${day}-${year}`;
}
function prettyDate(dateString) {
const date = new Date(dateString);
return new Intl.DateTimeFormat('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
timeZone: 'UTC',
}).format(date);
}
const release = context.payload.release;
// log the release object to help debug failed actions
console.log(release);
const lines = release.body.split('\n');
const feats = [];
const fixes = [];
for (const line of lines) {
if (line.startsWith('*')) {
const m = line.match(/^\*\s*([fF]eat|[fF]ix):\s*(.*)\s*/);
if (m) {
const [_, type, description] = m;
const byIndex = description.indexOf('by');
if (type.toLowerCase() === 'feat') {
const cleanedDesc = description.slice(0, byIndex).trim();
feats.push(cleanedDesc);
} else if (type.toLowerCase() === 'fix') {
const cleanedDesc = description.slice(0, byIndex).trim();
fixes.push(cleanedDesc);
}
}
}
}
// Stop the workflow if no features or fixes are found
if (feats.length === 0 && fixes.length === 0) {
core.setOutput('should_continue', 'false');
core.setOutput('error_message', 'No features or fixes found in the release notes. Stopping workflow.');
return;
}
core.setOutput('name', release.tag_name);
core.setOutput('new_feats', JSON.stringify(feats));
core.setOutput('new_fixes', JSON.stringify(fixes));
core.setOutput('created_at', formatDate(release.created_at));
core.setOutput('pretty_date', prettyDate(release.created_at));
core.setOutput('should_continue', 'true');
- name: Checkout beam-docs repo
if: steps.release.outputs.should_continue == 'true'
uses: actions/checkout@v3
with:
repository: slai-labs/beam-docs
path: beam-docs
token: ${{ secrets.BEAM_DOCS_PAT }}
- name: Process changelog
if: steps.release.outputs.should_continue == 'true'
id: process_changelog
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
const filename = `./beam-docs/v2/releases/${process.env.CREATED_AT}.mdx`;
let existingFeats = [];
let existingFixes = [];
if (fs.existsSync(filename)) {
const content = fs.readFileSync(filename, 'utf8');
const featuresMatch = content.match(/## Features\n([\s\S]*?)(?=\n## |$)/);
const fixesMatch = content.match(/## Fixes\n([\s\S]*?)(?=\n## |$)/);
if (featuresMatch) {
existingFeats = featuresMatch[1].split('\n').filter(line => line.trim().startsWith('-')).map(line => line.trim().slice(2));
}
if (fixesMatch) {
existingFixes = fixesMatch[1].split('\n').filter(line => line.trim().startsWith('-')).map(line => line.trim().slice(2));
}
}
const newFeats = JSON.parse(process.env.NEW_FEATS);
const newFixes = JSON.parse(process.env.NEW_FIXES);
const allFeats = [...new Set([...existingFeats, ...newFeats])];
const allFixes = [...new Set([...existingFixes, ...newFixes])];
const featsString = allFeats.map(feat => `- ${feat}`).join('\n');
const fixesString = allFixes.map(fix => `- ${fix}`).join('\n');
core.setOutput('feats', featsString);
core.setOutput('fixes', fixesString);
env:
CREATED_AT: ${{ steps.release.outputs.created_at }}
NEW_FEATS: ${{ steps.release.outputs.new_feats }}
NEW_FIXES: ${{ steps.release.outputs.new_fixes }}
- name: Create new release file in beam-docs
if: steps.release.outputs.should_continue == 'true'
run: |
cd beam-docs/v2/releases
FILENAME="./${{ steps.release.outputs.created_at }}.mdx"
if [ -f "$FILENAME" ]; then
rm -f $FILENAME
fi
echo "---" >> $FILENAME
echo "title: \"${{ steps.release.outputs.pretty_date }}\"" >> $FILENAME
echo "---" >> $FILENAME
echo "" >> $FILENAME
echo "## Features" >> $FILENAME
echo "" >> $FILENAME
echo "${{ steps.process_changelog.outputs.feats }}" >> $FILENAME
echo "" >> $FILENAME
echo "## Fixes" >> $FILENAME
echo "" >> $FILENAME
echo "${{ steps.process_changelog.outputs.fixes }}" >> $FILENAME
echo "" >> $FILENAME
- name: Update mint.json
if: steps.release.outputs.should_continue == 'true'
run: |
cd beam-docs
NEW_FILE="v2/releases/${{ steps.release.outputs.created_at }}"
jq --arg new_file "$NEW_FILE" '
.navigation[] |=
if .group == "Releases" then
.pages |= if index($new_file) then . else [$new_file] + . end
else
.
end
' ./mint.json > ./mint.json.tmp && mv ./mint.json.tmp ./mint.json
- name: Commit and push changes
if: steps.release.outputs.should_continue == 'true'
run: |
cd beam-docs
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
git checkout -b autochangelog/${{ steps.release.outputs.name }}
git add .
git commit -m "Add changelog for ${{ steps.release.outputs.name }}"
git push -u origin autochangelog/${{ steps.release.outputs.name }}
- name: Create pull request
if: steps.release.outputs.should_continue == 'true'
env:
GH_TOKEN: ${{ secrets.BEAM_DOCS_PAT }}
run: |
cd beam-docs
gh pr create --title "Changelog for ${{ steps.release.outputs.name }}" --body "This PR adds the changelog for ${{ steps.release.outputs.name }}." --base main --head autochangelog/${{ steps.release.outputs.name }}