-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathcheck_conformance_label.sh
More file actions
executable file
·86 lines (72 loc) · 2.53 KB
/
check_conformance_label.sh
File metadata and controls
executable file
·86 lines (72 loc) · 2.53 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env bash
set -eo pipefail
# Labels that allow conformance.toml changes (at least one required for changes to existing cases)
required_labels=(
breaking-format
breaking-api
)
# GitHub may refuse to render full PR diffs once they exceed the API's line cap.
# Use the paginated files API instead so large PRs still work.
repo="${GITHUB_REPOSITORY:-$(gh repo view --json nameWithOwner --jq '.nameWithOwner')}"
files=$(gh api --paginate --slurp "/repos/${repo}/pulls/${PR_NUMBER}/files")
# Filter for conformance.toml files
changed=$(jq -r '.[] | .[] | select(.filename | endswith("conformance.toml")) | .filename' <<<"$files")
if [ -z "$changed" ]; then
echo "No conformance.toml files changed"
exit 0
fi
echo "Conformance files changed:"
echo "$changed"
echo ""
# Check if any conformance.toml changes include deletions or other non-additive edits.
# If GitHub omits the patch for an existing file, require a label conservatively since
# we can no longer prove the change is additive.
has_deletions=false
while IFS= read -r file; do
filename=$(jq -r '.filename' <<<"$file")
status=$(jq -r '.status' <<<"$file")
patch_present=$(jq -r 'has("patch")' <<<"$file")
if [[ "$status" == "removed" || "$status" == "renamed" ]]; then
has_deletions=true
echo "Deletion/modification found in: $filename ($status)"
break
fi
if [[ "$status" != "added" && "$patch_present" != "true" ]]; then
has_deletions=true
echo "Unable to inspect patch for existing conformance file: $filename"
break
fi
if jq -e '
(.patch // "")
| split("\n")
| any(startswith("-") and (startswith("---") | not))
' <<<"$file" >/dev/null; then
has_deletions=true
echo "Deletion/modification found in: $filename"
break
fi
done < <(
jq -c '.[] | .[] | select(.filename | endswith("conformance.toml"))' <<<"$files"
)
if [ "$has_deletions" = "false" ]; then
echo "All conformance.toml changes are additive, no label required"
exit 0
fi
echo ""
# Get PR labels
labels=$(gh pr view "$PR_NUMBER" --json labels --jq '.labels[].name')
# Check if any required label is present
for req in "${required_labels[@]}"; do
if echo "$labels" | grep -qx "$req"; then
echo "Found required label: $req"
exit 0
fi
done
echo "ERROR: conformance.toml file(s) changed but no required label found."
echo ""
echo "Modifying or removing entries in conformance.toml files is a BREAKING CHANGE."
echo "Adding new entries is allowed without a label."
echo ""
echo "Required labels (at least one):"
printf " - %s\n" "${required_labels[@]}"
exit 1