@@ -517,6 +517,39 @@ get_json_value() {
517
517
yq --output-format=yaml " .$JSON_FIELD " " $JSON_SRC "
518
518
}
519
519
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
+
520
553
# ## Git
521
554
# ##
522
555
@@ -1112,6 +1145,11 @@ setup_app_workspace() {
1112
1145
local DEVELOPMENT_DIR=" $WORKSPACE_DIR /development"
1113
1146
git_shallow_clone " $DEVELOPMENT_REPO_URL " " $DEVELOPMENT_DIR "
1114
1147
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
+
1115
1153
# fetch app name and ref (tag or branch) required
1116
1154
local APP_NAME
1117
1155
APP_NAME=$( yq --output-format=yaml ' .name' " $REPO_DIR /package.json" )
@@ -1168,6 +1206,10 @@ init_app_infos() {
1168
1206
APP_NAME=$( yq --output-format=yaml ' .name' " $REPO_ROOT /package.json" )
1169
1207
local APP_VERSION
1170
1208
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 " )
1171
1213
1172
1214
local GIT_TAG
1173
1215
GIT_TAG=$( get_git_tag " $REPO_ROOT " )
@@ -1182,9 +1224,12 @@ init_app_infos() {
1182
1224
1183
1225
local KLI_FILE=" $KLI_BASE /$APP_NAME /$APP_FLAVOR /$APP_NAME "
1184
1226
case " $APP_FLAVOR " in
1185
- prod | test )
1227
+ prod)
1186
1228
KLI_FILE=" $KLI_FILE -$APP_VERSION "
1187
1229
;;
1230
+ test)
1231
+ KLI_FILE=" $KLI_FILE -$APP_VERSION_MAJOR .$APP_VERSION_MINOR "
1232
+ ;;
1188
1233
* )
1189
1234
;;
1190
1235
esac
0 commit comments