Update changelog-pr.yml

This commit is contained in:
CanbiZ 2025-02-21 10:44:54 +01:00 committed by GitHub
parent 16b8bbfca6
commit d0cd58e923
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -30,9 +30,7 @@ jobs:
- name: Get latest dates in changelog - name: Get latest dates in changelog
run: | run: |
# Extrahiere die neuesten zwei Daten aus dem Changelog
DATES=$(grep -E '^## [0-9]{4}-[0-9]{2}-[0-9]{2}' CHANGELOG.md | head -n 2 | awk '{print $2}') DATES=$(grep -E '^## [0-9]{4}-[0-9]{2}-[0-9]{2}' CHANGELOG.md | head -n 2 | awk '{print $2}')
LATEST_DATE=$(echo "$DATES" | sed -n '1p') LATEST_DATE=$(echo "$DATES" | sed -n '1p')
SECOND_LATEST_DATE=$(echo "$DATES" | sed -n '2p') SECOND_LATEST_DATE=$(echo "$DATES" | sed -n '2p')
TODAY=$(date -u +%Y-%m-%d) TODAY=$(date -u +%Y-%m-%d)
@ -86,7 +84,7 @@ jobs:
}); });
if (!pulls || pulls.length === 0) { if (!pulls || pulls.length === 0) {
console.log("⚠️ Keine gemergten PRs gefunden. Erzeuge leeres Changelog."); console.log("⚠️ Keine gemergten PRs gefunden. Setze leeres Changelog.");
core.setOutput("result", "[]"); core.setOutput("result", "[]");
return; return;
} }
@ -144,7 +142,7 @@ jobs:
}); });
core.setOutput("result", JSON.stringify(categorizedPRs.length ? categorizedPRs : [])); core.setOutput("result", JSON.stringify(categorizedPRs.length ? categorizedPRs : []));
- name: Update CHANGELOG.md - name: Update CHANGELOG.md
uses: actions/github-script@v7 uses: actions/github-script@v7
with: with:
@ -155,7 +153,11 @@ jobs:
const today = process.env.TODAY; const today = process.env.TODAY;
const latestDateInChangelog = process.env.LATEST_DATE; const latestDateInChangelog = process.env.LATEST_DATE;
const changelogPath = path.resolve('CHANGELOG.md'); const changelogPath = path.resolve('CHANGELOG.md');
const categorizedPRs = JSON.parse(process.env.RESULT); const result = `${{ steps.get-categorized-prs.outputs.result }}`.trim();
console.log("🔹 Ergebnis aus get-categorized-prs:", result);
const categorizedPRs = result && result !== "undefined" ? JSON.parse(result) : [];
let newReleaseNotes = `## ${today}\n\n### Changes\n\n`; let newReleaseNotes = `## ${today}\n\n### Changes\n\n`;
for (const { title, notes } of categorizedPRs) { for (const { title, notes } of categorizedPRs) {
@ -167,7 +169,6 @@ jobs:
const changelogContent = await fs.readFile(changelogPath, 'utf-8'); const changelogContent = await fs.readFile(changelogPath, 'utf-8');
const changelogIncludesTodaysReleaseNotes = changelogContent.includes(`\n## ${today}`); const changelogIncludesTodaysReleaseNotes = changelogContent.includes(`\n## ${today}`);
// Ersetze oder füge Release Notes ein
const regex = changelogIncludesTodaysReleaseNotes const regex = changelogIncludesTodaysReleaseNotes
? new RegExp(`## ${today}.*(?=## ${latestDateInChangelog})`, "gs") ? new RegExp(`## ${today}.*(?=## ${latestDateInChangelog})`, "gs")
: new RegExp(`(?=## ${latestDateInChangelog})`, "gs"); : new RegExp(`(?=## ${latestDateInChangelog})`, "gs");