-
Notifications
You must be signed in to change notification settings - Fork 9
40 lines (34 loc) · 1.68 KB
/
add-label.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
name: Label a PR with its updated packages
on:
pull_request:
types: [opened, synchronize, ready_for_review]
jobs:
label-pr:
if: ${{ github.event.pull_request.draft == false && github.event.pull_request.user.login != 'triple-bot' && !contains(github.event.pull_request.labels.*.name, 'release') }}
runs-on: [self-hosted, linux, x64]
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Get changed packages
run: |
RESPONSE=$(curl -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/compare/${{ github.event.pull_request.base.ref }}...${{ github.event.pull_request.head.ref }}")
if [[ $(echo "$RESPONSE" | jq '.total_commits') == null ]]; then
echo $RESPONSE | jq '.message'
exit 1
fi
CHANGED_PACKAGES=$(echo "$RESPONSE" | jq '[.files[].filename | capture("packages/(?<packageName>[^/]+)/") .packageName] | unique | tostring')
echo "CHANGED_PACKAGES=$CHANGED_PACKAGES" >> $GITHUB_ENV
- name: Label PR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PACKAGE_LABELS=$(echo ${{ env.CHANGED_PACKAGES }} | jq .)
curl -X POST \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels \
-d "{\"labels\": $PACKAGE_LABELS }"