From 82d39827ab0aea073866dac2d5b7ff9cf2e017d5 Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Tue, 17 Nov 2026 16:05:44 +0100 Subject: [PATCH] Merge only the changelog pull request the job opened (#18804) Look the pull request up among this repository's own branches and merge only the commit the job pushed. --- .github/workflows/changelog-archive.yml | 9 +++++---- .github/workflows/changelog-pr.yml | 13 +++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/changelog-archive.yml b/.github/workflows/changelog-archive.yml index e39b26f18..ac8d52df5 100644 --- a/.github/workflows/changelog-archive.yml +++ b/.github/workflows/changelog-archive.yml @@ -324,13 +324,14 @@ jobs: git commit -m "Archive old changelog entries" git checkout -b $BRANCH_NAME || git checkout $BRANCH_NAME git push origin $BRANCH_NAME --force + echo "HEAD_SHA=$(git rev-parse HEAD)" >> "$GITHUB_ENV" - name: Create pull request if not exists if: env.changed == 'true' env: GH_TOKEN: ${{ steps.generate-token.outputs.token }} run: | - PR_EXISTS=$(gh pr list --head "${BRANCH_NAME}" --json number --jq '.[].number') + PR_EXISTS=$(gh pr list --head "${BRANCH_NAME}" --state open --json number,isCrossRepository --jq '[.[] | select(.isCrossRepository == false)][0].number // empty') if [ -z "$PR_EXISTS" ]; then gh pr create --title "[Github Action] Archive old changelog entries" \ --body "This PR is auto-generated by a Github Action to archive old changelog entries (older than 14 days) to .github/changelogs/YEAR/MONTH.md" \ @@ -346,8 +347,8 @@ jobs: run: | git config --global user.name "github-actions-automege[bot]" git config --global user.email "github-actions-automege[bot]@users.noreply.github.com" - PR_NUMBER=$(gh pr list --head "${BRANCH_NAME}" --json number --jq '.[].number') + PR_NUMBER=$(gh pr list --head "${BRANCH_NAME}" --state open --json number,isCrossRepository --jq '[.[] | select(.isCrossRepository == false)][0].number // empty') if [ -n "$PR_NUMBER" ]; then - gh pr review $PR_NUMBER --approve - gh pr merge $PR_NUMBER --squash --admin + gh pr review "$PR_NUMBER" --approve + gh pr merge "$PR_NUMBER" --squash --admin --match-head-commit "$HEAD_SHA" fi diff --git a/.github/workflows/changelog-pr.yml b/.github/workflows/changelog-pr.yml index fb6667af7..19a1604c9 100644 --- a/.github/workflows/changelog-pr.yml +++ b/.github/workflows/changelog-pr.yml @@ -349,13 +349,14 @@ jobs: git commit -m "Update CHANGELOG.md" git checkout -b $BRANCH_NAME || git checkout $BRANCH_NAME git push origin $BRANCH_NAME --force + echo "HEAD_SHA=$(git rev-parse HEAD)" >> "$GITHUB_ENV" - name: Create pull request if not exists if: env.changed == 'true' env: GH_TOKEN: ${{ steps.generate-token.outputs.token }} run: | - PR_EXISTS=$(gh pr list --head "${BRANCH_NAME}" --json number --jq '.[].number') + PR_EXISTS=$(gh pr list --head "${BRANCH_NAME}" --state open --json number,isCrossRepository --jq '[.[] | select(.isCrossRepository == false)][0].number // empty') if [ -z "$PR_EXISTS" ]; then gh pr create --title "[Github Action] Update CHANGELOG.md" \ --body "This PR is auto-generated by a Github Action to update the CHANGELOG.md file." \ @@ -369,9 +370,9 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - PR_NUMBER=$(gh pr list --head "${BRANCH_NAME}" --json number --jq '.[].number') + PR_NUMBER=$(gh pr list --head "${BRANCH_NAME}" --state open --json number,isCrossRepository --jq '[.[] | select(.isCrossRepository == false)][0].number // empty') if [ -n "$PR_NUMBER" ]; then - gh pr review $PR_NUMBER --approve + gh pr review "$PR_NUMBER" --approve fi - name: Approve pull request and merge @@ -381,8 +382,8 @@ jobs: run: | git config --global user.name "github-actions-automege[bot]" git config --global user.email "github-actions-automege[bot]@users.noreply.github.com" - PR_NUMBER=$(gh pr list --head "${BRANCH_NAME}" --json number --jq '.[].number') + PR_NUMBER=$(gh pr list --head "${BRANCH_NAME}" --state open --json number,isCrossRepository --jq '[.[] | select(.isCrossRepository == false)][0].number // empty') if [ -n "$PR_NUMBER" ]; then - gh pr review $PR_NUMBER --approve - gh pr merge $PR_NUMBER --squash --admin + gh pr review "$PR_NUMBER" --approve + gh pr merge "$PR_NUMBER" --squash --admin --match-head-commit "$HEAD_SHA" fi