|
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 | | - |
13 | 1 | name: PR labels check |
14 | 2 |
|
15 | 3 | on: |
16 | 4 | pull_request_target: |
17 | 5 | types: [opened, labeled, unlabeled, synchronize] |
18 | 6 |
|
19 | 7 | permissions: |
20 | | - pull-requests: read |
| 8 | + issues: write |
| 9 | + pull-requests: write |
21 | 10 |
|
22 | 11 | jobs: |
23 | 12 | check-labels: |
24 | 13 | runs-on: ubuntu-latest |
25 | 14 |
|
26 | 15 | 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