Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Yuri Shkuro <github@ysh.us>
  • Loading branch information
yurishkuro committed Jul 27, 2024
1 parent 7bae809 commit c2f4edb
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions scripts/compute-tags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,7 @@ GITHUB_SHA=${GITHUB_SHA:?'expecting GITHUB_SHA env var'}
# allow substituting for ggrep on Mac, since its default grep doesn't grok -P flag.
GREP=${GREP:-"grep"}

## If we are on a release tag, let's extract the version number.
## The other possible values are 'main' or another branch name.
if [[ $BRANCH =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
MAJOR_MINOR_PATCH=$(echo "${BRANCH}" | ${GREP} -Po "([\d\.]+)")
MAJOR_MINOR=$(echo "${MAJOR_MINOR_PATCH}" | awk -F. '{print $1"."$2}')
MAJOR=$(echo "${MAJOR_MINOR_PATCH}" | awk -F. '{print $1}')
else
MAJOR_MINOR_PATCH="latest"
MAJOR_MINOR=""
MAJOR=""
fi

# accumulate output in this variable
IMAGE_TAGS=""

# append given tag for docker.io and quay.io
Expand All @@ -40,14 +29,19 @@ tags() {
}

tags "${BASE_BUILD_IMAGE}"
tags "${BASE_BUILD_IMAGE}:${MAJOR_MINOR_PATCH}"

if [ "${MAJOR_MINOR}x" != "x" ]; then
tags "${BASE_BUILD_IMAGE}:${MAJOR_MINOR}"
fi
## If we are on a release tag, let's extract the version number.
## The other possible values are 'main' or another branch name.
if [[ $BRANCH =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
MAJOR_MINOR_PATCH=$(echo "${BRANCH}" | ${GREP} -Po "([\d\.]+)")
MAJOR_MINOR=$(echo "${MAJOR_MINOR_PATCH}" | awk -F. '{print $1"."$2}')
MAJOR=$(echo "${MAJOR_MINOR_PATCH}" | awk -F. '{print $1}')

if [ "${MAJOR}x" != "x" ]; then
tags "${BASE_BUILD_IMAGE}:${MAJOR_MINOR_PATCH}"
tags "${BASE_BUILD_IMAGE}:${MAJOR_MINOR}"
tags "${BASE_BUILD_IMAGE}:${MAJOR}"
else
tags "${BASE_BUILD_IMAGE}:latest"
fi

tags "${BASE_BUILD_IMAGE}-snapshot:${GITHUB_SHA}"
Expand Down

0 comments on commit c2f4edb

Please # to comment.