Skip to content

Commit e3bd71e

Browse files
committed
fix(hooks): support macOS bash in qa-changed
1 parent a7cdd91 commit e3bd71e

1 file changed

Lines changed: 88 additions & 50 deletions

File tree

bin/qa-changed

Lines changed: 88 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ while [[ $# -gt 0 ]]; do
5353
esac
5454
done
5555

56+
changed_files=()
5657
if [[ ${#packages[@]} -eq 0 && $run_all -eq 0 ]]; then
5758
if [[ -z "$base_ref" ]]; then
5859
if upstream_ref=$(git -C "$ROOT_DIR" rev-parse --abbrev-ref --symbolic-full-name '@{upstream}' 2>/dev/null); then
@@ -67,36 +68,59 @@ if [[ ${#packages[@]} -eq 0 && $run_all -eq 0 ]]; then
6768
fi
6869

6970
range="$base_ref...$head_ref"
70-
mapfile -t changed_files < <(git -C "$ROOT_DIR" diff --name-only "$range" -- 'packages/pi-packages/**')
71-
72-
for file in "${changed_files[@]}"; do
73-
if [[ "$file" =~ ^packages/pi-packages/(pi-[^/]+)/ ]]; then
74-
packages+=("${BASH_REMATCH[1]}")
75-
fi
76-
done
71+
while IFS= read -r file; do
72+
changed_files+=("$file")
73+
done < <(git -C "$ROOT_DIR" diff --name-only "$range" -- 'packages/pi-packages/**')
74+
75+
if [[ ${#changed_files[@]} -gt 0 ]]; then
76+
for file in "${changed_files[@]}"; do
77+
if [[ "$file" =~ ^packages/pi-packages/(pi-[^/]+)/ ]]; then
78+
packages+=("${BASH_REMATCH[1]}")
79+
fi
80+
done
81+
fi
7782
else
78-
mapfile -t changed_files < <(git -C "$ROOT_DIR" diff --name-only "${base_ref:-HEAD~1}...$head_ref" -- 'packages/pi-packages/**' 2>/dev/null || true)
83+
while IFS= read -r file; do
84+
changed_files+=("$file")
85+
done < <(git -C "$ROOT_DIR" diff --name-only "${base_ref:-HEAD~1}...$head_ref" -- 'packages/pi-packages/**' 2>/dev/null || true)
7986
fi
8087

8188
if [[ $run_all -eq 1 ]]; then
82-
mapfile -t packages < <(find "$ROOT_DIR/packages/pi-packages" -mindepth 1 -maxdepth 1 -type d -name 'pi-*' -exec basename {} \; | sort)
89+
while IFS= read -r package; do
90+
packages+=("$package")
91+
done < <(find "$ROOT_DIR/packages/pi-packages" -mindepth 1 -maxdepth 1 -type d -name 'pi-*' -exec basename {} \; | sort)
8392
fi
8493

8594
if [[ ${#packages[@]} -eq 0 ]]; then
8695
echo "qa-changed: no packages/pi-packages changes detected"
8796
exit 0
8897
fi
8998

90-
mapfile -t packages < <(printf '%s\n' "${packages[@]}" | sed '/^$/d' | sort -u)
99+
unique_packages=()
100+
while IFS= read -r package; do
101+
unique_packages+=("$package")
102+
done < <(
103+
if [[ ${#packages[@]} -gt 0 ]]; then
104+
printf '%s\n' "${packages[@]}" | sed '/^$/d' | sort -u
105+
fi
106+
)
107+
packages=()
108+
if [[ ${#unique_packages[@]} -gt 0 ]]; then
109+
for package in "${unique_packages[@]}"; do
110+
packages+=("$package")
111+
done
112+
fi
91113

92114
echo "qa-changed: checking packages: ${packages[*]}"
93115

94116
arch_files=()
95-
for file in "${changed_files[@]}"; do
96-
if [[ -f "$ROOT_DIR/$file" && "$file" =~ ^packages/pi-packages/pi-[^/]+/.*\.tsx?$ ]]; then
97-
arch_files+=("$file")
98-
fi
99-
done
117+
if [[ ${#changed_files[@]} -gt 0 ]]; then
118+
for file in "${changed_files[@]}"; do
119+
if [[ -f "$ROOT_DIR/$file" && "$file" =~ ^packages/pi-packages/pi-[^/]+/.*\.tsx?$ ]]; then
120+
arch_files+=("$file")
121+
fi
122+
done
123+
fi
100124

101125
if [[ ${#arch_files[@]} -gt 0 ]]; then
102126
./bin/lint-ts-architecture "${arch_files[@]}"
@@ -116,33 +140,42 @@ fi
116140

117141
existing_packages=()
118142
removed_packages=()
119-
for pkg in "${packages[@]}"; do
120-
if [[ -f "$ROOT_DIR/packages/pi-packages/$pkg/package.json" ]]; then
121-
existing_packages+=("$pkg")
122-
else
123-
removed_packages+=("$pkg")
124-
fi
125-
done
143+
if [[ ${#packages[@]} -gt 0 ]]; then
144+
for pkg in "${packages[@]}"; do
145+
if [[ -f "$ROOT_DIR/packages/pi-packages/$pkg/package.json" ]]; then
146+
existing_packages+=("$pkg")
147+
else
148+
removed_packages+=("$pkg")
149+
fi
150+
done
151+
fi
126152

127153
if [[ ${#removed_packages[@]} -gt 0 ]]; then
128154
echo "qa-changed: skipping removed packages: ${removed_packages[*]}"
129155
fi
130-
packages=("${existing_packages[@]}")
156+
packages=()
157+
if [[ ${#existing_packages[@]} -gt 0 ]]; then
158+
for pkg in "${existing_packages[@]}"; do
159+
packages+=("$pkg")
160+
done
161+
fi
131162

132163
run_integration=0
133164
if [[ $run_all -eq 1 ]]; then
134165
run_integration=1
135166
else
136-
for file in "${changed_files[@]}"; do
137-
if [[ "$file" == packages/pi-packages/tests/* || "$file" == packages/pi-packages/package.json ]]; then
138-
run_integration=1
139-
break
140-
fi
141-
if [[ "$file" == packages/pi-packages/bun.lock && ${#packages[@]} -gt 0 ]]; then
142-
run_integration=1
143-
break
144-
fi
145-
done
167+
if [[ ${#changed_files[@]} -gt 0 ]]; then
168+
for file in "${changed_files[@]}"; do
169+
if [[ "$file" == packages/pi-packages/tests/* || "$file" == packages/pi-packages/package.json ]]; then
170+
run_integration=1
171+
break
172+
fi
173+
if [[ "$file" == packages/pi-packages/bun.lock && ${#packages[@]} -gt 0 ]]; then
174+
run_integration=1
175+
break
176+
fi
177+
done
178+
fi
146179
fi
147180

148181
if [[ ${#packages[@]} -eq 0 && $run_integration -eq 0 ]]; then
@@ -160,12 +193,14 @@ done < <(find "$ROOT_DIR/packages/pi-packages" -mindepth 2 -maxdepth 2 -type l -
160193

161194
restore_symlinked_node_modules() {
162195
local record link_path link_target
163-
for record in "${symlinked_node_modules[@]}"; do
164-
link_path="${record%%=*}"
165-
link_target="${record#*=}"
166-
rm -rf "$link_path"
167-
ln -s "$link_target" "$link_path"
168-
done
196+
if [[ ${#symlinked_node_modules[@]} -gt 0 ]]; then
197+
for record in "${symlinked_node_modules[@]}"; do
198+
link_path="${record%%=*}"
199+
link_target="${record#*=}"
200+
rm -rf "$link_path"
201+
ln -s "$link_target" "$link_path"
202+
done
203+
fi
169204
}
170205
trap restore_symlinked_node_modules EXIT
171206

@@ -180,19 +215,22 @@ has_script() {
180215
jq -e --arg script_name "$script_name" '.scripts[$script_name] != null' "$pkg_json" >/dev/null
181216
}
182217

183-
for pkg in "${packages[@]}"; do
184-
pkg_dir="$ROOT_DIR/packages/pi-packages/$pkg"
218+
if [[ ${#packages[@]} -gt 0 ]]; then
219+
for pkg in "${packages[@]}"; do
220+
pkg_dir="$ROOT_DIR/packages/pi-packages/$pkg"
185221

186-
if has_script "$pkg_dir" typecheck; then
187-
echo "qa-changed: $pkg -> typecheck"
188-
(cd "$pkg_dir" && bun run --silent typecheck)
189-
fi
222+
if has_script "$pkg_dir" typecheck; then
223+
echo "qa-changed: $pkg -> typecheck"
224+
(cd "$pkg_dir" && bun run --silent typecheck)
225+
fi
226+
227+
if has_script "$pkg_dir" test; then
228+
echo "qa-changed: $pkg -> test"
229+
(cd "$pkg_dir" && bun run --silent test)
230+
fi
231+
done
232+
fi
190233

191-
if has_script "$pkg_dir" test; then
192-
echo "qa-changed: $pkg -> test"
193-
(cd "$pkg_dir" && bun run --silent test)
194-
fi
195-
done
196234

197235
if [[ $run_integration -eq 1 ]]; then
198236
echo "qa-changed: running packages/pi-packages integration tests"

0 commit comments

Comments
 (0)