Skip to content

Commit de9a653

Browse files
committed
Simplify label check using pre-built action
1 parent c5ab9ee commit de9a653

1 file changed

Lines changed: 25 additions & 43 deletions

File tree

.github/workflows/pr-labels.yml

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,38 @@
1-
# Verifies if a pull request has at least one label from a set of valid
2-
# labels before it can be merged.
3-
#
4-
# NOTE:
5-
# This workflow may be triggered twice in quick succession when a PR is
6-
# created:
7-
# 1) `opened` — when the pull request is initially created
8-
# 2) `labeled` — if labels are added immediately after creation
9-
# (e.g. by manual labeling, another workflow, or GitHub App).
10-
#
11-
# These are separate GitHub events, so two workflow runs can be started.
12-
131
name: PR labels check
142

153
on:
164
pull_request_target:
175
types: [opened, labeled, unlabeled, synchronize]
186

197
permissions:
20-
pull-requests: read
8+
issues: write
9+
pull-requests: write
2110

2211
jobs:
2312
check-labels:
2413
runs-on: ubuntu-latest
2514

2615
steps:
27-
- name: Check for valid labels
28-
run: |
29-
PR_LABELS=$(echo '${{ toJson(github.event.pull_request.labels.*.name) }}' | jq -r '.[]')
30-
31-
echo "Current PR labels: $PR_LABELS"
32-
VALID_LABELS=(
33-
"[bot] release"
34-
"[scope] bug"
35-
"[scope] documentation"
36-
"[scope] enhancement"
37-
"[scope] maintenance"
38-
"[scope] significant"
39-
)
40-
41-
found=false
42-
for label in "${VALID_LABELS[@]}"; do
43-
if echo "$PR_LABELS" | grep -Fxq "$label"; then
44-
echo "✅ Found valid label: $label"
45-
found=true
46-
break
47-
fi
48-
done
49-
50-
if [ "$found" = false ]; then
51-
echo "ERROR: PR must have at least one of the following labels:"
52-
for label in "${VALID_LABELS[@]}"; do
53-
echo " - $label"
54-
done
55-
exit 1
56-
fi
16+
- name: Checkout repository
17+
uses: actions/checkout@v6
18+
19+
- name: Setup easyscience[bot]
20+
id: bot
21+
uses: ./.github/actions/setup-easyscience-bot
22+
with:
23+
app-id: ${{ vars.EASYSCIENCE_APP_ID }}
24+
private-key: ${{ secrets.EASYSCIENCE_APP_KEY }}
25+
26+
- uses: mheap/github-action-required-labels@v5
27+
with:
28+
token: ${{ steps.bot.outputs.token }}
29+
add_comment: true
30+
mode: minimum
31+
count: 1
32+
labels: |
33+
[bot] release
34+
[scope] bug
35+
[scope] documentation
36+
[scope] enhancement
37+
[scope] maintenance
38+
[scope] significant

0 commit comments

Comments
 (0)