-
-
Notifications
You must be signed in to change notification settings - Fork 1
64 lines (59 loc) · 1.84 KB
/
Copy pathlabel-sync.yml
File metadata and controls
64 lines (59 loc) · 1.84 KB
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
58
59
60
61
62
63
64
name: "Label Sync"
on:
push:
branches: [master]
paths:
- .github/labels.yml
- .github/workflows/label-sync.yml
workflow_dispatch:
inputs:
prune:
description: "Delete labels not in labels.yml"
type: boolean
default: false
permissions:
contents: read
issues: write
pull-requests: write
jobs:
sync:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
LABELS_FILE: .github/labels.yml
PRUNE: ${{ github.event.inputs.prune || 'false' }}
steps:
- uses: actions/checkout@v6
- name: Upsert labels
run: |
set -euo pipefail
count=$(yq '. | length' "$LABELS_FILE")
for i in $(seq 0 $((count - 1))); do
name=$(yq ".[$i].name" "$LABELS_FILE")
color=$(yq ".[$i].color" "$LABELS_FILE")
description=$(yq ".[$i].description // \"\"" "$LABELS_FILE")
echo "::group::$name"
gh label create "$name" \
--repo "$GITHUB_REPOSITORY" \
--color "$color" \
--description "$description" \
--force
echo "::endgroup::"
done
- name: Prune extra labels
if: env.PRUNE == 'true'
run: |
set -euo pipefail
desired=$(yq -r '.[].name' "$LABELS_FILE" | sort -u)
current=$(gh label list --repo "$GITHUB_REPOSITORY" --limit 500 --json name -q '.[].name' | sort -u)
extras=$(comm -23 <(echo "$current") <(echo "$desired"))
if [ -z "$extras" ]; then
echo "No extra labels."
exit 0
fi
echo "Deleting:"
echo "$extras"
while IFS= read -r name; do
[ -z "$name" ] && continue
gh label delete "$name" --repo "$GITHUB_REPOSITORY" --yes
done <<< "$extras"