Skip to content

Commit

Permalink
chore: get_all_manifests.sh: support tags and make it priority (opend…
Browse files Browse the repository at this point in the history
…atahub-io#1194)

Jira: https://issues.redhat.com/browse/RHOAIENG-11687

Current script is supposed to be used with branches since it uses
"git clone -b" while preparing tagged releases it is useful to fetch
tags. "git clone -b" can work with tags as well, but if the same
name branch exists it fetches the branch which is not desireable
behaviour if tagged release is being produced.

Try to fetch tag. If it fails fallback to branch.

GitHub discussion: opendatahub-io#1169 (comment)

Signed-off-by: Yauheni Kaliuta <[email protected]>
  • Loading branch information
ykaliuta authored Aug 21, 2024
1 parent 6acf1db commit d2caf7a
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions get_all_manifests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e
GITHUB_URL="https://github.com"

# component: notebook, dsp, kserve, dashbaord, cf/ray/kueue/trainingoperator, trustyai, modelmesh, modelregistry.
# in the format of "repo-org:repo-name:branch-name:source-folder:target-folder".
# in the format of "repo-org:repo-name:ref-name:source-folder:target-folder".
declare -A COMPONENT_MANIFESTS=(
["codeflare"]="opendatahub-io:codeflare-operator:main:config:codeflare"
["ray"]="opendatahub-io:kuberay:dev:ray-operator/config:ray"
Expand Down Expand Up @@ -49,21 +49,40 @@ fi
TMP_DIR=$(mktemp -d -t "odh-manifests.XXXXXXXXXX")
trap '{ rm -rf -- "$TMP_DIR"; }' EXIT

function git_fetch_ref()
{

local repo=$1
local ref=$2
local dir=$3
local git_fetch="git fetch -q --depth 1 $repo"

mkdir -p $dir
pushd $dir &>/dev/null
git init -q
# try tag first, avoid printing fatal: couldn't find remote ref
if ! $git_fetch refs/tags/$ref 2>/dev/null ; then
$git_fetch refs/heads/$ref
fi
git reset -q --hard FETCH_HEAD
popd &>/dev/null
}


for key in "${!COMPONENT_MANIFESTS[@]}"; do
echo -e "\033[32mCloning repo \033[33m${key}\033[32m:\033[0m ${COMPONENT_MANIFESTS[$key]}"
IFS=':' read -r -a repo_info <<< "${COMPONENT_MANIFESTS[$key]}"

repo_org="${repo_info[0]}"
repo_name="${repo_info[1]}"
repo_branch="${repo_info[2]}"
repo_ref="${repo_info[2]}"
source_path="${repo_info[3]}"
target_path="${repo_info[4]}"

repo_url="${GITHUB_URL}/${repo_org}/${repo_name}"
repo_dir=${TMP_DIR}/${key}
mkdir -p ${repo_dir}
git clone -q --depth 1 --branch ${repo_branch} ${repo_url} ${repo_dir}

git_fetch_ref ${repo_url} ${repo_ref} ${repo_dir}

mkdir -p ./opt/manifests/${target_path}
cp -rf ${repo_dir}/${source_path}/* ./opt/manifests/${target_path}
Expand Down

0 comments on commit d2caf7a

Please sign in to comment.