mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2025-03-08 13:19:05 +00:00
Update changelog-pr.yml
This commit is contained in:
parent
7105f67145
commit
9756ac639b
36
.github/workflows/changelog-pr.yml
vendored
36
.github/workflows/changelog-pr.yml
vendored
@ -6,7 +6,7 @@ on:
|
|||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
update-changelog:
|
update-changelog-pull-request:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
CONFIG_PATH: .github/changelog-pr-config.json
|
CONFIG_PATH: .github/changelog-pr-config.json
|
||||||
@ -28,12 +28,21 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Get latest date in changelog
|
- name: Get latest dates in changelog
|
||||||
run: |
|
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)
|
TODAY=$(date -u +%Y-%m-%d)
|
||||||
echo "LATEST_DATE=$LATEST_DATE" >> $GITHUB_ENV
|
|
||||||
echo "TODAY=$TODAY" >> $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
|
- name: Get categorized pull requests
|
||||||
id: get-categorized-prs
|
id: get-categorized-prs
|
||||||
@ -46,10 +55,10 @@ jobs:
|
|||||||
const configPath = path.resolve(process.env.CONFIG_PATH);
|
const configPath = path.resolve(process.env.CONFIG_PATH);
|
||||||
const fileContent = await fs.readFile(configPath, 'utf-8');
|
const fileContent = await fs.readFile(configPath, 'utf-8');
|
||||||
const changelogConfig = JSON.parse(fileContent);
|
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);
|
const latestDateInChangelog = new Date(process.env.LATEST_DATE);
|
||||||
latestDate.setUTCHours(23,59,59,999);
|
latestDateInChangelog.setUTCHours(23, 59, 59, 999);
|
||||||
|
|
||||||
const { data: pulls } = await github.rest.pulls.list({
|
const { data: pulls } = await github.rest.pulls.list({
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
@ -63,7 +72,7 @@ jobs:
|
|||||||
|
|
||||||
pulls.filter(pr =>
|
pulls.filter(pr =>
|
||||||
pr.merged_at &&
|
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()))
|
!pr.labels.some(label => ["invalid", "wontdo", process.env.AUTOMATED_PR_LABEL].includes(label.name.toLowerCase()))
|
||||||
).forEach(pr => {
|
).forEach(pr => {
|
||||||
const prLabels = pr.labels.map(label => label.name.toLowerCase());
|
const prLabels = pr.labels.map(label => label.name.toLowerCase());
|
||||||
@ -87,11 +96,11 @@ jobs:
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const today = process.env.TODAY;
|
const today = process.env.TODAY;
|
||||||
const latestDate = process.env.LATEST_DATE;
|
const latestDateInChangelog = process.env.LATEST_DATE;
|
||||||
const changelogPath = path.resolve('CHANGELOG.md');
|
const changelogPath = path.resolve('CHANGELOG.md');
|
||||||
const categorizedPRs = ${{ steps.get-categorized-prs.outputs.result }};
|
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) {
|
for (const { title, notes } of categorizedPRs) {
|
||||||
if (notes.length > 0) {
|
if (notes.length > 0) {
|
||||||
newReleaseNotes += `### ${title}\n\n${notes.join("\n")}\n\n`;
|
newReleaseNotes += `### ${title}\n\n${notes.join("\n")}\n\n`;
|
||||||
@ -101,9 +110,10 @@ 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}`);
|
||||||
|
|
||||||
const regex = changelogIncludesTodaysReleaseNotes ?
|
// Ersetze oder füge Release Notes ein
|
||||||
new RegExp(`## ${today}.*(?=## ${latestDate})`, "gs") :
|
const regex = changelogIncludesTodaysReleaseNotes
|
||||||
new RegExp(`(?=## ${latestDate})`, "gs");
|
? new RegExp(`## ${today}.*(?=## ${latestDateInChangelog})`, "gs")
|
||||||
|
: new RegExp(`(?=## ${latestDateInChangelog})`, "gs");
|
||||||
|
|
||||||
const newChangelogContent = changelogContent.replace(regex, newReleaseNotes);
|
const newChangelogContent = changelogContent.replace(regex, newReleaseNotes);
|
||||||
await fs.writeFile(changelogPath, newChangelogContent);
|
await fs.writeFile(changelogPath, newChangelogContent);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user