Skip to content

Commit 5c32e2c

Browse files
manusaclaude
andcommitted
fix(scripts): make check-authors work on macOS bash 3.2
The script aborted immediately on macOS with "declare: -A: invalid option". It relied on four constructs unavailable there: associative arrays and readarray (bash 4.0+), the -v array-key test (bash 4.2+), and grep -oP with \K (GNU grep; /usr/bin/grep rejects -P). Replaces them with an indexed array plus the script's existing array_contains helper, while-read loops, and a POSIX sed expression. Empty-array expansions now use the ${arr[@]+...} idiom already used elsewhere, since bash 3.2 under `set -u` errors on "${empty[@]}". The known-authors scan also excludes */target/* so it matches the file-discovery filter and is unaffected by whether a build has run. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Marc Nuri <marc@marcnuri.com>
1 parent 136cae4 commit 5c32e2c

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

‎scripts/check-authors.sh‎

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,24 @@ fi
6868

6969
# Build list of known authors from all @author tags in the codebase
7070
echo "Building list of known authors from codebase..."
71-
declare -A KNOWN_AUTHORS
71+
KNOWN_AUTHORS=()
7272
while IFS= read -r author; do
7373
if [[ -n "$author" ]]; then
74-
KNOWN_AUTHORS["$author"]=1
74+
KNOWN_AUTHORS+=("$author")
7575
fi
76-
done < <(grep -rhoP '@author\s+\K.+' --include="*.java" . 2>/dev/null | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | sort -u)
76+
done < <(find . -name "*.java" -type f ! -path "*/target/*" \
77+
-exec sed -n 's/.*@author[[:space:]][[:space:]]*//p' {} + \
78+
| sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | sort -u)
7779

7880
if [[ "$VERBOSE" == true ]]; then
79-
echo "Known authors: ${!KNOWN_AUTHORS[*]}"
81+
echo "Known authors: ${KNOWN_AUTHORS[*]+"${KNOWN_AUTHORS[*]}"}"
8082
fi
8183
echo ""
8284

8385
# Extract @author tags from a Java file
8486
get_javadoc_authors() {
8587
local file="$1"
86-
grep -oP '@author\s+\K.+' "$file" 2>/dev/null | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' || true
88+
sed -n 's/.*@author[[:space:]][[:space:]]*//p' "$file" 2>/dev/null | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' || true
8789
}
8890

8991
# Get git contributors for a file
@@ -112,23 +114,33 @@ MISSING_AUTHORS_TOTAL=0
112114
echo "Checking Java files for author information..."
113115
echo ""
114116

115-
for file in "${FILES[@]}"; do
117+
for file in "${FILES[@]+"${FILES[@]}"}"; do
116118
if [[ ! -f "$file" ]]; then
117119
continue
118120
fi
119121

120122
((TOTAL_FILES++)) || true
121123

122124
# Get authors from JavaDoc
123-
readarray -t javadoc_authors < <(get_javadoc_authors "$file")
125+
javadoc_authors=()
126+
while IFS= read -r author; do
127+
if [[ -n "$author" ]]; then
128+
javadoc_authors+=("$author")
129+
fi
130+
done < <(get_javadoc_authors "$file")
124131

125132
# Get authors from git history
126-
readarray -t git_authors < <(get_git_authors "$file")
133+
git_authors=()
134+
while IFS= read -r author; do
135+
if [[ -n "$author" ]]; then
136+
git_authors+=("$author")
137+
fi
138+
done < <(get_git_authors "$file")
127139

128140
# Filter to only known authors (ignore unknown git usernames)
129141
known_git_authors=()
130-
for author in "${git_authors[@]}"; do
131-
if [[ -n "$author" ]] && [[ -v "KNOWN_AUTHORS[$author]" ]]; then
142+
for author in "${git_authors[@]+"${git_authors[@]}"}"; do
143+
if array_contains "$author" "${KNOWN_AUTHORS[@]+"${KNOWN_AUTHORS[@]}"}"; then
132144
if ! array_contains "$author" "${known_git_authors[@]+"${known_git_authors[@]}"}"; then
133145
known_git_authors+=("$author")
134146
fi

0 commit comments

Comments
 (0)