@@ -4,6 +4,11 @@ set -euo pipefail
44
55SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
66
7+ if ! command -v jq & > /dev/null; then
8+ echo " Required command 'jq' is not installed or not available in PATH." >&2
9+ exit 1
10+ fi
11+
712SKIP_LIST=(
813 " autoload-splitter"
914 " composer-changelogs"
@@ -18,27 +23,43 @@ SKIP_LIST=(
1823
1924# Detect number of CPU cores, defaulting to 4.
2025if command -v nproc & > /dev/null; then
21- CORES =$( nproc)
26+ DETECTED_CORES =$( nproc)
2227elif command -v sysctl & > /dev/null; then
23- CORES =$( sysctl -n hw.logicalcpu 2> /dev/null || echo 4)
28+ DETECTED_CORES =$( sysctl -n hw.logicalcpu 2> /dev/null || echo 4)
2429else
30+ DETECTED_CORES=4
31+ fi
32+
33+ MAX_CORES=8
34+ CORES=" ${CLONE_JOBS:- ${WPCLI_DEV_JOBS:- ${DETECTED_CORES} } } "
35+
36+ if ! [[ " ${CORES} " =~ ^[1-9][0-9]* $ ]]; then
2537 CORES=4
38+ elif [[ -z " ${CLONE_JOBS:- } " && -z " ${WPCLI_DEV_JOBS:- } " && " ${CORES} " -gt " ${MAX_CORES} " ]]; then
39+ CORES=${MAX_CORES}
2640fi
2741
2842# Fetch repository list from the GitHub API.
29- CURL_OPTS=(-s )
43+ CURL_OPTS=(-fsS )
3044if [[ -n " ${GITHUB_TOKEN:- } " ]]; then
3145 CURL_OPTS+=(--header " Authorization: Bearer ${GITHUB_TOKEN} " )
3246fi
3347
34- RESPONSE=$( curl " ${CURL_OPTS[@]} " ' https://api.github.com/orgs/wp-cli/repos?per_page=100' )
48+ if ! RESPONSE=$( curl " ${CURL_OPTS[@]} " ' https://api.github.com/orgs/wp-cli/repos?per_page=100' ) ; then
49+ echo " Failed to fetch repository list from the GitHub API." >&2
50+ exit 1
51+ fi
3552
36- # Detect API errors such as rate limiting.
37- if echo " ${RESPONSE} " | jq -e ' .message' & > /dev/null; then
38- MESSAGE=$( echo " ${RESPONSE} " | jq -r ' .message' )
39- echo " GitHub responded with: ${MESSAGE} "
40- echo " If you are running into a rate limiting issue during large events please set GITHUB_TOKEN environment variable."
41- echo " See https://github.com/settings/tokens"
53+ # Validate the response shape and detect API errors such as rate limiting.
54+ if ! jq -e ' type == "array"' > /dev/null <<< " ${RESPONSE}" ; then
55+ if jq -e ' .message' > /dev/null <<< " ${RESPONSE}" ; then
56+ MESSAGE=$( jq -r ' .message' <<< " ${RESPONSE}" )
57+ echo " GitHub responded with: ${MESSAGE} " >&2
58+ echo " If you are running into a rate limiting issue during large events please set GITHUB_TOKEN environment variable." >&2
59+ echo " See https://github.com/settings/tokens" >&2
60+ else
61+ echo " GitHub API returned an unexpected response; expected a JSON array of repositories." >&2
62+ fi
4263 exit 1
4364fi
4465
@@ -85,5 +106,5 @@ if [[ ${#CLONE_LIST[@]} -gt 0 ]]; then
85106fi
86107
87108if [[ ${# UPDATE_FOLDERS[@]} -gt 0 ]]; then
88- printf ' %s\n' " ${UPDATE_FOLDERS[@]} " | xargs -n1 - P" ${CORES} " -I% php " ${SCRIPT_DIR} /refresh-repository.php" %
109+ printf ' %s\n' " ${UPDATE_FOLDERS[@]} " | xargs -P" ${CORES} " -I% php " ${SCRIPT_DIR} /refresh-repository.php" %
89110fi
0 commit comments