diff --git a/.github/workflows/prevent-no-label-execution.yaml b/.github/workflows/prevent-no-label-execution.yaml index 924e6ff6..dcfe234f 100644 --- a/.github/workflows/prevent-no-label-execution.yaml +++ b/.github/workflows/prevent-no-label-execution.yaml @@ -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: | @@ -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