Skip to content

Commit d4e34d2

Browse files
committed
Sync all repositories in a single parallel pass
`composer install` and `composer update` run clone-all-repositories.sh, which cloned missing repositories in one parallel pass and then refreshed every repository in a second one. The barrier between the two stages left cores idle: the refresh pass could not start until the slowest clone finished, and on a fresh checkout the whole refresh pass was wasted work because a freshly cloned repository is already up to date. sync-repository.sh collapses both stages into one task per repository: clone when the folder is missing, refresh when it is not. That lets the script run a single continuous parallel pass that keeps every slot busy until the last repository is done. The pass now renders through peek.php, so each repository gets its own line showing what it is doing and how long it has taken, instead of ~90 repositories interleaving their git output into one stream. Running behind that display means an interactive prompt would be overdrawn the moment it appeared and would hang the run waiting for input nobody can see. Git and ssh prompt on /dev/tty rather than stdin, so prompting is disabled outright and failures surface as visible errors in the job's own lane instead: - GIT_TERMINAL_PROMPT=0 stops git asking for credentials. - BatchMode=yes makes ssh fail instead of asking for a passphrase or host key confirmation; keys served by an ssh-agent keep working. It is only applied when GIT_SSH_COMMAND is not already customized. - GIT_MERGE_AUTOEDIT=no keeps a non-fast-forward pull from opening an editor.
1 parent 18bb9eb commit d4e34d2

2 files changed

Lines changed: 64 additions & 16 deletions

File tree

‎.maintenance/clone-all-repositories.sh‎

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,29 @@
33
set -euo pipefail
44

55
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
export SCRIPT_DIR
7+
8+
# peek.php renders a live lane of output per parallel job. Its use is
9+
# optional: it degrades to a plain passthrough on platforms that cannot
10+
# support the display (e.g. Windows) and can be disabled with NO_PEEK=1.
11+
PEEK_PHP="${SCRIPT_DIR}/peek.php"
12+
export PEEK_PHP
13+
14+
# Parallel jobs run behind the peek display, where an interactive prompt is
15+
# instantly overdrawn and would hang the run waiting for input nobody can
16+
# see. Git and ssh prompt on /dev/tty (not stdin), so disable prompting
17+
# entirely: failures then surface as visible errors in the job's lane.
18+
# - GIT_TERMINAL_PROMPT=0: no credential/username prompts from git itself.
19+
# - BatchMode=yes: ssh fails instead of asking for passphrases or host key
20+
# confirmation (keys served by an ssh-agent keep working). Only set when
21+
# GIT_SSH_COMMAND is not already customized.
22+
# - GIT_MERGE_AUTOEDIT=no: a non-fast-forward pull keeps the default merge
23+
# message instead of opening an editor.
24+
export GIT_TERMINAL_PROMPT=0
25+
export GIT_MERGE_AUTOEDIT=no
26+
if [[ -z "${GIT_SSH_COMMAND:-}" ]]; then
27+
export GIT_SSH_COMMAND="ssh -oBatchMode=yes"
28+
fi
629

730
if ! command -v jq &>/dev/null; then
831
echo "Required command 'jq' is not installed or not available in PATH." >&2
@@ -80,8 +103,11 @@ get_destination() {
80103
fi
81104
}
82105

83-
CLONE_LIST=()
84-
UPDATE_FOLDERS=()
106+
# One task per repository: sync-repository.sh clones missing folders and
107+
# refreshes existing ones. Running a single parallel pass over all
108+
# repositories keeps all ${CORES} slots busy for the whole run, instead of
109+
# a clone stage and a refresh stage separated by a barrier.
110+
TASK_LIST=()
85111

86112
while IFS=$'\t' read -r name clone_url ssh_url; do
87113
if is_skipped "${name}"; then
@@ -90,21 +116,14 @@ while IFS=$'\t' read -r name clone_url ssh_url; do
90116

91117
destination=$(get_destination "${name}")
92118

93-
if [[ ! -d "${destination}" ]]; then
94-
if [[ -n "${GITHUB_ACTION:-}" ]]; then
95-
CLONE_LIST+=("${destination}"$'\t'"${clone_url}")
96-
else
97-
CLONE_LIST+=("${destination}"$'\t'"${ssh_url}")
98-
fi
119+
if [[ -n "${GITHUB_ACTION:-}" ]]; then
120+
TASK_LIST+=("${destination}"$'\t'"${clone_url}")
121+
else
122+
TASK_LIST+=("${destination}"$'\t'"${ssh_url}")
99123
fi
100-
101-
UPDATE_FOLDERS+=("${destination}")
102124
done < <(echo "${RESPONSE}" | jq -r '.[] | [.name, .clone_url, .ssh_url] | @tsv')
103125

104-
if [[ ${#CLONE_LIST[@]} -gt 0 ]]; then
105-
printf '%s\n' "${CLONE_LIST[@]}" | xargs -n2 -P"${CORES}" bash "${SCRIPT_DIR}/clone-repository.sh"
106-
fi
107-
108-
if [[ ${#UPDATE_FOLDERS[@]} -gt 0 ]]; then
109-
printf '%s\n' "${UPDATE_FOLDERS[@]}" | xargs -P"${CORES}" -I% php "${SCRIPT_DIR}/refresh-repository.php" %
126+
if [[ ${#TASK_LIST[@]} -gt 0 ]]; then
127+
printf '%s\n' "${TASK_LIST[@]}" | php "${PEEK_PHP}" -- xargs -n2 -P"${CORES}" \
128+
bash -c 'exec php "${PEEK_PHP}" run -n "$1" -- bash "${SCRIPT_DIR}/sync-repository.sh" "$1" "$2"' _
110129
fi

‎.maintenance/sync-repository.sh‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
# Bring a single repository up to date: clone it if the folder is missing,
4+
# refresh it otherwise. Freshly cloned repositories are already current, so
5+
# they skip the refresh. This lets the caller run one continuous parallel
6+
# pass over all repositories instead of a clone stage and a refresh stage
7+
# separated by a barrier.
8+
9+
set -euo pipefail
10+
11+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12+
13+
if [[ $# -lt 1 ]]; then
14+
echo "Usage: sync-repository.sh <destination> [<clone_url>]" >&2
15+
exit 1
16+
fi
17+
18+
destination="$1"
19+
clone_url="${2:-}"
20+
21+
if [[ ! -d "${destination}" ]]; then
22+
if [[ -z "${clone_url}" ]]; then
23+
echo "Folder '${destination}' is missing and no clone URL was provided." >&2
24+
exit 1
25+
fi
26+
exec bash "${SCRIPT_DIR}/clone-repository.sh" "${destination}" "${clone_url}"
27+
fi
28+
29+
exec php "${SCRIPT_DIR}/refresh-repository.php" "${destination}"

0 commit comments

Comments
 (0)