1
1
name : Update from Template
2
2
3
3
# This workflow keeps the repo up to date with changes from the template repo (REMOTE_URL)
4
- # It duplicates the REMOTE_BRANCH (into UPDATE_BRANCH) and tries to merge it into the
4
+ # It duplicates the REMOTE_BRANCH (into UPDATE_BRANCH) and tries to merge it into
5
5
# this repos default branch (which is checked out here)
6
6
# Note that this requires a PAT (Personal Access Token) - at best from a servicing account
7
+ # PAT permissions: read:discussion, read:org, repo, workflow
7
8
# Also note that you should have at least once merged the template repo into the current repo manually
8
9
# otherwise a "refusing to merge unrelated histories" error might occur.
9
10
@@ -135,8 +136,9 @@ jobs:
135
136
136
137
echo "create_update_branch_pr=0" >> $GITHUB_OUTPUT
137
138
echo "create_update_branch_merged_pr=1" >> $GITHUB_OUTPUT
139
+ echo "try_close_update_branch_pr=1" >> $GITHUB_OUTPUT
138
140
139
- - name : PR update_branch
141
+ - name : Create/Update PR update_branch
140
142
if : steps.manage-branches.outputs.create_update_branch_pr == 1
141
143
env :
142
144
GH_TOKEN : ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }}
@@ -147,8 +149,16 @@ jobs:
147
149
gh_pr_up -B "${{ steps.manage-branches.outputs.base_branch }}" \
148
150
--title "Update from template" \
149
151
--body "An automated PR to sync changes from the template into this repo"
152
+
153
+ # Ensure that only a single PR is open (otherwise confusion and spam)
154
+ - name : Close PR update_branch
155
+ if : steps.manage-branches.outputs.try_close_update_branch_pr == 1
156
+ env :
157
+ GH_TOKEN : ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }}
158
+ run : |
159
+ gh pr close "${{ env.UPDATE_BRANCH }}" || true
150
160
151
- - name : PR update_branch_merged
161
+ - name : Create/Update PR update_branch_merged
152
162
if : steps.manage-branches.outputs.create_update_branch_merged_pr == 1
153
163
env :
154
164
GH_TOKEN : ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }}
0 commit comments