-
Notifications
You must be signed in to change notification settings - Fork 26
55 lines (47 loc) · 1.57 KB
/
prevent-no-label-execution.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
name: prevent-no-label-execution
on:
workflow_call:
inputs:
label:
required: true
type: string
outputs:
run:
value: ${{ jobs.prevent-no-label-execution.outputs.run }}
jobs:
prevent-no-label-execution:
runs-on: ubuntu-22.04
outputs:
run: ${{ steps.prevent-no-label-execution.outputs.run }}
steps:
- name: Prevent no label execution
id: prevent-no-label-execution
run: |
function check() {
if [ "${{ github.event_name }}" != "pull_request" ] && [ "${{ github.event_name }}" != "pull_request_target" ]; then
echo "true"
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
# Labeled before and synchronized
if [ "${{ contains(github.event.pull_request.labels.*.name, inputs.label) }}" = "true" ]; then
echo "true"
return
fi
echo "Please add the label '${{ inputs.label }}' to run this workflow."
return
}
echo "run=$(check)" >> $GITHUB_OUTPUT
shell: bash
- name: Show result
run: |
echo "::notice:: ${{ steps.prevent-no-label-execution.outputs.run }}"
shell: bash