-
Notifications
You must be signed in to change notification settings - Fork 0
57 lines (48 loc) · 1.73 KB
/
check for lable.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
name: Check for label on pull request
on:
pull_request:
types: [opened, labeled, unlabeled]
branches:
- main
jobs:
check-lables:
runs-on: ubuntu-latest
steps:
- name: Get PR labels
run: |
PR_LABELS="${{ join(github.event.pull_request.labels.*.name, ',') }}"
echo "PR_LABELS=$PR_LABELS" >> $GITHUB_ENV
echo "Labels fetched: $PR_LABELS"
- name: Calculate number of labels
run: |
LABEL_COUNT=$(echo "$PR_LABELS" | awk -F',' '{print NF}')
echo "LABEL_COUNT=$LABEL_COUNT" >> $GITHUB_ENV
- name: Contains lable
if: ${{ env.LABEL_COUNT == '0' }}
run: |
echo "The pull request needs a lable."
exit 1 #This fails the action
- name: Check if pull request labels combination is okay
run: |
#if it has exatly one label there is no combination
if [ "$LABEL_COUNT" -eq 1 ] exit 0; fi
#E alows for use of or operators
#breaking
if echo "$PR_LABELS" | grep -q "\bbreaking\b"; then
NOT_ALLOWED_LABELS="refactor|test|workflow"
if echo "$PR_LABELS" | grep -qE "\b($NOT_ALLOWED_LABELS)\b"; then
exit 1
fi
#bug
elif echo "$PR_LABELS" | grep -q "\bbug\b"; then
NOT_ALLOWED_LABELS="refactor"
if echo "$PR_LABELS" | grep -qE "\b($NOT_ALLOWED_LABELS)\b"; then
exit 1
fi
#feature
elif echo "$PR_LABELS" | grep -q "\bfeature\b"; then
NOT_ALLOWED_LABELS="refactor|test"
if echo "$PR_LABELS" | grep -qE "\b($NOT_ALLOWED_LABELS)\b"; then
exit 1
fi
fi