Skip to content

Commit

Permalink
Leave existing content intact
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jun 28, 2024
1 parent 8593f04 commit 1224442
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check-backport-changelog.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Check Core Backport Changlog
name: Verify Core Backport Changlog

on:
pull_request:
Expand All @@ -17,7 +17,7 @@ on:
- '!packages/block-library/**'
- '!packages/e2e-tests/**'
jobs:
check-backport-changelog:
check:
name: Check for a Core backport changelog entry
runs-on: ubuntu-latest
if: ${{ !contains(github.event.pull_request.labels.*.name, 'No Core Sync Required') && !contains(github.event.pull_request.labels.*.name, 'Backport from WordPress Core') }}
Expand Down
26 changes: 18 additions & 8 deletions .github/workflows/sync-backport-changelog.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Sync Core Backport Changelog Issue
name: Sync Core Backport Issue

on:
push:
Expand All @@ -7,11 +7,10 @@ on:

jobs:
sync-backport-changelog:
name: Sync Core Backport Changelog Issue
name: Sync Core Backport Issue
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Sync Issue
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
Expand Down Expand Up @@ -43,16 +42,27 @@ jobs:
const { execSync } = require('child_process');
const processedChangelog = execSync(`awk '/./ {print ($0 ~ /^[-*]/ ? " " : "- ") $0}' backport-changelog/${version}/*.md`).toString().trim();
const prependChangelog = `This description is continuously generated by a script. Please do not edit, leave comments instead.\n\n`;
const body = prependChangelog + processedChangelog;
const startDelimiter = '<!-- START TRUNK BACKPORT CHANGELOG -->';
const endDelimiter = '<!-- END TRUNK BACKPORT CHANGELOG -->';
const autoGeneratedContent = `${startDelimiter}\n${processedChangelog}\n${endDelimiter}`;
const regex = new RegExp(`${startDelimiter}[\\s\\S]*${endDelimiter}`);
let newBody;
if (regex.test(latestIssue.body)) {
// If delimiters exist, replace the content between them
newBody = latestIssue.body.replace(regex, autoGeneratedContent);
} else {
// If delimiters don't exist, append the new content at the end
newBody = `${latestIssue.body}\n\n${autoGeneratedContent}`;
}
if (latestIssue.body.trim() !== body.trim()) {
console.log(processedChangelog);
if (newBody.trim() !== latestIssue.body.trim()) {
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: latestIssue.number,
body
body: newBody
});
console.log('Issue description updated successfully.');
} else {
Expand Down

0 comments on commit 1224442

Please sign in to comment.