From 59b4a395ebb6aece7e6145727be9a1ceaeb6b164 Mon Sep 17 00:00:00 2001 From: Shuhuan Yan <71528407+syan-tibco@users.noreply.github.com> Date: Thu, 6 Jun 2024 23:16:22 -0500 Subject: [PATCH] [PDP-2797] adjust git clone for public repo (#1) --- charts/common-dependency/Chart.yaml | 2 +- .../common-dependency/scripts/_functions.sh | 28 +++++++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/charts/common-dependency/Chart.yaml b/charts/common-dependency/Chart.yaml index cf0566c..cc297d8 100644 --- a/charts/common-dependency/Chart.yaml +++ b/charts/common-dependency/Chart.yaml @@ -6,7 +6,7 @@ apiVersion: v2 name: common-dependency -version: "1.0.5" +version: "1.0.6" appVersion: "1.0.0" description: common-dependency type: application diff --git a/charts/common-dependency/scripts/_functions.sh b/charts/common-dependency/scripts/_functions.sh index ca43d3c..a22e24b 100755 --- a/charts/common-dependency/scripts/_functions.sh +++ b/charts/common-dependency/scripts/_functions.sh @@ -511,25 +511,29 @@ function common::git_clone() { # git_hash is optional function git_clone() { - if [ -z "${GITHUB_TOKEN}" ]; then - # read github - common::debug "try to read github token from secret volume" - GITHUB_TOKEN=$(cat /tmp/secret-github/GITHUB_TOKEN) - if [ $? -ne 0 ]; then - common::err "GITHUB_TOKEN is not set and pipeline container does not mount secret for GITHUB_TOKEN as well." - return 1 - fi - fi - local REPO=${1} local BRANCH_NAME=${2} local GIT_FOLDER=${3} local GIT_HASH=${4} # optional + # by default use public repo + _git_url="https://${REPO}" + if [ -z "${GITHUB_TOKEN}" ]; then + # try token on secret volume + common::debug "try to read github token from secret volume" + if [[ -f /tmp/secret-github/GITHUB_TOKEN ]]; then + common::debug "read github token from secret volume" + GITHUB_TOKEN=$(cat /tmp/secret-github/GITHUB_TOKEN) + _git_url="https://${GITHUB_TOKEN}:x-oauth-basic@${REPO}" + fi + else + _git_url="https://${GITHUB_TOKEN}:x-oauth-basic@${REPO}" + fi + mkdir -p ${GIT_FOLDER} if [ -n "${GIT_HASH}" ]; then - git clone -q --branch "${BRANCH_NAME}" https://"${GITHUB_TOKEN}":x-oauth-basic@"${REPO}" "${GIT_FOLDER}" + git clone -q --branch "${BRANCH_NAME}" "${_git_url}" "${GIT_FOLDER}" if [ $? -ne 0 ]; then common::err "git clone error" return 1 @@ -549,7 +553,7 @@ function git_clone() { fi cd "${CURRENT_PATH}" || exit else - git clone -q --branch "${BRANCH_NAME}" --depth 1 https://"${GITHUB_TOKEN}":x-oauth-basic@"${REPO}" "${GIT_FOLDER}" + git clone -q --branch "${BRANCH_NAME}" --depth 1 "${_git_url}" "${GIT_FOLDER}" if [ $? -ne 0 ]; then common::err "git clone with branch ${BRANCH_NAME} error" return 1