Skip to content

Commit

Permalink
feat: get_git_ref_from_container_tag
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbourianes-kalisio committed May 16, 2024
1 parent fa6e4b4 commit d8245ef
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
31 changes: 31 additions & 0 deletions kash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,37 @@ get_flavor_from_git() {
fi
}

# Returns the git ref that produced the given container tag.
# Eg.
# - container tag is 2.2.0-test => git ref = test-v2.2
# - container tag is 2.2.2-prod => git ref = prod-v2.2.2
# - container tag is 2.2.2-dev => git ref = master
# Expected args:
# 1. the container tag
get_git_ref_from_container_tag() {
local CONTAINER_TAG=$1
local CONTAINER_TAG_REGEX="^([0-9]+\.[0-9]+\.[0-9]+)-(.*)$"
if [[ "$CONTAINER_TAG" =~ $CONTAINER_TAG_REGEX ]]; then
if [ "${BASH_REMATCH[2]}" = "prod" ]; then
# Prod container => tag is prod-v1.2.3
printf "%s-v%s" "${BASH_REMATCH[2]}" "${BASH_REMATCH[1]}"
elif [ "${BASH_REMATCH[2]}" = "test" ]; then
# Test container => branch is test-v1.2 (or just test)
printf "%s-v%s" "${BASH_REMATCH[2]}" "${BASH_REMATCH[1]%.*}"
else
# Dev container => branch is master
printf "master"
fi
fi

# Also possible to find just 'test' or 'dev' as container tags
if [ "$CONTAINER_TAG" = "test" ]; then
printf "test"
elif [ "$CONTAINER_TAG" = "dev" ]; then
printf "master"
fi
}

# Runs kli in a separate folder.
# Expected args:
# 1. the folder where to install everything
Expand Down
6 changes: 6 additions & 0 deletions scripts/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ setup_workspace "$TMP_DIR/fake" "https://github.com/kalisio/kApp.git" \
[ "$(get_flavor_from_git "$TMP_DIR/kApp.v1.3" )" != "test" ] && exit 1
[ "$(get_flavor_from_git "$TMP_DIR/kApp.v1.3.0" )" != "prod" ] && exit 1

[ "$(get_git_ref_from_container_tag "1.1.1-test")" != "test-v1.1" ] && exit 1
[ "$(get_git_ref_from_container_tag "test")" != "test" ] && exit 1
[ "$(get_git_ref_from_container_tag "1.1.1-prod")" != "prod-v1.1.1" ] && exit 1
[ "$(get_git_ref_from_container_tag "1.1.1-dev")" != "master" ] && exit 1
[ "$(get_git_ref_from_container_tag "dev")" != "master" ] && exit 1

## App helpers

init_app_infos "$TMP_DIR/kApp.master" "$TMP_DIR/kli"
Expand Down

0 comments on commit d8245ef

Please sign in to comment.