Update changelog-pr.yml

This commit is contained in:
CanbiZ 2025-02-10 14:47:38 +01:00 committed by GitHub
parent 7105f67145
commit 9756ac639b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,7 +6,7 @@ on:
workflow_dispatch:
jobs:
update-changelog:
update-changelog-pull-request:
runs-on: ubuntu-latest
env:
CONFIG_PATH: .github/changelog-pr-config.json
@ -28,12 +28,21 @@ jobs:
with:
fetch-depth: 0
- name: Get latest date in changelog
- name: Get latest dates in changelog
run: |
LATEST_DATE=$(grep '^## [0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}' CHANGELOG.md | head -n 1 | awk '{print $2}')
# 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)
echo "LATEST_DATE=$LATEST_DATE" >> $GITHUB_ENV
echo "TODAY=$TODAY" >> $GITHUB_ENV
if [[ "$LATEST_DATE" == "$TODAY" ]]; then
echo "LATEST_DATE=$SECOND_LATEST_DATE" >> $GITHUB_ENV
else
echo "LATEST_DATE=$LATEST_DATE" >> $GITHUB_ENV
fi
- name: Get categorized pull requests
id: get-categorized-prs
@ -46,10 +55,10 @@ jobs:
const configPath = path.resolve(process.env.CONFIG_PATH);
const fileContent = await fs.readFile(configPath, 'utf-8');
const changelogConfig = JSON.parse(fileContent);
const categorizedPRs = changelogConfig.map((obj) => ({ ...obj, notes: [] }));
const categorizedPRs = changelogConfig.map(obj => ({ ...obj, notes: [] }));
const latestDate = new Date(process.env.LATEST_DATE);
latestDate.setUTCHours(23,59,59,999);
const latestDateInChangelog = new Date(process.env.LATEST_DATE);
latestDateInChangelog.setUTCHours(23, 59, 59, 999);
const { data: pulls } = await github.rest.pulls.list({
owner: context.repo.owner,
@ -63,7 +72,7 @@ jobs:
pulls.filter(pr =>
pr.merged_at &&
new Date(pr.merged_at) > latestDate &&
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());
@ -87,11 +96,11 @@ jobs:
const path = require('path');
const today = process.env.TODAY;
const latestDate = process.env.LATEST_DATE;
const latestDateInChangelog = process.env.LATEST_DATE;
const changelogPath = path.resolve('CHANGELOG.md');
const categorizedPRs = ${{ steps.get-categorized-prs.outputs.result }};
let newReleaseNotes = `## ${today}\n\n`;
let newReleaseNotes = `## ${today}\n\n### Changes\n\n`;
for (const { title, notes } of categorizedPRs) {
if (notes.length > 0) {
newReleaseNotes += `### ${title}\n\n${notes.join("\n")}\n\n`;
@ -101,9 +110,10 @@ jobs:
const changelogContent = await fs.readFile(changelogPath, 'utf-8');
const changelogIncludesTodaysReleaseNotes = changelogContent.includes(`\n## ${today}`);
const regex = changelogIncludesTodaysReleaseNotes ?
new RegExp(`## ${today}.*(?=## ${latestDate})`, "gs") :
new RegExp(`(?=## ${latestDate})`, "gs");
// Ersetze oder füge Release Notes ein
const regex = changelogIncludesTodaysReleaseNotes
? new RegExp(`## ${today}.*(?=## ${latestDateInChangelog})`, "gs")
: new RegExp(`(?=## ${latestDateInChangelog})`, "gs");
const newChangelogContent = changelogContent.replace(regex, newReleaseNotes);
await fs.writeFile(changelogPath, newChangelogContent);