-
Notifications
You must be signed in to change notification settings - Fork 440
57 lines (48 loc) · 1.77 KB
/
label_check.yml
File metadata and controls
57 lines (48 loc) · 1.77 KB
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
name: Check release label
on:
pull_request:
types:
- synchronize
- opened
- reopened
- edited
- labeled
- unlabeled
jobs:
label_check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Wait for bot to set label
run: sleep 10
- name: Check labels
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Get PR number and repo name from event payload
PR_NUMBER=$(jq -r .pull_request.number "$GITHUB_EVENT_PATH")
REPO_FULL_NAME=$(jq -r .repository.full_name "$GITHUB_EVENT_PATH")
# Fetch fresh PR data from GitHub API
PR_DATA=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO_FULL_NAME/issues/$PR_NUMBER")
NUMBER_OF_LABELS=$(echo "$PR_DATA" | jq '.labels | length')
if [ $NUMBER_OF_LABELS -eq 0 ]; then
echo "PR has no labels. Please add at least one label of release type."
exit 1
fi
RELEASE_LABELS=("release::enhancements" "release::bug_fixes" "release::ci_docs" "release::maintenance")
PR_LABELS=$(echo "$PR_DATA" | jq -r '.labels[].name')
NB_RELEASE_LABELS=0
for LABEL in $PR_LABELS; do
if [[ " ${RELEASE_LABELS[@]} " =~ " ${LABEL} " ]]; then
NB_RELEASE_LABELS=$((NB_RELEASE_LABELS+1))
fi
done
if [ $NB_RELEASE_LABELS -eq 0 ]; then
echo "PR has no release labels. Please add a label of release type."
exit 1
elif [ $NB_RELEASE_LABELS -gt 1 ]; then
echo "PR has multiple release labels. Please remove all but one label."
exit 1
fi