diff --git a/.github/workflows/changelog-pr.yml b/.github/workflows/changelog-pr.yml index 5d49254d..19e9a70e 100644 --- a/.github/workflows/changelog-pr.yml +++ b/.github/workflows/changelog-pr.yml @@ -30,7 +30,9 @@ jobs: - name: Get latest dates in changelog 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}') + LATEST_DATE=$(echo "$DATES" | sed -n '1p') SECOND_LATEST_DATE=$(echo "$DATES" | sed -n '2p') TODAY=$(date -u +%Y-%m-%d) @@ -42,7 +44,7 @@ jobs: echo "LATEST_DATE=$LATEST_DATE" >> $GITHUB_ENV fi - - name: Get categorized pull requests (including PR template selections) + - name: Get categorized pull requests id: get-categorized-prs uses: actions/github-script@v7 with: @@ -52,22 +54,7 @@ jobs: const configPath = path.resolve(process.env.CONFIG_PATH); const fileContent = await fs.readFile(configPath, 'utf-8'); - let changelogConfig = JSON.parse(fileContent); - - const order = [ - "๐Ÿ’ฅ Breaking Changes", - "๐Ÿ†• New Scripts", - "๐Ÿš€ Updated Scripts", - "๐Ÿž Bug Fixes (Updated Scripts)", - "โœจ Feature Updates (Updated Scripts)", - "โœจ New Features", - "๐ŸŒ Website", - "๐Ÿ“ก API", - "๐Ÿงฐ Maintenance", - "โ” Unlabelled" - ]; - changelogConfig = changelogConfig.sort((a, b) => order.indexOf(a.title) - order.indexOf(b.title)); - + const changelogConfig = JSON.parse(fileContent); const categorizedPRs = changelogConfig.map(obj => ({ ...obj, notes: [] })); const latestDateInChangelog = new Date(process.env.LATEST_DATE); @@ -83,65 +70,23 @@ jobs: per_page: 100, }); - if (!pulls || pulls.length === 0) { - console.log("โš ๏ธ Keine gemergten PRs gefunden. Setze leeres Changelog."); - core.setOutput("result", "[]"); - return; - } - pulls.filter(pr => pr.merged_at && new Date(pr.merged_at) > latestDateInChangelog && !pr.labels.some(label => ["invalid", "wontdo", process.env.AUTOMATED_PR_LABEL].includes(label.name.toLowerCase())) ).forEach(pr => { const prLabels = pr.labels.map(label => label.name.toLowerCase()); - const prBody = pr.body ? pr.body.toLowerCase() : ""; const prNote = `- ${pr.title} [@${pr.user.login}](https://github.com/${pr.user.login}) ([#${pr.number}](${pr.html_url}))`; - const templateLabelMappings = { - "๐Ÿž bug fix": "bugfix", - "โœจ new feature": "feature", - "๐Ÿ’ฅ breaking change": "breaking change", - "๐Ÿ†• new script": "new script" - }; - - let addedByTemplate = false; - for (const [checkbox, label] of Object.entries(templateLabelMappings)) { - const regex = new RegExp(`- \\[(.*?)\\] ${checkbox}`, "i"); - const match = prBody.match(regex); - if (match && match[1].trim() !== "") { - prLabels.push(label); - addedByTemplate = true; - } - } - - let categorized = false; - for (const { labels, notes, title } of categorizedPRs) { - if (labels.includes("update script") && labels.includes("bugfix")) { - if (title === "๐Ÿž Bug Fixes (Updated Scripts)") { - notes.push(prNote); - categorized = true; - break; - } - } else if (labels.includes("update script") && labels.includes("feature")) { - if (title === "โœจ Feature Updates (Updated Scripts)") { - notes.push(prNote); - categorized = true; - break; - } - } else if (labels.length === 0 || labels.some(label => prLabels.includes(label))) { + for (const { labels, notes } of categorizedPRs) { + if (labels.length === 0 || labels.some(label => prLabels.includes(label))) { notes.push(prNote); - categorized = true; break; } } - - if (addedByTemplate) { - console.log(`PR #${pr.number} wurde durch PR-Template-Kategorie hinzugefรผgt.`); - } }); - core.setOutput("result", JSON.stringify(categorizedPRs.length ? categorizedPRs : [])); + return categorizedPRs; - name: Update CHANGELOG.md uses: actions/github-script@v7 @@ -153,11 +98,7 @@ jobs: const today = process.env.TODAY; const latestDateInChangelog = process.env.LATEST_DATE; const changelogPath = path.resolve('CHANGELOG.md'); - 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) : []; + const categorizedPRs = ${{ steps.get-categorized-prs.outputs.result }}; let newReleaseNotes = `## ${today}\n\n### Changes\n\n`; for (const { title, notes } of categorizedPRs) { @@ -169,6 +110,7 @@ jobs: const changelogContent = await fs.readFile(changelogPath, 'utf-8'); const changelogIncludesTodaysReleaseNotes = changelogContent.includes(`\n## ${today}`); + // Ersetze oder fรผge Release Notes ein const regex = changelogIncludesTodaysReleaseNotes ? new RegExp(`## ${today}.*(?=## ${latestDateInChangelog})`, "gs") : new RegExp(`(?=## ${latestDateInChangelog})`, "gs");