From 53ba423e0b4b80af3918ecfb153cea8b6349a2c5 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Tue, 12 Nov 2024 17:23:09 -0700 Subject: [PATCH 1/2] Avoid pushing workflow changes in Library.Template updates --- .github/workflows/libtemplate-update.yml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/libtemplate-update.yml b/.github/workflows/libtemplate-update.yml index b0fdd16..3c7fc94 100644 --- a/.github/workflows/libtemplate-update.yml +++ b/.github/workflows/libtemplate-update.yml @@ -43,7 +43,26 @@ jobs: exit 0 } - git -c http.extraheader="AUTHORIZATION: bearer $env:GH_TOKEN" push origin -u FETCH_HEAD:refs/heads/auto/libtemplateUpdate + # Pushing commits that add or change files under .github/workflows will cause our workflow to fail. + # But it usually isn't necessary because the target branch already has (or doesn't have) these changes. + # So if the merged doesn't bring in any changes to these files, try the merge locally and push that + # to keep github happy. + if ((git rev-list FETCH_HEAD ^HEAD --count -- .github/workflows) -eq 0) { + # Indeed there are no changes in that area. So merge locally to try to appease GitHub. + git checkout -b auto/libtemplateUpdate + git config user.name "Andrew Arnott" + git config user.email "andrewarnott@live.com" + git merge FETCH_HEAD + if ($LASTEXITCODE -ne 0) { + Write-Host "Merge conflicts prevent creating the pull request. Please run tools/MergeFrom-Template.ps1 locally and push the result as a pull request." + exit 2 + } + + git -c http.extraheader="AUTHORIZATION: bearer $env:GH_TOKEN" push origin -u HEAD + } else { + Write-Host "Changes to github workflows are included in this update. Please run tools/MergeFrom-Template.ps1 locally and push the result as a pull request." + exit 1 + } - name: pull request shell: pwsh if: success() && steps.merge.outputs.uptodate != 'true' From 77ef017a4ba024f8e5c8edf19be45d614be13128 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Tue, 12 Nov 2024 17:39:15 -0700 Subject: [PATCH 2/2] Improve placement of warning --- .github/workflows/libtemplate-update.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/libtemplate-update.yml b/.github/workflows/libtemplate-update.yml index 3c7fc94..0831ced 100644 --- a/.github/workflows/libtemplate-update.yml +++ b/.github/workflows/libtemplate-update.yml @@ -77,6 +77,8 @@ jobs: $prTitle = "Merge latest Library.Template" $prBody = "This merges the latest features and fixes from [Library.Template's branch](https://github.com/AArnott/Library.Template/tree/). + ⚠️ Do **not** squash this pull request when completing it. You must *merge* it." +
Merge conflicts? Resolve merge conflicts locally by carrying out these steps: @@ -91,8 +93,6 @@ jobs: ```
- ⚠️ Do **not** squash this pull request when completing it. You must *merge* it." - gh pr create -H auto/libtemplateUpdate -b $prBody -t $prTitle env: GH_TOKEN: ${{ github.token }}