Skip to content

Commit

Permalink
Merge "Get version for tag based on number of git commits"
Browse files Browse the repository at this point in the history
  • Loading branch information
MOS CI authored and Gerrit Code Review committed Nov 15, 2024
2 parents ea26ed4 + d2768e4 commit 1cec690
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions tools/get_version.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
#!/bin/bash

# Returns version for helm chart
# Returns version for os controller image
# <tag>: if current commit is tagged
# <latest-tag+1>-<sha> - if current commit in other branches
# <latest-tag+1>-<devVersion> - if current commit in other branches

REPO_DIR=$(cd $(dirname "$0")/../ && pwd)
GIT_SHA=$(git -C $REPO_DIR rev-parse --short HEAD)

if git -C $REPO_DIR describe --exact-match --tags ${GIT_SHA} > /dev/null 2>&1; then
GIT_TAG=$(git -C $REPO_DIR describe --exact-match --tags ${GIT_SHA})
IMG_TAG="${GIT_TAG}"
else
GIT_LATEST_TAG=$(git -C $REPO_DIR describe --tags --abbrev=0)
tag_part1=$(echo ${GIT_LATEST_TAG} | awk -F '.' '{print $1}')
tag_part2=$(echo ${GIT_LATEST_TAG} | awk -F '.' '{print $2}')
tag_part3=$(echo ${GIT_LATEST_TAG} | awk -F '.' '{print $3}')
next_tag="${tag_part1}.${tag_part2}.$(( tag_part3 + 1 ))"
IMG_TAG="${next_tag}-${GIT_SHA}"
fi
# Fetch version with setup.py to align with PBR's version calculation.
# Using rev-list may lead to confusion as it doesn't match PBR logic.
pushd $REPO_DIR > /dev/null
IMG_TAG=$(python3 setup.py --version 2>/dev/null | grep -v "Generating ChangeLog" | sed 's/.dev/-dev/g')
popd > /dev/null
echo $IMG_TAG

0 comments on commit 1cec690

Please sign in to comment.