Skip to content

Commit 893bff1

Browse files
[gh] Update Changelog Workflow (#2621)
* Update Workflow * Update Workflow
1 parent bef3ccd commit 893bff1

File tree

4 files changed

+99
-31
lines changed

4 files changed

+99
-31
lines changed

.github/autolabeler-config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,5 @@
6868
"excludeGlobs": []
6969
}
7070
]
71+
7172
}

.github/changelog-pr-config.json

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,26 @@
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+
},
1830
{
1931
"title": "🌐 Website",
2032
"labels": ["website"]

.github/workflows/autolabeler.yml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ 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+
36+
const prBody = context.payload.pull_request.body.toLowerCase();
37+
3738
let labelsToAdd = new Set();
3839
3940
const prListFilesResponse = await github.rest.pulls.listFiles({
@@ -42,14 +43,35 @@ jobs:
4243
pull_number: prNumber,
4344
});
4445
const prFiles = prListFilesResponse.data;
46+
47+
const templateLabelMappings = {
48+
"🐞 **bug fix**": "bugfix",
49+
"✨ **new feature**": "feature",
50+
"💥 **breaking change**": "breaking change",
51+
"🆕 **new script**": "new script"
52+
};
53+
54+
for (const [checkbox, label] of Object.entries(templateLabelMappings)) {
55+
const escapedCheckbox = checkbox.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
56+
const regex = new RegExp(`- \\[(x|X)\\]\\s*.*${escapedCheckbox}`, "i");
57+
const match = prBody.match(regex);
58+
if (match) {
59+
console.log(`Match: ${match}`);
60+
labelsToAdd.add(label);
61+
}
62+
}
63+
if (labelsToAdd.size === 0) {
64+
labelsToAdd.add("general");
65+
}
4566
67+
// Apply labels based on file changes
4668
for (const [label, rules] of Object.entries(autolabelerConfig)) {
4769
const shouldAddLabel = prFiles.some((prFile) => {
4870
return rules.some((rule) => {
4971
const isFileStatusMatch = rule.fileStatus ? rule.fileStatus === prFile.status : true;
5072
const isIncludeGlobMatch = rule.includeGlobs.some((glob) => minimatch(prFile.filename, glob));
5173
const isExcludeGlobMatch = rule.excludeGlobs.some((glob) => minimatch(prFile.filename, glob));
52-
74+
5375
return isFileStatusMatch && isIncludeGlobMatch && !isExcludeGlobMatch;
5476
});
5577
});

.github/workflows/changelog-pr.yml

Lines changed: 57 additions & 24 deletions
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,29 +77,33 @@ 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;
8291
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-
}
92+
const updateScriptsCategory = categorizedPRs.find(category =>
93+
category.labels.some(label => prLabels.includes(label))
94+
);
95+
96+
if (updateScriptsCategory) {
97+
98+
const subCategory = updateScriptsCategory.subCategories.find(sub =>
99+
sub.labels.some(label => prLabels.includes(label))
100+
);
101+
102+
if (subCategory) {
103+
subCategory.notes.push(prNote);
104+
} else {
105+
updateScriptsCategory.notes.push(prNote);
90106
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;
96107
}
97108
}
98109
@@ -104,9 +115,12 @@ jobs:
104115
}
105116
}
106117
});
118+
119+
console.log(JSON.stringify(categorizedPRs, null, 2));
107120
108121
return categorizedPRs;
109122
123+
110124
- name: Update CHANGELOG.md
111125
uses: actions/github-script@v7
112126
with:
@@ -119,13 +133,32 @@ jobs:
119133
const changelogPath = path.resolve('CHANGELOG.md');
120134
const categorizedPRs = ${{ steps.get-categorized-prs.outputs.result }};
121135
136+
console.log(JSON.stringify(categorizedPRs, null, 2));
137+
122138
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`;
139+
for (const { title, notes, subCategories } of categorizedPRs) {
140+
const hasSubcategories = subCategories && subCategories.length > 0;
141+
const hasMainNotes = notes.length > 0;
142+
const hasSubNotes = hasSubcategories && subCategories.some(sub => sub.notes && sub.notes.length > 0);
143+
144+
if (hasMainNotes || hasSubNotes) {
145+
newReleaseNotes += `### ${title}\n\n`;
146+
}
147+
148+
if (hasMainNotes) {
149+
newReleaseNotes += `${notes.join("\n")}\n\n`;
150+
}
151+
152+
if (hasSubcategories) {
153+
for (const { title: subTitle, notes: subNotes } of subCategories) {
154+
if (subNotes && subNotes.length > 0) {
155+
newReleaseNotes += ` #### ${subTitle}\n\n`;
156+
newReleaseNotes += ` ${subNotes.join("\n ")}\n\n`;
157+
}
158+
}
126159
}
127-
}
128-
160+
}
161+
129162
const changelogContent = await fs.readFile(changelogPath, 'utf-8');
130163
const changelogIncludesTodaysReleaseNotes = changelogContent.includes(`\n## ${today}`);
131164

0 commit comments

Comments
 (0)