11name : Manage PRs
22
33env :
4- SUBMISSION_PARSER_VERSION : 1.1.1 # See: https://github.com/arduino/library-manager-submission-parser/releases
4+ SUBMISSION_PARSER_VERSION : 2.0.0 # See: https://github.com/arduino/library-manager-submission-parser/releases
55 MAINTAINERS : |
66 # GitHub user names to request reviews from in cases where PRs can't be managed automatically.
77 - per1234
8- CHECK_SUBMISSIONS_FAIL_FLAG_ARTIFACT : check-submissions-failed
8+ CHECK_SUBMISSIONS_FAIL_FLAG_ARTIFACT_PREFIX : check-submissions-failed-
99 ERROR_MESSAGE_PREFIX : " :x: **ERROR:** "
1010
1111on :
@@ -114,7 +114,7 @@ jobs:
114114 run : echo "::set-output name=head::$(jq -c .head.sha "${{ steps.configuration.outputs.path }}/${{ env.JSON_IDENTIFIER }}")"
115115
116116 - name : Upload diff file to workflow artifact
117- uses : actions/upload-artifact@v3
117+ uses : actions/upload-artifact@v4
118118 with :
119119 path : ${{ steps.configuration.outputs.path }}/${{ steps.configuration.outputs.filename }}
120120 name : ${{ steps.configuration.outputs.artifact }}
@@ -125,6 +125,7 @@ jobs:
125125 runs-on : ubuntu-latest
126126
127127 outputs :
128+ conclusion : ${{ steps.parse-request.outputs.conclusion }}
128129 type : ${{ steps.parse-request.outputs.type }}
129130 error : ${{ steps.parse-request.outputs.error }}
130131 arduinoLintLibraryManagerSetting : ${{ steps.parse-request.outputs.arduinoLintLibraryManagerSetting }}
@@ -133,6 +134,8 @@ jobs:
133134 indexer-logs-urls : ${{ steps.parse-request.outputs.indexer-logs-urls }}
134135
135136 steps :
137+ # Checkout the tip of the default branch (this is the action's default ref input value when workflow is triggered
138+ # by an issue_comment or pull_request_target event).
136139 - name : Checkout local repository
137140 uses : actions/checkout@v4
138141
@@ -144,13 +147,13 @@ jobs:
144147 location : ${{ runner.temp }}
145148
146149 - name : Download diff
147- uses : actions/download-artifact@v3
150+ uses : actions/download-artifact@v4
148151 with :
149152 path : ${{ needs.diff.outputs.path }}
150153 name : ${{ needs.diff.outputs.artifact }}
151154
152155 - name : Remove no longer needed artifact
153- uses : geekyeggo/delete-artifact@v2
156+ uses : geekyeggo/delete-artifact@v5
154157 with :
155158 name : ${{ needs.diff.outputs.artifact }}
156159
@@ -160,12 +163,15 @@ jobs:
160163 chmod u+x "${{ steps.download-parser.outputs.file-path }}"
161164 REQUEST="$( \
162165 "${{ steps.download-parser.outputs.file-path }}" \
166+ --accesslist=".github/workflows/assets/accesslist.yml" \
163167 --diffpath="${{ needs.diff.outputs.path }}/${{ needs.diff.outputs.filename }}" \
164168 --repopath="${{ github.workspace }}" \
165169 --listname="repositories.txt" \
170+ --submitter="${{ github.actor }}" \
166171 )"
167172 # Due to limitations of the GitHub Actions workflow system, dedicated outputs must be created for use in
168173 # certain workflow fields.
174+ echo "::set-output name=conclusion::$(echo "$REQUEST" | jq -r -c '.conclusion')"
169175 echo "::set-output name=type::$(echo "$REQUEST" | jq -r -c '.type')"
170176 echo "::set-output name=error::$(echo "$REQUEST" | jq -r -c '.error')"
171177 echo "::set-output name=arduinoLintLibraryManagerSetting::$(echo "$REQUEST" | jq -r -c '.arduinoLintLibraryManagerSetting')"
@@ -191,10 +197,13 @@ jobs:
191197 labels : |
192198 - "topic: ${{ needs.parse.outputs.type }}"
193199
200+ # Handle problem found by the parser that can potentially be resolved by requester.
194201 parse-fail :
195202 needs :
196203 - parse
197- if : needs.parse.outputs.error != ''
204+ if : >
205+ needs.parse.outputs.conclusion != 'declined' &&
206+ needs.parse.outputs.error != ''
198207
199208 runs-on : ubuntu-latest
200209 steps :
@@ -219,13 +228,64 @@ jobs:
219228 More information:
220229 https://github.com/${{ github.repository }}/blob/main/README.md#if-the-problem-is-with-the-pull-request
221230
231+ # Requester's registry privileges have been revoked.
232+ decline-request :
233+ needs :
234+ - parse
235+ if : >
236+ needs.parse.outputs.conclusion == 'declined' &&
237+ needs.parse.outputs.error != ''
238+ runs-on : ubuntu-latest
239+ steps :
240+ - name : Comment reason for declining request
241+ 242+ if : needs.parse.outputs.error != ''
243+ env :
244+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
245+ with :
246+ route : POST /repos/{owner}/{repo}/issues/{issue_number}/comments
247+ owner : ${{ github.repository_owner }}
248+ repo : ${{ github.event.repository.name }}
249+ issue_number : ${{ github.event.pull_request.number }}${{ github.event.issue.number }}
250+ body : |
251+ |
252+ Hi @${{ github.actor }}
253+ Your request has been declined:
254+
255+ ${{ env.ERROR_MESSAGE_PREFIX }}${{ needs.parse.outputs.error }}
256+
257+ - name : Close PR
258+ 259+ env :
260+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
261+ with :
262+ route : PATCH /repos/{owner}/{repo}/pulls/{pull_number}
263+ owner : ${{ github.repository_owner }}
264+ repo : ${{ github.event.repository.name }}
265+ pull_number : ${{ github.event.pull_request.number }}${{ github.event.issue.number }}
266+ state : closed
267+
268+ - name : Add conclusion label to PR
269+ 270+ env :
271+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
272+ with :
273+ # See: https://docs.github.com/rest/issues/labels#add-labels-to-an-issue
274+ route : POST /repos/{owner}/{repo}/issues/{issue_number}/labels
275+ owner : ${{ github.repository_owner }}
276+ repo : ${{ github.event.repository.name }}
277+ issue_number : ${{ github.event.pull_request.number }}${{ github.event.issue.number }}
278+ labels : |
279+ - "conclusion: ${{ needs.parse.outputs.conclusion }}"
280+
222281 check-submissions :
223282 name : Check ${{ matrix.submission.submissionURL }}
224283 needs :
225284 - parse
226285 if : >
227286 needs.parse.outputs.type == 'submission' ||
228287 needs.parse.outputs.type == 'modification'
288+
229289 runs-on : ubuntu-latest
230290 strategy :
231291 fail-fast : false
@@ -275,6 +335,15 @@ jobs:
275335 if : matrix.submission.error != ''
276336 run : echo "PASS=false" >> "$GITHUB_ENV"
277337
338+ # Parser checks are relevant in the case where request is declined due to registry access having been revoked for
339+ # the library repository owners. However, the rest of the checks are irrelevant and may result in confusing
340+ # comments from the bot, so should be skipped.
341+ - name : Skip the rest of the checks if request is declined
342+ if : >
343+ needs.parse.outputs.conclusion == 'declined' &&
344+ env.PASS == 'true'
345+ run : echo "PASS=false" >> "$GITHUB_ENV"
346+
278347 - name : Install Arduino Lint
279348 if : env.PASS == 'true'
280349 run : |
@@ -376,15 +445,23 @@ jobs:
376445 if : env.PASS == 'false'
377446 run : touch ${{ env.FAIL_FLAG_PATH }} # Arbitrary file to provide content for the flag artifact
378447
448+ # Each workflow artifact must have a unique name. The job matrix doesn't provide a guaranteed unique string to use
449+ # for a name so it is necessary to generate one.
450+ - name : Generate unique artifact suffix
451+ if : env.PASS == 'false'
452+ run : |
453+ echo "CHECK_SUBMISSIONS_FAIL_FLAG_ARTIFACT_SUFFIX=$(cat /proc/sys/kernel/random/uuid)" >> "$GITHUB_ENV"
454+
379455 # The value of a job matrix output is set by whichever job happened to run last, not of use for this application.
380456 # So it's necessary to use an alternative means of indicating that at least one submission failed the checks.
381457 - name : Upload failure flag artifact
382458 if : env.PASS == 'false'
383- uses : actions/upload-artifact@v3
459+ uses : actions/upload-artifact@v4
384460 with :
385461 if-no-files-found : error
462+ include-hidden-files : true
386463 path : ${{ env.FAIL_FLAG_PATH }}
387- name : ${{ env.CHECK_SUBMISSIONS_FAIL_FLAG_ARTIFACT }}
464+ name : ${{ env.CHECK_SUBMISSIONS_FAIL_FLAG_ARTIFACT_PREFIX }}${{ env.CHECK_SUBMISSIONS_FAIL_FLAG_ARTIFACT_SUFFIX }}
388465
389466 check-submissions-result :
390467 needs : check-submissions
@@ -393,20 +470,32 @@ jobs:
393470 outputs :
394471 pass : ${{ steps.failure-flag-exists.outcome == 'failure' }}
395472
473+ env :
474+ CHECK_SUBMISSIONS_FAIL_FLAG_ARTIFACT_PATH : ${{ github.workspace }}/artifacts
475+
396476 steps :
477+ - name : Download submission check failure flag artifacts
478+ uses : actions/download-artifact@v4
479+ with :
480+ path : ${{ env.CHECK_SUBMISSIONS_FAIL_FLAG_ARTIFACT_PATH }}
481+ pattern : ${{ env.CHECK_SUBMISSIONS_FAIL_FLAG_ARTIFACT_PREFIX }}*
482+
397483 - name : Check for existence of submission check failure flag artifact
398484 id : failure-flag-exists
399- uses : actions/download-artifact@v3
400485 continue-on-error : true
401- with :
402- name : ${{ env.CHECK_SUBMISSIONS_FAIL_FLAG_ARTIFACT }}
486+ # actions/download-artifact does not create a folder per its `path` input if no artifacts match `pattern`.
487+ run : |
488+ test -d "${{ env.CHECK_SUBMISSIONS_FAIL_FLAG_ARTIFACT_PATH }}"
403489
490+ # Handle problem found by the submission checks that can potentially be resolved by requester.
404491 check-submissions-fail :
405492 needs :
493+ - parse
406494 - check-submissions-result
407- if : needs.check-submissions-result.outputs.pass == 'false'
495+ if : >
496+ needs.parse.outputs.conclusion != 'declined' &&
497+ needs.check-submissions-result.outputs.pass == 'false'
408498 runs-on : ubuntu-latest
409-
410499 steps :
411500 - name : Comment instructions to fix errors detected during submission checks
412501@@ -432,6 +521,37 @@ jobs:
432521 More information:
433522 https://github.com/${{ github.repository }}/blob/main/README.md#if-the-problem-is-with-the-pull-request
434523
524+ decline-submissions :
525+ needs :
526+ - parse
527+ - check-submissions
528+ if : needs.parse.outputs.conclusion == 'declined'
529+ runs-on : ubuntu-latest
530+ steps :
531+ - name : Close PR
532+ 533+ env :
534+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
535+ with :
536+ route : PATCH /repos/{owner}/{repo}/pulls/{pull_number}
537+ owner : ${{ github.repository_owner }}
538+ repo : ${{ github.event.repository.name }}
539+ pull_number : ${{ github.event.pull_request.number }}${{ github.event.issue.number }}
540+ state : closed
541+
542+ - name : Add conclusion label to PR
543+ 544+ env :
545+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
546+ with :
547+ # See: https://docs.github.com/rest/issues/labels#add-labels-to-an-issue
548+ route : POST /repos/{owner}/{repo}/issues/{issue_number}/labels
549+ owner : ${{ github.repository_owner }}
550+ repo : ${{ github.event.repository.name }}
551+ issue_number : ${{ github.event.pull_request.number }}${{ github.event.issue.number }}
552+ labels : |
553+ - "conclusion: ${{ needs.parse.outputs.conclusion }}"
554+
435555 merge :
436556 needs :
437557 - diff
@@ -584,6 +704,7 @@ jobs:
584704 - parse
585705 # These request types can't be automatically approved.
586706 if : >
707+ needs.parse.outputs.conclusion != 'declined' &&
587708 needs.parse.outputs.type != 'submission' &&
588709 needs.parse.outputs.type != 'invalid'
589710 runs-on : ubuntu-latest
@@ -610,8 +731,10 @@ jobs:
610731 needs :
611732 # Run after all other jobs
612733 - parse-fail
734+ - decline-request
613735 - merge-fail
614736 - check-submissions-fail
737+ - decline-submissions
615738 - label
616739 - not-submission
617740 # Run if any job failed. The workflow is configured so that jobs only fail when there is an unexpected error.
0 commit comments