-
Notifications
You must be signed in to change notification settings - Fork 77
53 lines (49 loc) · 2.07 KB
/
pr-label-check.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
# make sure the pr is labeled as wanted, case: we could generate changelog by the pr label
name: PR Label Check
# Trigger the workflow on pull requests only
on:
pull_request:
types: [opened, labeled, unlabeled, synchronize]
env:
LEASE_ONE_OF_LABELS: "release/bug release/feature-new release/feature-changed release/none pr/robot_update"
FORBID_LABELS: "pr/not-ready not-ready"
jobs:
check-label:
name: Check label set
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
# must set one of required label, for release note generator
- name: check label
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -x
PR_NUMBER="${{ github.event.number }}"
[ -n "${PR_NUMBER}" ] || { echo "no PR number" ; exit 1 ; }
gh pr view ${PR_NUMBER}
PR_LABEL=` gh pr view ${PR_NUMBER} | grep -i "^labels:" | tr ',' ' ' | tr -s ' ' | sed 's/labels://g' `
[ -n "${PR_LABEL}" ] || { echo "no PR_LABEL " ; exit 1 ; }
echo "============ checking forbidden label ============ "
for LABEL in ${PR_LABEL} ; do
if grep -i " ${LABEL} " <<< " ${{ env.FORBID_LABELS }} " &>/dev/null ; then
echo "error, forbidden label ${LABEL} is not clear, all forbidden labels: '${{ env.FORBID_LABELS }}' "
exit 1
fi
done
echo "============ checking required label ============ "
COUNTER=0
for LABEL in ${PR_LABEL} ; do
! grep -i " ${LABEL} " <<< " ${{ env.LEASE_ONE_OF_LABELS }} " &>/dev/null || (( COUNTER=COUNTER+1 ))
done
if (( COUNTER == 0 )) ; then
echo "error, at lease, one of '${{ env.LEASE_ONE_OF_LABELS }}' should be set "
exit 1
fi
echo "============ result ============ "
echo "pr labels: ${PR_LABEL}"
echo "required one label: ${{ env.LEASE_ONE_OF_LABELS }} "
echo "forbideen labels: ${{ env.FORBID_LABELS }} "