From 3f09cbee16ed315e6898137046599d8bc4678df3 Mon Sep 17 00:00:00 2001 From: Ruslan Aliev Date: Wed, 26 Mar 2025 12:30:01 -0500 Subject: [PATCH] Further improvements to chart_version.sh * added -euo pipefail to fail accordingly * removed unnecessary ";" * placed variables into quotes Change-Id: Iaeb639fe9af4a4b609033b05ef64a8180ee1738f Signed-off-by: Ruslan Aliev --- tools/chart_version.sh | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/tools/chart_version.sh b/tools/chart_version.sh index 80f52b13c3..186689c8be 100755 --- a/tools/chart_version.sh +++ b/tools/chart_version.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -euo pipefail + if [[ $# -lt 2 ]]; then echo "Usage: $0 " echo " - The chart directory." @@ -10,23 +12,16 @@ fi CHART_DIR=$1 BASE_VERSION=$2 -MAJOR=$(echo $BASE_VERSION | cut -d. -f1); -MINOR=$(echo $BASE_VERSION | cut -d. -f2); +MAJOR=$(echo "$BASE_VERSION" | cut -d. -f1) +MINOR=$(echo "$BASE_VERSION" | cut -d. -f2) -if git show-ref --tags $BASE_VERSION --quiet; then +if git show-ref --tags "$BASE_VERSION" --quiet; then # if there is tag $BASE_VERSION, then we count the number of commits since the tag - PATCH=$(git log --oneline ${BASE_VERSION}.. $CHART_DIR | wc -l | xargs) + PATCH=$(git log --oneline "${BASE_VERSION}.." "$CHART_DIR" | wc -l | xargs) else # if there is no tag $BASE_VERSION, then we count the number of commits since the beginning - PATCH=$(git log --oneline $CHART_DIR | wc -l | xargs) + PATCH=$(git log --oneline "$CHART_DIR" | wc -l | xargs) fi -COMMIT_SHA=$(git rev-parse --short HEAD); -OSH_INFRA_COMMIT_SHA=$(cd ../openstack-helm-infra; git rev-parse --short HEAD); -if [[ ${COMMIT_SHA} = ${OSH_INFRA_COMMIT_SHA} ]]; then - BUILD_META=${COMMIT_SHA} -else - BUILD_META=${COMMIT_SHA}-${OSH_INFRA_COMMIT_SHA} -fi - -echo "${MAJOR}.${MINOR}.${PATCH}+${BUILD_META}" +COMMIT_SHA=$(git rev-parse --short HEAD) +echo "${MAJOR}.${MINOR}.${PATCH}+${COMMIT_SHA}"