Skip to content

Commit 46f9f63

Browse files
committed
ci: add label check script
1 parent ecd7db0 commit 46f9f63

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

.github/scripts/check-labels.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
#
3+
# This script checks the local label table (ISSUE_LABELS.md) against canonical label file in the
4+
# protocol/.github repo.
5+
6+
set -euo pipefail
7+
set -x
8+
9+
# The canonical source of labels.
10+
CANONICAl_LABELS="https://raw.githubusercontent.com/protocol/.github/master/ISSUE_LABELS.json"
11+
12+
# Matches labels in label tables. Assumes table rows have the form:
13+
# | `label name` | Some description... | ...`#hexcolor`... |
14+
LABEL_REGEXP='s/|.*`\([^`]*\)`.*| *\([^|]*[^ |]\) *|.*`\(#[a-f0-9]*\)`.*|/\1\t\3\t\2/p'
15+
16+
# Reads a label markdown file on stdin and prints a JSON version on stdout.
17+
parse_labels() {
18+
while IFS=$'\t' read -r label color description; do
19+
jq -n \
20+
--arg name "$label" \
21+
--arg color "${color##\#}" \
22+
--arg description "$description" \
23+
'{"name": $name, "color": $color, "description": $description}'
24+
done < <(sed -ne "$LABEL_REGEXP" - ) |
25+
jq 'select(.name | startswith("area/") == false)' | # area labels are not synced.
26+
jq -s 'sort_by(.name)' # sort into a canonical order for comparison.
27+
}
28+
29+
# Extract labels.
30+
parse_labels < ISSUE_LABELS.md > ISSUE_LABELS.json
31+
32+
# Download canonical labels.
33+
curl "$CANONICAl_LABELS" |
34+
jq 'del(.aliases)|sort_by(.name)' > CANONICAL_LABELS.json
35+
36+
# Compare.
37+
if ! diff -u CANONICAL_LABELS.json ISSUE_LABELS.json; then
38+
echo "Please update the labels defined at https://github.com/protocol/.github/blob/master/ISSUE_LABELS.json."
39+
exit 1
40+
fi
41+

0 commit comments

Comments
 (0)