Skip to content

Commit f7aaebe

Browse files
committed
fix: split script exit code
1 parent 9bcfacf commit f7aaebe

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

tools/split.sh

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,29 @@ done < <(jq -r 'to_entries[] | "\(.key)=\(.value)"' "$OVERRIDES_FILE")
4545
split_package() {
4646
local package="$1"
4747
local repo="${OVERRIDES[$package]:-$package}"
48+
local label="$package -> $ORG/$repo"
4849

49-
echo "[split] $package -> $ORG/$repo"
50+
local sha stats
51+
stats=$(splitsh-lite --prefix="src/$package" 2>&1 >/tmp/splitsh-sha-$$-"$package")
52+
sha=$(cat /tmp/splitsh-sha-$$-"$package")
53+
rm -f /tmp/splitsh-sha-$$-"$package"
5054

51-
local sha
52-
sha=$(splitsh-lite --prefix="src/$package")
55+
if [[ -z "$sha" ]]; then
56+
echo "[error] $label - splitsh-lite failed"
57+
return 1
58+
fi
5359

5460
if [[ "$DRY_RUN" == true ]]; then
55-
echo "[dry-run] Would push $sha to $ORG/$repo ($BRANCH)"
61+
echo "[dry-run] $label: $stats"
5662
return
5763
fi
5864

59-
git push --quiet --force "https://x-access-token@github.com/${ORG}/${repo}.git" "$sha:refs/heads/$BRANCH"
60-
61-
echo "[split] $package done"
65+
if git push --quiet --force "https://x-access-token@github.com/${ORG}/${repo}.git" "$sha:refs/heads/$BRANCH" 2>/dev/null; then
66+
echo "[ok] $label ($stats)"
67+
else
68+
echo "[error] $label - push failed"
69+
return 1
70+
fi
6271
}
6372

6473
cd "$REPO_ROOT"
@@ -71,18 +80,30 @@ done
7180

7281
echo "Splitting ${#packages[@]} packages (max $MAX_PARALLEL parallel)..."
7382

74-
# Run splits in parallel batches
83+
# Run splits in parallel batches, tracking failures
84+
failed=0
7585
running=0
7686
for package in "${packages[@]}"; do
7787
split_package "$package" &
7888
running=$((running + 1))
7989

8090
if [[ $running -ge $MAX_PARALLEL ]]; then
81-
wait -n
91+
wait -n || ((failed++))
8292
running=$((running - 1))
8393
fi
8494
done
8595

86-
wait
96+
# Wait for remaining jobs
97+
while [[ $running -gt 0 ]]; do
98+
wait -n || ((failed++))
99+
running=$((running - 1))
100+
done
101+
87102
rm -f "$GIT_ASKPASS_SCRIPT"
103+
104+
if [[ $failed -gt 0 ]]; then
105+
echo "$failed package(s) failed to split."
106+
exit 1
107+
fi
108+
88109
echo "All ${#packages[@]} packages split successfully."

0 commit comments

Comments
 (0)