-
Notifications
You must be signed in to change notification settings - Fork 1.6k
76 lines (60 loc) · 2.17 KB
/
label-checker.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
name: Check PR Labels
on:
pull_request:
types: [opened, labeled, unlabeled, synchronize]
jobs:
check-label:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
- name: Install yq
run: |
pip install yq
- name: Get required labels from release.yml
id: get-required-labels
run: |
labels=()
for label in $(yq -r '.changelog.categories[] | select(.title != "Uncategorized") | .labels[]' .github/release.yml); do
labels+=("$label")
done
labels_string=$(IFS=, ; echo "${labels[*]}")
echo "Required labels: $labels_string"
echo "required_labels=$labels_string" >> $GITHUB_OUTPUT
- name: Get PR labels
id: get-pr-labels
run: |
labels=()
for label in $(jq -r '.pull_request.labels[].name' "$GITHUB_EVENT_PATH"); do
labels+=("$label")
done
labels_string=$(IFS=, ; echo "${labels[*]}")
echo "PR labels: $labels_string"
echo "labels=$labels_string" >> $GITHUB_OUTPUT
- name: Check for specific labels
id: check-label
run: |
required_labels="${{ steps.get-required-labels.outputs.required_labels }}"
pr_labels="${{ steps.get-pr-labels.outputs.labels }}"
IFS=',' read -r -a required_labels_array <<< "$required_labels"
IFS=',' read -r -a pr_labels_array <<< "$pr_labels"
found=false
for required_label in "${required_labels_array[@]}"; do
for pr_label in "${pr_labels_array[@]}"; do
if [[ "$required_label" == "$pr_label" ]]; then
found=true
break 2
fi
done
done
echo "label_exists=$found" >> $GITHUB_OUTPUT
- name: Fail if no required labels are found
if: steps.check-label.outputs.label_exists == 'false'
run: |
echo "None of the required labels are applied to the PR."
exit 1