-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathdetect-go-changes.bash
More file actions
executable file
·48 lines (43 loc) · 1.32 KB
/
detect-go-changes.bash
File metadata and controls
executable file
·48 lines (43 loc) · 1.32 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
#!/usr/bin/env bash
# Detect whether a PR or push includes Go-related changes.
# Prints "true" or "false" to stdout.
#
# Requires: GH_TOKEN, GITHUB_REPOSITORY
# Arguments: <event_name> <pr_number|""> <before_sha|""> <head_sha|"">
set -euo pipefail
event_name=$1
pr_number=${2:-}
before_sha=${3:-}
head_sha=${4:-}
if [ "$event_name" = "pull_request" ]; then
changed=$(gh api "repos/${GITHUB_REPOSITORY}/pulls/${pr_number}/files" \
--paginate --jq '.[].filename')
else
if [ "$before_sha" = "0000000000000000000000000000000000000000" ]; then
echo true
exit 0
fi
changed=$(gh api "repos/${GITHUB_REPOSITORY}/compare/${before_sha}...${head_sha}" \
--jq '.files[].filename')
fi
if [ -z "$changed" ]; then
echo false
exit 0
fi
# For push events, the compare API caps at 300 files.
if [ "$event_name" != "pull_request" ]; then
file_count=$(echo "$changed" | wc -l)
if [ "$file_count" -ge 300 ]; then
echo "::warning::Compare API file cap hit ($file_count files), assuming Go changes"
echo true
exit 0
fi
fi
# Anything outside these paths is considered Go-related.
# Intentionally conservative: unknown paths trigger Go CI.
non_docs=$(echo "$changed" | grep -vE '^docs/|^images/|\.md$|^LICENSE|^\.github/workflows/pages\.yml$|^\.claude/' || true)
if [ -n "$non_docs" ]; then
echo true
else
echo false
fi