Skip to content

Commit bcb0fc6

Browse files
committed
build: ensure job doesn't fail when a user doesn't have write access
1 parent 2cf1a24 commit bcb0fc6

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

.github/workflows/process_metadata.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ on:
2525
branches:
2626
- develop
2727
issue_comment:
28-
types: [created, edited]
28+
types: [ created, edited ]
2929

3030
# Global permissions:
3131
permissions:
@@ -48,15 +48,24 @@ jobs:
4848
steps:
4949
# Exit if the user does not have write access to the repository:
5050
- name: 'Exit if user does not have write access'
51+
id: assert-write-access
52+
5153
# Pin action to full length commit SHA
5254
uses: lannonbr/repo-permission-check-action@2bb8c89ba8bf115c4bfab344d6a6f442b24c9a1f # v2.0.2
5355
with:
5456
permission: 'write'
5557
env:
5658
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5759

60+
# Continue with subsequent steps even when this step fails in order to "pass" the job and not trigger failure e-mails/notifications:
61+
continue-on-error: true
62+
5863
# Checkout the repository:
5964
- name: 'Checkout repository'
65+
66+
# Only run this step if a user has write access:
67+
if: steps.assert-write-access.outcome == 'success'
68+
6069
# Pin action to full length commit SHA
6170
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
6271
with:
@@ -73,11 +82,16 @@ jobs:
7382
# Extract commit message and issue comment metadata:
7483
- name: 'Extract metadata'
7584
id: extract-metadata
85+
86+
# Only run this step if a user has write access:
87+
if: steps.assert-write-access.outcome == 'success'
88+
7689
# Pin action to full length commit SHA
7790
uses: stdlib-js/metadata-action@3ccf68f24c51ae23470319e8e5619d539df8212b # v3.0.0
7891

7992
# Check the metadata for directives to send tweets:
8093
- name: 'Send tweets'
94+
8195
# Pin action to full length commit SHA
8296
uses: stdlib-js/metadata-tweet-action@8e9b688c86150797c1c7f60bc8f7c9a9a30e10fe # v2.0.0
8397
with:
@@ -90,6 +104,10 @@ jobs:
90104
# Check the metadata for directives to dispatch workflows:
91105
- name: 'Check metadata for workflow dispatch directives'
92106
id: check-workflow-dispatch
107+
108+
# Only run this step if a user has write access:
109+
if: steps.assert-write-access.outcome == 'success'
110+
93111
run: |
94112
inputs=$(echo '${{ steps.extract-metadata.outputs.metadata }}' | jq -c '.[] | select(.type | contains("workflow_dispatch"))')
95113
if [ -n "$inputs" ]; then
@@ -104,9 +122,10 @@ jobs:
104122
105123
# Dispatch first found workflow (if applicable):
106124
- name: 'Dispatch workflow with inputs'
125+
107126
# Pin action to full length commit SHA
108127
uses: benc-uk/workflow-dispatch@25b02cc069be46d637e8fe2f1e8484008e9e9609 # v1.2.3
109-
if: steps.check-workflow-dispatch.outputs.dispatch == 'true'
128+
if: ${{ steps.assert-write-access.outcome == 'success' && steps.check-workflow-dispatch.outputs.dispatch == 'true' }}
110129
with:
111130
workflow: ${{ steps.check-workflow-dispatch.outputs.workflow }}
112131
inputs: ${{ steps.check-workflow-dispatch.outputs.inputs }}

0 commit comments

Comments
 (0)