Skip to content

Commit 53e6b36

Browse files
fix: init_app_infos kli file computation
1 parent dc480af commit 53e6b36

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

kash.sh

+46-1
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,39 @@ get_json_value() {
517517
yq --output-format=yaml ".$JSON_FIELD" "$JSON_SRC"
518518
}
519519

520+
# Extract version major from a version string.
521+
# Expected args:
522+
# 1. the version string
523+
get_semver_major() {
524+
local VERSION="$1"
525+
local VERSION_REGEX="^([0-9]+)(\.[0-9]+)?(\.[0-9]+)?$"
526+
if [[ "$VERSION" =~ $VERSION_REGEX ]]; then
527+
printf "%s" "${BASH_REMATCH[1]}"
528+
fi
529+
}
530+
531+
# Extract version minor from a version string.
532+
# Expected args:
533+
# 1. the version string
534+
get_semver_minor() {
535+
local VERSION="$1"
536+
local VERSION_REGEX="^[0-9]+\.([0-9]+)(\.[0-9]+)?$"
537+
if [[ "$VERSION" =~ $VERSION_REGEX ]]; then
538+
printf "%s" "${BASH_REMATCH[1]}"
539+
fi
540+
}
541+
542+
# Extract version minor from a version string.
543+
# Expected args:
544+
# 1. the version string
545+
get_semver_patch() {
546+
local VERSION="$1"
547+
local VERSION_REGEX="^[0-9]+\.[0-9]+\.([0-9]+)$"
548+
if [[ "$VERSION" =~ $VERSION_REGEX ]]; then
549+
printf "%s" "${BASH_REMATCH[1]}"
550+
fi
551+
}
552+
520553
### Git
521554
###
522555

@@ -1112,6 +1145,11 @@ setup_app_workspace() {
11121145
local DEVELOPMENT_DIR="$WORKSPACE_DIR/development"
11131146
git_shallow_clone "$DEVELOPMENT_REPO_URL" "$DEVELOPMENT_DIR"
11141147

1148+
# NOTE: we don't reuse init_app_infos here since init_app_infos
1149+
# fetch app version from package.json (it requires a cloned repo)
1150+
# Here we might be setting up workspace for a specific
1151+
# branch / tag that's not currently checked out.
1152+
11151153
# fetch app name and ref (tag or branch) required
11161154
local APP_NAME
11171155
APP_NAME=$(yq --output-format=yaml '.name' "$REPO_DIR/package.json")
@@ -1168,6 +1206,10 @@ init_app_infos() {
11681206
APP_NAME=$(yq --output-format=yaml '.name' "$REPO_ROOT/package.json")
11691207
local APP_VERSION
11701208
APP_VERSION=$(yq --output-format=yaml '.version' "$REPO_ROOT/package.json")
1209+
local APP_VERSION_MAJOR
1210+
local APP_VERSION_MINOR
1211+
APP_VERSION_MAJOR=$(get_semver_major "$APP_VERSION")
1212+
APP_VERSION_MINOR=$(get_semver_minor "$APP_VERSION")
11711213

11721214
local GIT_TAG
11731215
GIT_TAG=$(get_git_tag "$REPO_ROOT")
@@ -1182,9 +1224,12 @@ init_app_infos() {
11821224

11831225
local KLI_FILE="$KLI_BASE/$APP_NAME/$APP_FLAVOR/$APP_NAME"
11841226
case "$APP_FLAVOR" in
1185-
prod | test)
1227+
prod)
11861228
KLI_FILE="$KLI_FILE-$APP_VERSION"
11871229
;;
1230+
test)
1231+
KLI_FILE="$KLI_FILE-$APP_VERSION_MAJOR.$APP_VERSION_MINOR"
1232+
;;
11881233
*)
11891234
;;
11901235
esac

scripts/run_tests.sh

+13-1
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,23 @@ curl -OLsS "https://raw.githubusercontent.com/kalisio/krawler/master/package.jso
5151
[ "$(get_json_value "$TMP_DIR/utils/package.json" 'name')" != "@kalisio/krawler" ] && exit 1
5252
cd ~-
5353

54+
[ "$(get_semver_major "1" )" != "1" ] && exit 1
55+
[ "$(get_semver_major "1.5" )" != "1" ] && exit 1
56+
[ "$(get_semver_major "1.5.90" )" != "1" ] && exit 1
57+
[ "$(get_semver_major "abcd" )" != "" ] && exit 1
58+
59+
[ "$(get_semver_minor "10.4" )" != "4" ] && exit 1
60+
[ "$(get_semver_minor "10.5.0" )" != "5" ] && exit 1
61+
[ "$(get_semver_minor "abcd" )" != "" ] && exit 1
62+
63+
[ "$(get_semver_patch "10.4.59" )" != "59" ] && exit 1
64+
[ "$(get_semver_patch "abcd" )" != "" ] && exit 1
65+
5466
## Git helpers
5567

5668
case "$CI_ID" in
5769
github)
58-
[ "$(get_git_branch "$ROOT_DIR" )" != "$GITHUB_REF_NAME" ] && exit 1
70+
[ "''$(get_git_branch "$ROOT_DIR" )" != "$GITHUB_REF_NAME" ] && exit 1
5971
;;
6072
gitlab)
6173
[ "$(get_git_branch "$ROOT_DIR" )" != "$CI_COMMIT_REF_NAME" ] && exit 1

0 commit comments

Comments
 (0)