1- name : Library.Template update
1+ name : ⛜ Library.Template update
22
3- # PREREQUISITE: This workflow requires the repo to be configured to allow workflows to push commits and create pull requests.
3+ # PREREQUISITE: This workflow requires the repo to be configured to allow workflows to create pull requests.
44# Visit https://github.com/USER/REPO/settings/actions
5- # Under "Workflow permissions", select "Read and write permissions" and check "Allow GitHub Actions to create ...pull requests"
5+ # Under "Workflow permissions" check "Allow GitHub Actions to create ...pull requests"
66# Click Save.
77
88on :
1313jobs :
1414 merge :
1515 runs-on : ubuntu-latest
16+ permissions :
17+ contents : write
18+ pull-requests : write
1619 steps :
1720 - uses : actions/checkout@v4
1821 with :
1922 fetch-depth : 0 # avoid shallow clone so nbgv can do its work.
2023
2124 - name : merge
25+ id : merge
2226 shell : pwsh
2327 run : |
24- $LibTemplateBranch = & ./azure-pipelines /Get-LibTemplateBasis.ps1 -ErrorIfNotRelated
28+ $LibTemplateBranch = & ./tools /Get-LibTemplateBasis.ps1 -ErrorIfNotRelated
2529 if ($LASTEXITCODE -ne 0) {
2630 exit $LASTEXITCODE
2731 }
@@ -31,15 +35,37 @@ jobs:
3135 exit $LASTEXITCODE
3236 }
3337 $LibTemplateCommit = git rev-parse FETCH_HEAD
38+ git diff --stat ...FETCH_HEAD
3439
3540 if ((git rev-list FETCH_HEAD ^HEAD --count) -eq 0) {
3641 Write-Host "There are no Library.Template updates to merge."
42+ echo "uptodate=true" >> $env:GITHUB_OUTPUT
3743 exit 0
3844 }
3945
40- git -c http.extraheader="AUTHORIZATION: bearer $env:GH_TOKEN" push origin -u FETCH_HEAD:refs/heads/auto/libtemplateUpdate
46+ # Pushing commits that add or change files under .github/workflows will cause our workflow to fail.
47+ # But it usually isn't necessary because the target branch already has (or doesn't have) these changes.
48+ # So if the merged doesn't bring in any changes to these files, try the merge locally and push that
49+ # to keep github happy.
50+ if ((git rev-list FETCH_HEAD ^HEAD --count -- .github/workflows) -eq 0) {
51+ # Indeed there are no changes in that area. So merge locally to try to appease GitHub.
52+ git checkout -b auto/libtemplateUpdate
53+ git config user.name "Andrew Arnott"
54+ git config user.email "[email protected] " 55+ git merge FETCH_HEAD
56+ if ($LASTEXITCODE -ne 0) {
57+ Write-Host "Merge conflicts prevent creating the pull request. Please run tools/MergeFrom-Template.ps1 locally and push the result as a pull request."
58+ exit 2
59+ }
60+
61+ git -c http.extraheader="AUTHORIZATION: bearer $env:GH_TOKEN" push origin -u HEAD
62+ } else {
63+ 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."
64+ exit 1
65+ }
4166 - name : pull request
4267 shell : pwsh
68+ if : success() && steps.merge.outputs.uptodate != 'true'
4369 run : |
4470 # If there is already an active pull request, don't create a new one.
4571 $existingPR = gh pr list -H auto/libtemplateUpdate --json url | ConvertFrom-Json
5177 $prTitle = "Merge latest Library.Template"
5278 $prBody = "This merges the latest features and fixes from [Library.Template's branch](https://github.com/AArnott/Library.Template/tree/).
5379
80+ ⚠️ Do **not** squash this pull request when completing it. You must *merge* it.
81+
5482 <details>
5583 <summary>Merge conflicts?</summary>
5684 Resolve merge conflicts locally by carrying out these steps:
6391 git commit
6492 git push
6593 ```
66- </details>
67-
68- ⚠️ Do **not** squash this pull request when completing it. You must *merge* it."
94+ </details>"
6995
7096 gh pr create -H auto/libtemplateUpdate -b $prBody -t $prTitle
7197 env :
0 commit comments