Skip to content

Commit

Permalink
fix: init_app_infos kli file computation
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbourianes-kalisio committed Mar 10, 2025
1 parent dc480af commit 53e6b36
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
47 changes: 46 additions & 1 deletion kash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,39 @@ get_json_value() {
yq --output-format=yaml ".$JSON_FIELD" "$JSON_SRC"
}

# Extract version major from a version string.
# Expected args:
# 1. the version string
get_semver_major() {
local VERSION="$1"
local VERSION_REGEX="^([0-9]+)(\.[0-9]+)?(\.[0-9]+)?$"
if [[ "$VERSION" =~ $VERSION_REGEX ]]; then
printf "%s" "${BASH_REMATCH[1]}"
fi
}

# Extract version minor from a version string.
# Expected args:
# 1. the version string
get_semver_minor() {
local VERSION="$1"
local VERSION_REGEX="^[0-9]+\.([0-9]+)(\.[0-9]+)?$"
if [[ "$VERSION" =~ $VERSION_REGEX ]]; then
printf "%s" "${BASH_REMATCH[1]}"
fi
}

# Extract version minor from a version string.
# Expected args:
# 1. the version string
get_semver_patch() {
local VERSION="$1"
local VERSION_REGEX="^[0-9]+\.[0-9]+\.([0-9]+)$"
if [[ "$VERSION" =~ $VERSION_REGEX ]]; then
printf "%s" "${BASH_REMATCH[1]}"
fi
}

### Git
###

Expand Down Expand Up @@ -1112,6 +1145,11 @@ setup_app_workspace() {
local DEVELOPMENT_DIR="$WORKSPACE_DIR/development"
git_shallow_clone "$DEVELOPMENT_REPO_URL" "$DEVELOPMENT_DIR"

# NOTE: we don't reuse init_app_infos here since init_app_infos
# fetch app version from package.json (it requires a cloned repo)
# Here we might be setting up workspace for a specific
# branch / tag that's not currently checked out.

# fetch app name and ref (tag or branch) required
local APP_NAME
APP_NAME=$(yq --output-format=yaml '.name' "$REPO_DIR/package.json")
Expand Down Expand Up @@ -1168,6 +1206,10 @@ init_app_infos() {
APP_NAME=$(yq --output-format=yaml '.name' "$REPO_ROOT/package.json")
local APP_VERSION
APP_VERSION=$(yq --output-format=yaml '.version' "$REPO_ROOT/package.json")
local APP_VERSION_MAJOR
local APP_VERSION_MINOR
APP_VERSION_MAJOR=$(get_semver_major "$APP_VERSION")
APP_VERSION_MINOR=$(get_semver_minor "$APP_VERSION")

local GIT_TAG
GIT_TAG=$(get_git_tag "$REPO_ROOT")
Expand All @@ -1182,9 +1224,12 @@ init_app_infos() {

local KLI_FILE="$KLI_BASE/$APP_NAME/$APP_FLAVOR/$APP_NAME"
case "$APP_FLAVOR" in
prod | test)
prod)
KLI_FILE="$KLI_FILE-$APP_VERSION"
;;
test)
KLI_FILE="$KLI_FILE-$APP_VERSION_MAJOR.$APP_VERSION_MINOR"
;;
*)
;;
esac
Expand Down
14 changes: 13 additions & 1 deletion scripts/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,23 @@ curl -OLsS "https://raw.githubusercontent.com/kalisio/krawler/master/package.jso
[ "$(get_json_value "$TMP_DIR/utils/package.json" 'name')" != "@kalisio/krawler" ] && exit 1
cd ~-

[ "$(get_semver_major "1" )" != "1" ] && exit 1
[ "$(get_semver_major "1.5" )" != "1" ] && exit 1
[ "$(get_semver_major "1.5.90" )" != "1" ] && exit 1
[ "$(get_semver_major "abcd" )" != "" ] && exit 1

[ "$(get_semver_minor "10.4" )" != "4" ] && exit 1
[ "$(get_semver_minor "10.5.0" )" != "5" ] && exit 1
[ "$(get_semver_minor "abcd" )" != "" ] && exit 1

[ "$(get_semver_patch "10.4.59" )" != "59" ] && exit 1
[ "$(get_semver_patch "abcd" )" != "" ] && exit 1

## Git helpers

case "$CI_ID" in
github)
[ "$(get_git_branch "$ROOT_DIR" )" != "$GITHUB_REF_NAME" ] && exit 1
[ "''$(get_git_branch "$ROOT_DIR" )" != "$GITHUB_REF_NAME" ] && exit 1
;;
gitlab)
[ "$(get_git_branch "$ROOT_DIR" )" != "$CI_COMMIT_REF_NAME" ] && exit 1
Expand Down

0 comments on commit 53e6b36

Please sign in to comment.