Skip to content

Commit

Permalink
Sync backport changelog action: Use outputs instead of env (#63792)
Browse files Browse the repository at this point in the history
* Sync backport changelog action: Use outputs instead of env

* Default empty issue body to ''

Co-authored-by: noisysocks <[email protected]>
Co-authored-by: talldan <[email protected]>
  • Loading branch information
3 people authored Jul 22, 2024
1 parent cd8d59f commit 18c5c6a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/sync-backport-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ jobs:
with:
fetch-depth: 2 # Fetch the last two commits to compare changes
- name: Check for changes in backport-changelog
id: check-for-changes
run: |
git diff --quiet HEAD^ HEAD -- backport-changelog || echo "changes=true" >> $GITHUB_OUTPUT
git diff --quiet HEAD^ HEAD -- backport-changelog || echo "HAS_CHANGES=1" >> "$GITHUB_OUTPUT"
- name: Sync Issue
if: env.changes == 'true'
if: steps.check-for-changes.outputs.HAS_CHANGES
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
Expand Down Expand Up @@ -52,18 +53,20 @@ jobs:
const endDelimiter = '<!-- END TRUNK BACKPORT CHANGELOG -->';
const autoGeneratedContent = `${startDelimiter}\n${processedChangelog}\n${endDelimiter}`;
const regex = new RegExp(`${startDelimiter}[\\s\\S]*${endDelimiter}`);
const existingBody = latestIssue.body ?? '';
let newBody;
if (regex.test(latestIssue.body)) {
const regex = new RegExp(`${startDelimiter}[\\s\\S]*${endDelimiter}`);
if (regex.test(existingBody)) {
// If delimiters exist, replace the content between them
newBody = latestIssue.body.replace(regex, autoGeneratedContent);
newBody = existingBody.replace(regex, autoGeneratedContent);
} else {
// If delimiters don't exist, append the new content at the end
newBody = `${latestIssue.body}\n\n${autoGeneratedContent}`;
newBody = `${existingBody}\n\n${autoGeneratedContent}`;
}
if (newBody.trim() !== latestIssue.body.trim()) {
if (newBody.trim() !== existingBody.trim()) {
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
Expand Down

1 comment on commit 18c5c6a

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 18c5c6a.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/10035094205
📝 Reported issues:

Please sign in to comment.