Skip to content

Commit

Permalink
feat(prevent-no-label-execution): support multiple labels
Browse files Browse the repository at this point in the history
Signed-off-by: M. Fatih Cırıt <[email protected]>
  • Loading branch information
M. Fatih Cırıt committed Jun 12, 2024
1 parent 9a6e0b7 commit 5700bc3
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions .github/workflows/prevent-no-label-execution.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:
outputs:
run: ${{ steps.prevent-no-label-execution.outputs.run }}
steps:
- name: Install jq
run: sudo apt-get install -y jq

- name: Prevent no label execution
id: prevent-no-label-execution
run: |
Expand All @@ -25,25 +28,17 @@ jobs:
return
fi
# Labeled now
if [ "${{ github.event.label.name }}" != "" ]; then
if [ "${{ github.event.label.name == inputs.label }}" = "true" ]; then
echo "true"
return
fi
echo "Skipping execution since a different label '${{ github.event.label.name }}' is added."
return
fi
# Fetch all labels on the pull request
all_labels=$(jq -r '.pull_request.labels | map(.name) | @json' "${GITHUB_EVENT_PATH}")
required_label=$(jq -r --arg label "${{ inputs.label }}" 'map(select(. == $label)) | .[0]' <<< "${all_labels}")
# Labeled before and synchronized
if [ "${{ contains(github.event.pull_request.labels.*.name, inputs.label) }}" = "true" ]; then
if [ -n "${required_label}" ]; then
echo "true"
return
else
echo "Please add the label '${{ inputs.label }}' to run this workflow."
return
fi
echo "Please add the label '${{ inputs.label }}' to run this workflow."
return
}
echo "run=$(check)" >> $GITHUB_OUTPUT
Expand Down

0 comments on commit 5700bc3

Please sign in to comment.