Skip to content

Commit 5c0213b

Browse files
address preston's comments
1 parent 51897cd commit 5c0213b

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

.github/workflows/check-logs.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ jobs:
1616
with:
1717
go-version: '1.25.1'
1818

19+
- name: Install ripgrep
20+
run: sudo apt-get install -y ripgrep
21+
1922
- name: Check log.go files
20-
run: |
21-
chmod +x hack/gen-logs.sh hack/check-logs.sh
22-
./hack/check-logs.sh
23+
run: ./hack/check-logs.sh

hack/gen-logs.sh

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ EXCLUDED_PATH_PREFIXES=(
2525
"bazel-prysm"
2626
"bazel-testlogs"
2727
"build"
28+
".git"
2829
".github"
2930
".jj"
3031
".idea"
@@ -35,6 +36,12 @@ EXCLUDED_PATH_PREFIXES=(
3536
LOGRUS_IMPORT="github.com/sirupsen/logrus"
3637
# ----------------------------
3738

39+
# Require ripgrep
40+
if ! command -v rg >/dev/null 2>&1; then
41+
echo "Error: ripgrep (rg) is required but not installed." >&2
42+
exit 1
43+
fi
44+
3845
# Find project root (git repo root if available, else current dir)
3946
ROOT_DIR="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
4047
cd "$ROOT_DIR"
@@ -52,30 +59,28 @@ is_excluded() {
5259
return 1
5360
}
5461

55-
# Build a find command that:
56-
# - starts at .
57-
# - prunes all EXCLUDED_PATH_PREFIXES
58-
# - returns only *.go files that are NOT *_test.go
59-
find_cmd=(find .)
60-
61-
find_cmd+=( \( -path './.git' )
62+
# Build rg command:
63+
# - respects .gitignore automatically
64+
# - searches only *.go, excluding *_test.go
65+
# - excludes EXCLUDED_PATH_PREFIXES via negative globs so rg doesn't even enter them
66+
rg_args=(
67+
rg -F "$LOGRUS_IMPORT"
68+
--glob '*.go'
69+
--glob '!*_test.go'
70+
-l # list matching files
71+
-0 # NUL-delimited output
72+
)
6273

63-
# Add all excluded prefixes to prune group
6474
for ex in "${EXCLUDED_PATH_PREFIXES[@]}"; do
65-
find_cmd+=( -o -path "./$ex" )
75+
rg_args+=( --glob "!$ex/**" )
6676
done
6777

68-
# Close prune group, then search for go files
69-
find_cmd+=( \) -prune -o -type f -name '*.go' ! -name '*_test.go' -print0 )
70-
71-
# Find all non-test .go files that import logrus, respecting exclusions
72-
mapfile -t FILES < <(
73-
"${find_cmd[@]}" \
74-
| xargs -0 -r grep -Il "$LOGRUS_IMPORT" \
75-
|| true
78+
# 1) Use ripgrep to find all non-test .go files that import logrus.
79+
mapfile -d '' -t FILES < <(
80+
"${rg_args[@]}" . || true
7681
)
7782

78-
# Collect unique directories containing such files
83+
# 2) Collect unique directories containing such files (is_excluded is now redundant but harmless)
7984
declare -A DIRS=()
8085
for f in "${FILES[@]}"; do
8186
dir="$(dirname "$f")"
@@ -85,6 +90,7 @@ for f in "${FILES[@]}"; do
8590
DIRS["$dir"]=1
8691
done
8792

93+
# 3) For each directory, (re)generate log.go
8894
for dir in "${!DIRS[@]}"; do
8995
# Collect Go files in this directory
9096
shopt -s nullglob

0 commit comments

Comments
 (0)