From 2f34fb1536bf8ba9127fa74b6cde3b2e3d329dd3 Mon Sep 17 00:00:00 2001 From: garciadeblas Date: Fri, 26 Sep 2025 10:11:36 +0200 Subject: [PATCH] Update tools/change-chart-version.sh to work from Jenkins Change-Id: I2b31bf9a64b45fb5d158026c1f501d810997f512 Signed-off-by: garciadeblas --- tools/change-chart-version.sh | 62 ++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/tools/change-chart-version.sh b/tools/change-chart-version.sh index 358cd741..acafe020 100755 --- a/tools/change-chart-version.sh +++ b/tools/change-chart-version.sh @@ -13,33 +13,71 @@ # limitations under the License. # -if [ "$#" -ne 2 ]; then - echo "Usage: $0 " - echo "Example: $0 16.0.0 garciadeblas" - echo "Example: $0 15.0.7 vegall" +if [ "$#" -lt 2 ] || [ "$#" -gt 3 ]; then + echo "Usage: $0 []" + echo " Example: $0 16.0.0 garciadeblas" + echo " Example: $0 15.0.7 vegall" + echo "When is provided, it will be used for git https authentication. Otherwise, ssh authentication will be used." exit 1 fi NEW_VERSION="$1" -USER="$2" -REPO_URL="ssh://$USER@osm.etsi.org:29418/osm/devops" -# If the $NEW_VERSION == 15.0.1, the $BRANCH_NAME will be v15.0 +GIT_USER="$2" +GIT_PASSWORD="${3:-}" + BRANCH_NAME="v$(echo $NEW_VERSION | grep -oE '[0-9]+\.[0-9]+')" -git clone $REPO_URL && (cd "devops" && curl https://osm.etsi.org/gerrit/tools/hooks/commit-msg > .git/hooks/commit-msg ; chmod +x .git/hooks/commit-msg) -pushd devops +BASE_FOLDER=$(mktemp -d change-chart-version.XXXXXX) +pushd $BASE_FOLDER -git checkout $BRANCH_NAME +if [ -n "$GIT_PASSWORD" ]; then + REPO_URL="https://${GIT_USER}@osm.etsi.org/gerrit/a/osm/devops" + # Follow recommendation for user auth with git using a script git-creds.sh + cat << "EOF" > "${HOME}/git-creds.sh" +#!/bin/sh +if echo "$1" | grep -q '^Password'; then + echo "${GIT_PASSWORD}" +else + echo "${GIT_USER}" +fi +exit 0 +EOF + chmod +x "${HOME}/git-creds.sh" +else + REPO_URL="ssh://${GIT_USER}@osm.etsi.org:29418/osm/devops" +fi + +echo "Cloning devops repo" +if [ -n "$GIT_PASSWORD" ]; then + echo "Using https authentication" + GIT_USERNAME="${GIT_USER}" GIT_ASKPASS=~/git-creds.sh git clone "${REPO_URL}" +else + echo "Using ssh authentication" + git clone "${REPO_URL}" +fi +cd "devops" +curl https://osm.etsi.org/gerrit/tools/hooks/commit-msg > .git/hooks/commit-msg +chmod +x .git/hooks/commit-msg +git checkout $BRANCH_NAME sed -i -E "0,/^version: .*/s//version: \"$NEW_VERSION\"/" installers/helm/osm/Chart.yaml sed -i -E "0,/^appVersion: .*/s//appVersion: \"$NEW_VERSION\"/" installers/helm/osm/Chart.yaml git add installers/helm/osm/Chart.yaml git commit -s -m "Update chart version version to $NEW_VERSION" -git push origin $BRANCH_NAME + +echo "Pushing changes to devops repo" +if [ -n "$GIT_PASSWORD" ]; then + echo "Using https authentication" + GIT_USERNAME="${GIT_USER}" GIT_ASKPASS=~/git-creds.sh git push origin $BRANCH_NAME +else + echo "Using ssh authentication" + git push origin $BRANCH_NAME +fi commit=$(git show --summary | grep commit | awk '{print $2}') echo "The commit is $commit" -popd +cd .. rm -rf devops +popd -- 2.25.1