Skip to content

Commit 3401b76

Browse files
Updated Changelog Workflow (#2632)
1 parent 599a518 commit 3401b76

File tree

4 files changed

+98
-55
lines changed

4 files changed

+98
-55
lines changed

.github/autolabeler-config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,5 @@
6767
"includeGlobs": ["misc/build.func", "misc/install.func", "ct/create_lxc.sh"],
6868
"excludeGlobs": []
6969
}
70-
]
70+
]
7171
}

.github/changelog-pr-config.json

+17-4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,27 @@
77
"title": "🆕 New Scripts",
88
"labels": ["new script"]
99
},
10-
{
11-
"title": "🐞 Bug Fixes",
12-
"labels": ["bugfix"]
13-
},
1410
{
1511
"title": "✨ New Features",
1612
"labels": ["feature"]
1713
},
14+
{
15+
"title": "🚀 Updated Scripts",
16+
"labels": ["update script"],
17+
"subCategories": [
18+
{
19+
"title": "🐞 Bug Fixes",
20+
"labels": ["bugfix"],
21+
"notes" : []
22+
},
23+
{
24+
"title": "General Updates",
25+
"labels": ["general"],
26+
"notes" : []
27+
}
28+
]
29+
},
30+
1831
{
1932
"title": "🌐 Website",
2033
"labels": ["website"]

.github/workflows/autolabeler.yml

+25-18
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ jobs:
3232
const autolabelerConfig = JSON.parse(fileContent);
3333
3434
const prNumber = context.payload.pull_request.number;
35-
const prBody = context.payload.pull_request.body;
36-
35+
const prBody = context.payload.pull_request.body.toLowerCase();
36+
3737
let labelsToAdd = new Set();
3838
3939
const prListFilesResponse = await github.rest.pulls.listFiles({
@@ -42,14 +42,35 @@ jobs:
4242
pull_number: prNumber,
4343
});
4444
const prFiles = prListFilesResponse.data;
45+
46+
const templateLabelMappings = {
47+
"🐞 **bug fix**": "bugfix",
48+
"✨ **new feature**": "feature",
49+
"💥 **breaking change**": "breaking change",
50+
"🆕 **new script**": "new script"
51+
};
52+
53+
for (const [checkbox, label] of Object.entries(templateLabelMappings)) {
54+
const escapedCheckbox = checkbox.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
55+
const regex = new RegExp(`- \\[(x|X)\\]\\s*.*${escapedCheckbox}`, "i");
56+
const match = prBody.match(regex);
57+
if (match) {
58+
console.log(`Match: ${match}`);
59+
labelsToAdd.add(label);
60+
}
61+
}
62+
if (labelsToAdd.size === 0) {
63+
labelsToAdd.add("general");
64+
}
4565
66+
// Apply labels based on file changes
4667
for (const [label, rules] of Object.entries(autolabelerConfig)) {
4768
const shouldAddLabel = prFiles.some((prFile) => {
4869
return rules.some((rule) => {
4970
const isFileStatusMatch = rule.fileStatus ? rule.fileStatus === prFile.status : true;
5071
const isIncludeGlobMatch = rule.includeGlobs.some((glob) => minimatch(prFile.filename, glob));
5172
const isExcludeGlobMatch = rule.excludeGlobs.some((glob) => minimatch(prFile.filename, glob));
52-
73+
5374
return isFileStatusMatch && isIncludeGlobMatch && !isExcludeGlobMatch;
5475
});
5576
});
@@ -58,21 +79,7 @@ jobs:
5879
labelsToAdd.add(label);
5980
}
6081
}
61-
62-
const templateLabelMappings = {
63-
"🐞 bug fix": "bugfix",
64-
"✨ new feature": "feature",
65-
"💥 breaking change": "breaking change",
66-
"🆕 new script": "new script"
67-
};
68-
69-
for (const [checkbox, label] of Object.entries(templateLabelMappings)) {
70-
const regex = new RegExp(`- \\[x\\] ${checkbox}`, "i"); // Match only checked checkboxes
71-
if (regex.test(prBody)) {
72-
labelsToAdd.add(label);
73-
}
74-
}
75-
82+
7683
console.log(`Labels to add: ${Array.from(labelsToAdd).join(", ")}`);
7784
7885
if (labelsToAdd.size > 0) {

.github/workflows/changelog-pr.yml

+55-32
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ jobs:
3030

3131
- name: Get latest dates in changelog
3232
run: |
33-
# Extrahiere die neuesten zwei Daten aus dem Changelog
3433
DATES=$(grep -E '^## [0-9]{4}-[0-9]{2}-[0-9]{2}' CHANGELOG.md | head -n 2 | awk '{print $2}')
3534
3635
LATEST_DATE=$(echo "$DATES" | sed -n '1p')
@@ -55,7 +54,15 @@ jobs:
5554
const configPath = path.resolve(process.env.CONFIG_PATH);
5655
const fileContent = await fs.readFile(configPath, 'utf-8');
5756
const changelogConfig = JSON.parse(fileContent);
58-
const categorizedPRs = changelogConfig.map(obj => ({ ...obj, notes: [] }));
57+
58+
const categorizedPRs = changelogConfig.map(obj => ({
59+
...obj,
60+
notes: [],
61+
subCategories: obj.subCategories ?? (obj.labels.includes("update script") ? [
62+
{ title: "🐞 Bug Fixes", labels: ["bugfix"] },
63+
{ title: "✨ Feature Updates", labels: ["feature"] }
64+
] : [])
65+
}));
5966
6067
const latestDateInChangelog = new Date(process.env.LATEST_DATE);
6168
latestDateInChangelog.setUTCHours(23, 59, 59, 999);
@@ -70,40 +77,36 @@ jobs:
7077
per_page: 100,
7178
});
7279
73-
pulls.filter(pr =>
74-
pr.merged_at &&
75-
new Date(pr.merged_at) > latestDateInChangelog &&
76-
!pr.labels.some(label => ["invalid", "wontdo", process.env.AUTOMATED_PR_LABEL].includes(label.name.toLowerCase()))
80+
pulls.filter(pr =>
81+
pr.merged_at &&
82+
new Date(pr.merged_at) > latestDateInChangelog &&
83+
!pr.labels.some(label =>
84+
["invalid", "wontdo", process.env.AUTOMATED_PR_LABEL].includes(label.name.toLowerCase())
85+
)
7786
).forEach(pr => {
87+
7888
const prLabels = pr.labels.map(label => label.name.toLowerCase());
7989
const prNote = `- ${pr.title} [@${pr.user.login}](https://github.com/${pr.user.login}) ([#${pr.number}](${pr.html_url}))`;
8090
81-
let isCategorized = false;
91+
const updateScriptsCategory = categorizedPRs.find(category =>
92+
category.labels.some(label => prLabels.includes(label))
93+
);
8294
83-
for (const { labels, notes } of categorizedPRs) {
84-
// If no labels are specified (e.g., "Unlabelled"), assign to this category
85-
if (labels.length === 0 && prLabels.length === 0) {
86-
notes.push(prNote);
87-
isCategorized = true;
88-
break;
89-
}
95+
if (updateScriptsCategory) {
96+
97+
const subCategory = updateScriptsCategory.subCategories.find(sub =>
98+
sub.labels.some(label => prLabels.includes(label))
99+
);
90100
91-
// If labels are specified, check if PR has ALL required labels
92-
if (labels.length > 0 && labels.every(label => prLabels.includes(label.toLowerCase()))) {
93-
notes.push(prNote);
94-
isCategorized = true;
95-
break;
96-
}
97-
}
98-
99-
// If PR is not categorized, assign it to the "Unlabelled" category
100-
if (!isCategorized) {
101-
const unlabelledCategory = categorizedPRs.find(cat => cat.title === "❔ Unlabelled");
102-
if (unlabelledCategory) {
103-
unlabelledCategory.notes.push(prNote);
101+
if (subCategory) {
102+
subCategory.notes.push(prNote);
103+
} else {
104+
updateScriptsCategory.notes.push(prNote);
104105
}
105106
}
106107
});
108+
109+
console.log(JSON.stringify(categorizedPRs, null, 2));
107110
108111
return categorizedPRs;
109112
@@ -119,13 +122,33 @@ jobs:
119122
const changelogPath = path.resolve('CHANGELOG.md');
120123
const categorizedPRs = ${{ steps.get-categorized-prs.outputs.result }};
121124
125+
console.log(JSON.stringify(categorizedPRs, null, 2));
126+
122127
let newReleaseNotes = `## ${today}\n\n### Changes\n\n`;
123-
for (const { title, notes } of categorizedPRs) {
124-
if (notes.length > 0) {
125-
newReleaseNotes += `### ${title}\n\n${notes.join("\n")}\n\n`;
128+
for (const { title, notes, subCategories } of categorizedPRs) {
129+
const hasSubcategories = subCategories && subCategories.length > 0;
130+
const hasMainNotes = notes.length > 0;
131+
const hasSubNotes = hasSubcategories && subCategories.some(sub => sub.notes && sub.notes.length > 0);
132+
133+
134+
if (hasMainNotes || hasSubNotes) {
135+
newReleaseNotes += `### ${title}\n\n`;
136+
}
137+
138+
if (hasMainNotes) {
139+
newReleaseNotes += `${notes.join("\n")}\n\n`;
140+
}
141+
142+
if (hasSubcategories) {
143+
for (const { title: subTitle, notes: subNotes } of subCategories) {
144+
if (subNotes && subNotes.length > 0) {
145+
newReleaseNotes += ` #### ${subTitle}\n\n`;
146+
newReleaseNotes += ` ${subNotes.join("\n ")}\n\n`;
147+
}
148+
}
126149
}
127-
}
128-
150+
}
151+
129152
const changelogContent = await fs.readFile(changelogPath, 'utf-8');
130153
const changelogIncludesTodaysReleaseNotes = changelogContent.includes(`\n## ${today}`);
131154

0 commit comments

Comments
 (0)