From 97948a5d8cd070b673521e83238510279a1d2dd6 Mon Sep 17 00:00:00 2001 From: bmamihai Date: Sun, 2 Apr 2023 01:17:18 +0300 Subject: [PATCH 1/2] added build commit no --- build.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/build.sh b/build.sh index 21971c9..ad7954b 100755 --- a/build.sh +++ b/build.sh @@ -33,18 +33,24 @@ key=" \"version\": \"" count=$(echo ${version%%-*} | grep -o "\." | wc -l) if (( $count > 1 )); then - version=${version%%-*} + version=${version%%-*} else - version="${version%%-*}.0" + if [[ "$1" == "dev" ]];then + cleanprefix=${version#*-} + cleansuffix=${cleanprefix%-*} + version="${version%%-*}.${cleansuffix}" + else + version="${version%%-*}.0" # one `%` remove everything after last `-`, two `%%` remove everything after all `-` + fi fi if [ -f "$file_pkg" ] && [ ! -z "$version" ]; then version=" \"version\": \"$version\"," sed -i "s|^.*$key.*|${version//\//\\/}|g" $file_pkg text=$(cat $file_pkg | grep -c "$version") if [ $text -eq 0 ]; then - echo "Version couldn't be set" + echo "Version couldn't be set" else - echo "Version $version successfully applied to App" + echo "Version $version successfully applied to App" fi fi -- 2.37.1 From 5da2eb6927a5f02b8a9c06a7ae3f6d14c2bd8cda Mon Sep 17 00:00:00 2001 From: bmamihai Date: Wed, 5 Apr 2023 01:57:58 +0300 Subject: [PATCH 2/2] update build.sh after review --- build.sh | 76 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 30 deletions(-) diff --git a/build.sh b/build.sh index ad7954b..fceecef 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,40 @@ #/!bin/bash +## FUNCTIONS +function getGitVersion(){ + version=$(git describe) + count=$(echo ${version%%-*} | grep -o "\." | wc -l) + if (( $count > 1 )); then + version=${version%%-*} + elif (( $count == 0 ));then + echo -e "Error: Git version \"${version%%-*}\" not respecting Safemobile standard.\n Must be like 4.xx or 4.xx.xx" + version="0.0.0" + else + if [[ "$1" == "dev" ]];then + cleanprefix=${version#*-} # remove everything before `-` including `-` + cleansuffix=${cleanprefix%-*} # remove everything after `-` including `-` + version="${version%%-*}.${cleansuffix}" + else + version="${version%%-*}.0" # one `%` remove everything after last `-`, two `%%` remove everything after all `-` + fi + fi +} + +function addVersionPm2(){ + file_pkg="package.json" + key=" \"version\": \"" + + if [ -f "$file_pkg" ] && [ ! -z "$version" ]; then + versionApp=" \"version\": \"$version\"," + sed -i "s|^.*$key.*|${versionApp//\//\\/}|g" $file_pkg + text=$(cat $file_pkg | grep -c "$version") + if [ $text -eq 0 ]; then + echo "Version couldn't be set" + else + echo "Version $version successfully applied to App" + fi + fi +} + ## PREBUILD PROCESS # check dist dir to be present and empty if [ ! -d "dist" ]; then @@ -22,37 +58,17 @@ echo "Building app... from $(git rev-parse --abbrev-ref HEAD)" #npm run-script build cp -r {.env,app.js,package.json,server,public,doc,Dockerfile} dist/ #cp -r ./* dist/ -dateString=$(date +"%Y%m%d-%H%M%S") -git log --pretty=format:"%ad%x09%an%x09%s" --no-merges -20 > "dist/git--$dateString.log" -#Add version control for pm2 -cd dist -#Add version control for pm2 -version=$(git describe) -file_pkg="package.json" -key=" \"version\": \"" -count=$(echo ${version%%-*} | grep -o "\." | wc -l) -if (( $count > 1 )); then - version=${version%%-*} -else - if [[ "$1" == "dev" ]];then - cleanprefix=${version#*-} - cleansuffix=${cleanprefix%-*} - version="${version%%-*}.${cleansuffix}" - else - version="${version%%-*}.0" # one `%` remove everything after last `-`, two `%%` remove everything after all `-` - fi -fi -if [ -f "$file_pkg" ] && [ ! -z "$version" ]; then - version=" \"version\": \"$version\"," - sed -i "s|^.*$key.*|${version//\//\\/}|g" $file_pkg - text=$(cat $file_pkg | grep -c "$version") - if [ $text -eq 0 ]; then - echo "Version couldn't be set" - else - echo "Version $version successfully applied to App" - fi -fi +# Generate Git log +dateString=$(date +"%Y%m%d-%H%M%S") +git log --pretty=format:"%ad%x09%an%x09%s" --no-merges -20 > "dist/git-$dateString.log" + +# Get Git version control +getGitVersion $1 + +# Add version control for pm2 +cd dist +addVersionPm2 ## POST BUILD -- 2.37.1