diff --git a/.github/workflows/check-branches.yml b/.github/workflows/check-branches.yml index 7daef09..aba6034 100644 --- a/.github/workflows/check-branches.yml +++ b/.github/workflows/check-branches.yml @@ -401,6 +401,9 @@ jobs: if [ "$EXISTING" = "$GENERATED" ]; then echo "Fix branch already contains identical changes — skipping push to preserve PR approvals." echo "pushed=false" >> "$GITHUB_OUTPUT" + echo "branch_ready=true" >> "$GITHUB_OUTPUT" + echo "fix_branch=$FIX_BRANCH" >> "$GITHUB_OUTPUT" + echo "base_branch=$BASE_BRANCH" >> "$GITHUB_OUTPUT" exit 0 fi fi @@ -424,11 +427,12 @@ jobs: echo "base_branch=$BASE_BRANCH" >> "$GITHUB_OUTPUT" - name: Create or update fix PR - if: steps.push.outputs.pushed == 'true' + if: steps.push.outputs.pushed == 'true' || steps.push.outputs.branch_ready == 'true' uses: actions/github-script@v7 env: FIX_BRANCH: ${{ steps.push.outputs.fix_branch }} BASE_BRANCH: ${{ steps.push.outputs.base_branch }} + PUSHED: ${{ steps.push.outputs.pushed }} with: github-token: ${{ secrets.PGEDGE_BUILDER_TOKEN }} script: | @@ -436,6 +440,7 @@ jobs: const body = fs.readFileSync('/tmp/drift-report.md', 'utf8'); const fixBranch = process.env.FIX_BRANCH; const baseBranch = process.env.BASE_BRANCH; + const pushed = process.env.PUSHED === 'true'; const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/'); const { data: prs } = await github.rest.pulls.list({ @@ -445,13 +450,18 @@ jobs: }); if (prs.length > 0) { - const prNumber = prs[0].number; - console.log(`Updating existing PR #${prNumber}`); - await github.rest.issues.createComment({ - owner, repo, - issue_number: prNumber, - body, - }); + if (pushed) { + // New content was pushed — update the PR body to reflect latest drift + const prNumber = prs[0].number; + console.log(`Updating PR #${prNumber} body`); + await github.rest.pulls.update({ + owner, repo, + pull_number: prNumber, + body, + }); + } else { + console.log(`PR already open and branch unchanged — no update needed`); + } } else { console.log('Creating new fix PR'); await github.rest.pulls.create({