From c8c2b62ba7570fbe95890417c9197931fae8eaa2 Mon Sep 17 00:00:00 2001 From: Jake Bayliss Date: Wed, 16 Jul 2025 15:30:43 +1000 Subject: [PATCH 1/7] Add auto-merge workflow for small content changes - 2 files or less --- .../workflows/auto-merge-content-changes.yml | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 .github/workflows/auto-merge-content-changes.yml diff --git a/.github/workflows/auto-merge-content-changes.yml b/.github/workflows/auto-merge-content-changes.yml new file mode 100644 index 0000000000..865fc638fd --- /dev/null +++ b/.github/workflows/auto-merge-content-changes.yml @@ -0,0 +1,122 @@ +name: Auto-Merge Small Changes + +on: + pull_request: + types: [ready_for_review] + paths: + - 'content/**' + - 'public/**' + +concurrency: + group: auto-merge-${{ github.event.number }} + cancel-in-progress: true + +defaults: + run: + shell: pwsh + +jobs: + detect-small-changes: + name: Detect Small Changes + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + outputs: + is-small-change: ${{ steps.analyse-changes.outputs.is-small-change }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Analyse changes + id: analyse-changes + shell: pwsh + run: | + # Get the base branch + $baseBranch = "${{ github.base_ref }}" + if ([string]::IsNullOrEmpty($baseBranch)) { + $baseBranch = "main" + } + + $maxFiles = 2 + $changedFiles = git diff --name-only origin/$baseBranch...HEAD + $contentFiles = $changedFiles | Where-Object { $_ -like "content/*" } + $nonContentFiles = $changedFiles | Where-Object { $_ -notlike "content/*" } + $isContentOnly = $contentFiles.Count -gt 0 -and $nonContentFiles.Count -eq 0 + $isSmallChange = $isContentOnly -and $changedFiles.Count -le $maxFiles + + # Debug output + Write-Host "Changed files: $($changedFiles -join ', ')" + Write-Host "Content files: $($contentFiles -join ', ')" + Write-Host "Non-content files: $($nonContentFiles -join ', ')" + Write-Host "Is content only: $isContentOnly" + Write-Host "Is small change: $isSmallChange" + + echo "is-small-change=$($isSmallChange.ToString().ToLower())" >> $env:GITHUB_OUTPUT + + - name: Comment analysis on PR + uses: mshick/add-pr-comment@v2 + with: + message: | + 🤖 **Small Change Analysis** + + **Result:** ${{ steps.analyse-changes.outputs.is-small-change == 'true' && '✅ Eligible for auto-merge' || '❌ Not eligible for auto-merge' }} + + This PR has been analyzed for auto-merge eligibility based on: + - Content-only changes + - Maximum ${{ $maxFiles }} file changed + repo-token: ${{ secrets.GITHUB_TOKEN }} + allow-repeats: true + + auto-merge: + name: Auto-Merge Small Changes + needs: detect-small-changes + if: needs.detect-small-changes.outputs.is-small-change == 'true' + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: + - name: Auto-merge PR + id: auto-merge-pr + uses: actions/github-script@v7 + with: + script: | + try { + const pr = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number + }); + + if (!pr.data.mergeable) { + throw new Error('PR is not mergeable. It may have conflicts or not be up to date.'); + } + + const result = await github.rest.pulls.merge({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number, + merge_method: 'squash', + commit_title: `Auto-merge: ${{ github.event.pull_request.title }}`, + commit_message: `🤖 Auto-merged small content change\n\n- PR: #${{ github.event.number }}` + }); + + console.log('Auto-merge successful:', result.data.message); + } catch (error) { + console.error('Auto-merge failed:', error.message); + core.setFailed(`Auto-merge failed: ${error.message}`); + } + + - name: Comment merge result + uses: mshick/add-pr-comment@v2 + if: always() + with: + message: | + ${{ steps.auto-merge-pr.outcome == 'success' && '✅ **Auto-merge completed successfully!**' || '❌ **Auto-merge failed** - Please check the workflow logs for details.' }} + + This PR was automatically merged as a small content change. + repo-token: ${{ secrets.GITHUB_TOKEN }} + allow-repeats: true \ No newline at end of file From 0ecd82276213cae30c14ea7f00eb46ea468c1f0a Mon Sep 17 00:00:00 2001 From: Jake Bayliss Date: Wed, 16 Jul 2025 15:37:20 +1000 Subject: [PATCH 2/7] Update workflow --- .github/workflows/auto-merge-content-changes.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-merge-content-changes.yml b/.github/workflows/auto-merge-content-changes.yml index 865fc638fd..79be0d9652 100644 --- a/.github/workflows/auto-merge-content-changes.yml +++ b/.github/workflows/auto-merge-content-changes.yml @@ -66,7 +66,7 @@ jobs: This PR has been analyzed for auto-merge eligibility based on: - Content-only changes - - Maximum ${{ $maxFiles }} file changed + - Maximum 2 files changed repo-token: ${{ secrets.GITHUB_TOKEN }} allow-repeats: true From 3971eea00ae69e02177f487c7ae64905242f258a Mon Sep 17 00:00:00 2001 From: Jake Bayliss Date: Wed, 16 Jul 2025 15:41:55 +1000 Subject: [PATCH 3/7] Include public folder in auto-merge --- .github/workflows/auto-merge-content-changes.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/auto-merge-content-changes.yml b/.github/workflows/auto-merge-content-changes.yml index 79be0d9652..2045f25a34 100644 --- a/.github/workflows/auto-merge-content-changes.yml +++ b/.github/workflows/auto-merge-content-changes.yml @@ -42,8 +42,8 @@ jobs: $maxFiles = 2 $changedFiles = git diff --name-only origin/$baseBranch...HEAD - $contentFiles = $changedFiles | Where-Object { $_ -like "content/*" } - $nonContentFiles = $changedFiles | Where-Object { $_ -notlike "content/*" } + $contentFiles = $changedFiles | Where-Object { $_ -like "content/*" -or $_ -like "public/*" } + $nonContentFiles = $changedFiles | Where-Object { $_ -notlike "content/*" -and $_ -notlike "public/*" } $isContentOnly = $contentFiles.Count -gt 0 -and $nonContentFiles.Count -eq 0 $isSmallChange = $isContentOnly -and $changedFiles.Count -le $maxFiles @@ -66,7 +66,7 @@ jobs: This PR has been analyzed for auto-merge eligibility based on: - Content-only changes - - Maximum 2 files changed + - Maximum ${{ $maxFiles }} file changed repo-token: ${{ secrets.GITHUB_TOKEN }} allow-repeats: true From 56231f73582c2e6496fa9cc48ada1086717bfef8 Mon Sep 17 00:00:00 2001 From: "Matt Wicks [SSW]" Date: Wed, 10 Dec 2025 10:42:31 +1100 Subject: [PATCH 4/7] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/workflows/auto-merge-content-changes.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-merge-content-changes.yml b/.github/workflows/auto-merge-content-changes.yml index 2045f25a34..20e1121a87 100644 --- a/.github/workflows/auto-merge-content-changes.yml +++ b/.github/workflows/auto-merge-content-changes.yml @@ -66,7 +66,7 @@ jobs: This PR has been analyzed for auto-merge eligibility based on: - Content-only changes - - Maximum ${{ $maxFiles }} file changed + - Maximum ${{ $maxFiles }} file${{ $maxFiles > 1 && 's' || '' }} changed repo-token: ${{ secrets.GITHUB_TOKEN }} allow-repeats: true From 92ef173cce62152f89f6fb0ee1071942fefae5b8 Mon Sep 17 00:00:00 2001 From: "Matt Wicks [SSW]" Date: Wed, 10 Dec 2025 10:42:56 +1100 Subject: [PATCH 5/7] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/workflows/auto-merge-content-changes.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/auto-merge-content-changes.yml b/.github/workflows/auto-merge-content-changes.yml index 20e1121a87..476719c478 100644 --- a/.github/workflows/auto-merge-content-changes.yml +++ b/.github/workflows/auto-merge-content-changes.yml @@ -91,8 +91,8 @@ jobs: pull_number: context.issue.number }); - if (!pr.data.mergeable) { - throw new Error('PR is not mergeable. It may have conflicts or not be up to date.'); + if (pr.data.mergeable !== true) { + throw new Error('PR is not mergeable or its mergeability status is indeterminate. It may have conflicts, not be up to date, or still be computing mergeability.'); } const result = await github.rest.pulls.merge({ @@ -119,4 +119,4 @@ jobs: This PR was automatically merged as a small content change. repo-token: ${{ secrets.GITHUB_TOKEN }} - allow-repeats: true \ No newline at end of file + allow-repeats: true \ No newline at end of file From da386dc02c2e7d19160d8d9dd49be55c06d7b1ae Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Wed, 10 Dec 2025 10:51:29 +1100 Subject: [PATCH 6/7] Extract maxFiles to job-level environment variable (#4378) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses review feedback to extract the `maxFiles` PowerShell variable to a job-level environment variable, making it properly accessible throughout the workflow. **Changes:** - Added `MAX_FILES: 2` as job-level environment variable in `detect-small-changes` job - Updated PowerShell script to read from `$env:MAX_FILES` instead of hardcoded value - Fixed comment step to use `${{ env.MAX_FILES }}` (previously referenced undefined `$maxFiles` in GitHub Actions context) - Exposed as job output for potential cross-job usage **Before:** ```yaml run: | $maxFiles = 2 # ...later in different step message: | - Maximum ${{ $maxFiles }} file... # ❌ undefined in Actions context ``` **After:** ```yaml env: MAX_FILES: 2 outputs: max-files: ${{ env.MAX_FILES }} steps: run: | $maxFiles = [int]$env:MAX_FILES # ...later in different step message: | - Maximum ${{ env.MAX_FILES }} file... # ✅ properly scoped ``` - Affected routes: N/A (GitHub Actions workflow only) - [ ] If adding a new page, I have followed the [📃 New Webpage](https://github.com/SSWConsulting/SSW.Website/issues/new?assignees=&labels=&projects=&template=new_webpage.yml&title=%F0%9F%93%84+%7B%7B+TITLE+%7D%7D+) issue template - [ ] If updating the livestream banner, I have tested and followed the steps in [Wiki - Testing the live banner](https://github.com/SSWConsulting/SSW.Website/wiki/Testing-the-live-banner) - [ ] Include Done Video or screenshots --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey). --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: wicksipedia <600044+wicksipedia@users.noreply.github.com> --- .github/workflows/auto-merge-content-changes.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/auto-merge-content-changes.yml b/.github/workflows/auto-merge-content-changes.yml index 476719c478..51fbc22de3 100644 --- a/.github/workflows/auto-merge-content-changes.yml +++ b/.github/workflows/auto-merge-content-changes.yml @@ -22,8 +22,11 @@ jobs: permissions: contents: read pull-requests: write + env: + MAX_FILES: 2 outputs: is-small-change: ${{ steps.analyse-changes.outputs.is-small-change }} + max-files: ${{ env.MAX_FILES }} steps: - name: Checkout repository uses: actions/checkout@v4 @@ -40,7 +43,7 @@ jobs: $baseBranch = "main" } - $maxFiles = 2 + $maxFiles = [int]$env:MAX_FILES $changedFiles = git diff --name-only origin/$baseBranch...HEAD $contentFiles = $changedFiles | Where-Object { $_ -like "content/*" -or $_ -like "public/*" } $nonContentFiles = $changedFiles | Where-Object { $_ -notlike "content/*" -and $_ -notlike "public/*" } @@ -66,7 +69,7 @@ jobs: This PR has been analyzed for auto-merge eligibility based on: - Content-only changes - - Maximum ${{ $maxFiles }} file${{ $maxFiles > 1 && 's' || '' }} changed + - Maximum ${{ env.MAX_FILES }} file${{ env.MAX_FILES > 1 && 's' || '' }} changed repo-token: ${{ secrets.GITHUB_TOKEN }} allow-repeats: true From e992bc80d25fd2b5c3c31d712e3e427af9a2c4d1 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Wed, 10 Dec 2025 10:59:59 +1100 Subject: [PATCH 7/7] Move auto-merge comments to separate job for reliable failure reporting (#4379) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Restructured the auto-merge workflow to ensure comments are posted reliably in all scenarios, including when the merge step fails with an exception. **Changes:** - Created a new `comment-result` job that runs separately from the `auto-merge` job - Job uses `if: always()` to ensure it runs even when the auto-merge job fails - Split comments into two conditional steps based on `needs.auto-merge.result`: - `Comment merge success` - Runs only when merge succeeds, includes "This PR was automatically merged as a small content change." - `Comment merge failure` - Runs only when merge fails, shows error message only **Before:** ```yaml # Comments were steps within the auto-merge job - name: Comment merge result if: always() with: message: | ${{ steps.auto-merge-pr.outcome == 'success' && '✅ **Auto-merge completed successfully!**' || '❌ **Auto-merge failed**' }} This PR was automatically merged as a small content change. ``` **After:** ```yaml # Comments are now in a separate job that acts as a catch-all comment-result: name: Comment Merge Result needs: [detect-small-changes, auto-merge] if: always() && needs.detect-small-changes.outputs.is-small-change == 'true' steps: - name: Comment merge success if: needs.auto-merge.result == 'success' with: message: | ✅ **Auto-merge completed successfully!** This PR was automatically merged as a small content change. - name: Comment merge failure if: needs.auto-merge.result == 'failure' with: message: | ❌ **Auto-merge failed** - Please check the workflow logs for details. ``` **Benefits:** - Failure comments now post even if the auto-merge job encounters an exception - Better separation of concerns between merging and status reporting - More reliable feedback to PR authors in all scenarios - Affected routes: N/A (workflow change only) - [ ] If adding a new page, I have followed the [📃 New Webpage](https://github.com/SSWConsulting/SSW.Website/issues/new?assignees=&labels=&projects=&template=new_webpage.yml&title=%F0%9F%93%84+%7B%7B+TITLE+%7D%7D+) issue template - [ ] If updating the livestream banner, I have tested and followed the steps in [Wiki - Testing the live banner](https://github.com/SSWConsulting/SSW.Website/wiki/Testing-the-live-banner) - [ ] Include Done Video or screenshots --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey). --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: wicksipedia <600044+wicksipedia@users.noreply.github.com> --- .../workflows/auto-merge-content-changes.yml | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/workflows/auto-merge-content-changes.yml b/.github/workflows/auto-merge-content-changes.yml index 51fbc22de3..4617746174 100644 --- a/.github/workflows/auto-merge-content-changes.yml +++ b/.github/workflows/auto-merge-content-changes.yml @@ -113,13 +113,30 @@ jobs: core.setFailed(`Auto-merge failed: ${error.message}`); } - - name: Comment merge result + comment-result: + name: Comment Merge Result + needs: [detect-small-changes, auto-merge] + if: always() && needs.detect-small-changes.outputs.is-small-change == 'true' + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - name: Comment merge success uses: mshick/add-pr-comment@v2 - if: always() + if: needs.auto-merge.result == 'success' with: message: | - ${{ steps.auto-merge-pr.outcome == 'success' && '✅ **Auto-merge completed successfully!**' || '❌ **Auto-merge failed** - Please check the workflow logs for details.' }} + ✅ **Auto-merge completed successfully!** This PR was automatically merged as a small content change. repo-token: ${{ secrets.GITHUB_TOKEN }} - allow-repeats: true \ No newline at end of file + allow-repeats: true + + - name: Comment merge failure + uses: mshick/add-pr-comment@v2 + if: needs.auto-merge.result == 'failure' + with: + message: | + ❌ **Auto-merge failed** - Please check the workflow logs for details. + repo-token: ${{ secrets.GITHUB_TOKEN }} + allow-repeats: true