Skip to content

Commit

Permalink
update compute-build-args.sh to use yq
Browse files Browse the repository at this point in the history
  • Loading branch information
AyodeAwe committed Feb 27, 2024
1 parent 209ab38 commit 26ccfc6
Showing 1 changed file with 12 additions and 30 deletions.
42 changes: 12 additions & 30 deletions ci/compute-build-args.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#!/bin/bash
set -euo pipefail

if [[ -z "${CUDA_VER}" || -z "${LINUX_VER}" || -z "${PYTHON_VER}" || -z "${ARCH}" ]]; then
echo "Error: One or more required variables are not provided."
exit 1
fi

MANYLINUX_VER="manylinux_2_17"
if [[
"${LINUX_VER}" == "ubuntu18.04" ||
Expand All @@ -18,35 +13,22 @@ elif [[
MANYLINUX_VER="manylinux_2_28"
fi

ARGS=(
# common args
"CUDA_VER=${CUDA_VER}"
"LINUX_VER=${LINUX_VER}"
"PYTHON_VER=${PYTHON_VER}"
# wheel args
"CPU_ARCH=${ARCH}"
"REAL_ARCH=$(arch)"
"MANYLINUX_VER=${MANYLINUX_VER}"
)

YAML_FILE="versions.yaml"
if [ -f "$YAML_FILE" ]; then
while IFS= read -r line; do
key=$(echo "$line" | cut -f1 -d':')
value=$(echo "$line" | cut -f2 -d':')
ARGS+=("$key=${value}")
done < <(yq e '. | to_entries | .[] | .key + ":" + (.value | sub("^v"; ""))' "$YAML_FILE")
fi
ARGS="
CUDA_VER: ${CUDA_VER}
LINUX_VER: ${LINUX_VER}
PYTHON_VER: ${PYTHON_VER}
CPU_ARCH: ${ARCH}
REAL_ARCH: $(arch)
MANYLINUX_VER: ${MANYLINUX_VER}
"
export ARGS

set +u
if [ -n "$GITHUB_ACTIONS" ]; then
if [ -n "${GITHUB_ACTIONS:-}" ]; then
cat <<EOF > "${GITHUB_OUTPUT:-/dev/stdout}"
ARGS<<EOT
$(printf "%s\n" "${ARGS[@]}")
$(yq -r '. + env(ARGS) | to_entries | map(.key + "=" + .value) | join(" \n")' versions.yaml)
EOT
EOF
else
for arg in "${ARGS[@]}"; do
printf -- "--build-arg %s " "$arg"
done
yq -r '. + env(ARGS) | to_entries | map("--build-arg " + .key + "=" + .value) | join(" ")' versions.yaml
fi

0 comments on commit 26ccfc6

Please sign in to comment.