@@ -121,7 +121,6 @@ jobs:
121
121
github_token : ${{ secrets.OCTOMERGER_PAT_WITH_REPO_AND_WORKFLOW_SCOPE }}
122
122
123
123
- name : Create pull request
124
- id : create-pull
125
124
uses : repo-sync/pull-request@65194d8015be7624d231796ddee1cd52a5023cb3
126
125
env :
127
126
GITHUB_TOKEN : ${{ secrets.OCTOMERGER_PAT_WITH_REPO_AND_WORKFLOW_SCOPE }}
@@ -146,13 +145,6 @@ jobs:
146
145
author : Octomerger
147
146
state : open
148
147
149
- - name : Approve pull request
150
- if : ${{ steps.find-pull-request.outputs.number }}
151
- uses : juliangruber/approve-pull-request-action@c530832d4d346c597332e20e03605aa94fa150a8
152
- with :
153
- github-token : ${{ secrets.GITHUB_TOKEN }}
154
- number : ${{ steps.find-pull-request.outputs.number }}
155
-
156
148
# Because we get far too much spam ;_;
157
149
- name : Lock conversations
158
150
if : ${{ github.repository == 'github/docs' && steps.find-pull-request.outputs.number }}
@@ -221,8 +213,47 @@ jobs:
221
213
console.log(`Branch is already up-to-date`)
222
214
}
223
215
224
- - name : Enable GitHub auto-merge
216
+ - name : Check pull request file count after updating
225
217
if : ${{ steps.find-pull-request.outputs.number }}
218
+ uses : actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
219
+ id : pr-files
220
+ env :
221
+ PR_NUMBER : ${{ steps.find-pull-request.outputs.number }}
222
+ with :
223
+ github-token : ${{ secrets.OCTOMERGER_PAT_WITH_REPO_AND_WORKFLOW_SCOPE }}
224
+ result-encoding : string
225
+ script : |
226
+ const prFiles = await github.pulls.listFiles({
227
+ ...context.repo,
228
+ pull_number: process.env.PR_NUMBER,
229
+ })
230
+ core.setOutput('count', (prFiles && prFiles.length || 0).toString())
231
+
232
+ # Sometimes after updating the branch, there aren't any remaining files changed.
233
+ # If not, we should close the PR instead of merging it and triggering deployments.
234
+ - name : Close the pull request if no files remain
235
+ if : ${{ steps.find-pull-request.outputs.number && steps.pr-files.outputs.count == '0' }}
236
+ env :
237
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
238
+ run : |
239
+ gh pr close ${{ steps.find-pull-request.outputs.number }} --repo $GITHUB_REPOSITORY
240
+
241
+ - name : Comment on the pull request if no files remain
242
+ if : ${{ steps.find-pull-request.outputs.number && steps.pr-files.outputs.count == '0' }}
243
+ env :
244
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
245
+ run : |
246
+ gh pr comment ${{ steps.find-pull-request.outputs.number }} --repo $GITHUB_REPOSITORY --body "This pull request was closed because it no longer contained any changes."
247
+
248
+ - name : Approve pull request
249
+ if : ${{ steps.find-pull-request.outputs.number && steps.pr-files.outputs.count != '0' }}
250
+ uses : juliangruber/approve-pull-request-action@c530832d4d346c597332e20e03605aa94fa150a8
251
+ with :
252
+ github-token : ${{ secrets.GITHUB_TOKEN }}
253
+ number : ${{ steps.find-pull-request.outputs.number }}
254
+
255
+ - name : Enable GitHub auto-merge
256
+ if : ${{ steps.find-pull-request.outputs.number && steps.pr-files.outputs.count != '0' }}
226
257
env :
227
258
GITHUB_TOKEN : ${{ secrets.OCTOMERGER_PAT_WITH_REPO_AND_WORKFLOW_SCOPE }}
228
259
AUTOMERGE_PR_NUMBER : ${{ steps.find-pull-request.outputs.number }}
0 commit comments