-
Notifications
You must be signed in to change notification settings - Fork 16
57 lines (52 loc) · 1.74 KB
/
Copy pathlabel-sync.yml
File metadata and controls
57 lines (52 loc) · 1.74 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
name: Label sync
on:
push:
branches: [main, master]
paths:
- ".github/labels.yml"
- ".github/workflows/label-sync.yml"
workflow_dispatch:
permissions: {}
concurrency:
group: label-sync
cancel-in-progress: true
jobs:
sync:
name: Sync repository labels
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
issues: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Create or update labels
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
set -euo pipefail
while IFS=$'\t' read -r name color description; do
encoded_name="$(jq -rn --arg value "$name" '$value | @uri')"
if gh api --silent "repos/$GITHUB_REPOSITORY/labels/$encoded_name"; then
gh api --silent --method PATCH "repos/$GITHUB_REPOSITORY/labels/$encoded_name" \
-f new_name="$name" \
-f color="$color" \
-f description="$description"
else
gh api --silent --method POST "repos/$GITHUB_REPOSITORY/labels" \
-f name="$name" \
-f color="$color" \
-f description="$description"
fi
done < <(
ruby -ryaml -e '
YAML.safe_load_file(".github/labels.yml").each do |label|
values = %w[name color description].map { |key| label.fetch(key).to_s }
abort "label fields must be single-line values" if values.any? { |value| value.include?("\t") || value.include?("\n") }
puts values.join("\t")
end
'
)