diff --git a/features/src/rapids-build-utils/opt/rapids-build-utils/bin/generate-scripts.sh b/features/src/rapids-build-utils/opt/rapids-build-utils/bin/generate-scripts.sh index 5e4b9968..fa515ccd 100755 --- a/features/src/rapids-build-utils/opt/rapids-build-utils/bin/generate-scripts.sh +++ b/features/src/rapids-build-utils/opt/rapids-build-utils/bin/generate-scripts.sh @@ -40,6 +40,29 @@ generate_script() { fi } +generate_all_script_impl() { + local bin="$SCRIPT-all"; + if test -n "$bin" && ! test -f "/tmp/${bin}.sh"; then + cat - \ + | envsubst '$NAMES + $SCRIPT' \ + | sudo tee "/tmp/${bin}.sh" >/dev/null; + + sudo chmod +x "/tmp/${bin}.sh"; + + sudo update-alternatives --install \ + "/usr/bin/${bin}" "${bin}" "/tmp/${bin}.sh" 0 \ + >/dev/null 2>&1; + fi +} + +generate_all_script() { + ( + cat ${TMPL}/all.tmpl.sh \ + | generate_all_script_impl; + ) || true; +} + generate_clone_script() { ( cat ${TMPL}/clone.tmpl.sh \ @@ -97,6 +120,8 @@ generate_scripts() { local j; local k; + local repo_name_all=() + for ((i=0; i < ${repos_length:-0}; i+=1)); do local repo="repos_${i}"; @@ -110,6 +135,8 @@ generate_scripts() { repo_name="$(tr "[:upper:]" "[:lower:]" <<< "${!repo_name:-}")"; + repo_name_all+=($repo_name) + # Generate a clone script for each repo ( NAME="${repo_name:-}" \ @@ -215,6 +242,13 @@ generate_scripts() { -o -type f -exec chmod 0755 {} \; \); unset cpp_name_to_path; + + # Generate a script to clone all repos + ( + NAMES="${repo_name_all[@]}" \ + SCRIPT="clone" \ + generate_all_script ; + ) || true; } if test -n "${rapids_build_utils_debug:-}"; then diff --git a/features/src/rapids-build-utils/opt/rapids-build-utils/bin/tmpl/all.tmpl.sh b/features/src/rapids-build-utils/opt/rapids-build-utils/bin/tmpl/all.tmpl.sh new file mode 100755 index 00000000..89f779b4 --- /dev/null +++ b/features/src/rapids-build-utils/opt/rapids-build-utils/bin/tmpl/all.tmpl.sh @@ -0,0 +1,13 @@ +clone_all() { + set -euo pipefail; + + for name in $NAMES; do + clone-$name + done; +} + +if [[ -n "$devcontainer_utils_debug" ]]; then + PS4="+ ${BASH_SOURCE[0]}:\${LINENO} "; set -x; +fi + +clone_all "$@"; diff --git a/features/src/utils/opt/devcontainer/bin/github/repo/clone.sh b/features/src/utils/opt/devcontainer/bin/github/repo/clone.sh index bf2d974c..49e97c09 100755 --- a/features/src/utils/opt/devcontainer/bin/github/repo/clone.sh +++ b/features/src/utils/opt/devcontainer/bin/github/repo/clone.sh @@ -32,8 +32,7 @@ get_user_fork_name() { if [ "${user}" = "${owner}" ]; then echo "${owner}/${name}"; else - gh repo list "${user}" --fork --json nameWithOwner --json parent --jq "$(cat <<________EOF | tr -s '[:space:]' - . + local query="$(cat <<________EOF | tr -s '[:space:]' | map(select( .parent.name == "${name}" and @@ -42,6 +41,16 @@ get_user_fork_name() { | map(.nameWithOwner)[] ________EOF )"; + local nameWithOwner="$(gh repo list "${user}" --fork --json nameWithOwner --json parent --jq ". ${query}" 2>/dev/null || echo "")"; + if test -z "${nameWithOwner}"; then + for repo in $(gh repo list "${user}" --fork --json name --jq 'map(.name)[]'); do + nameWithOwner="$(gh repo view "${repo}" --json nameWithOwner --json parent --jq "[.] ${query}" 2>/dev/null || echo "")"; + if test -n "${nameWithOwner}"; then + break; + fi + done + fi + echo "${nameWithOwner:-}"; fi }