added build commit no #31

Merged
bmamihai merged 2 commits from build-commit-no into develop 2023-04-10 23:36:34 +00:00

View File

@ -1,4 +1,40 @@
#/!bin/bash #/!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 ## PREBUILD PROCESS
# check dist dir to be present and empty # check dist dir to be present and empty
if [ ! -d "dist" ]; then if [ ! -d "dist" ]; then
@ -22,31 +58,17 @@ echo "Building app... from $(git rev-parse --abbrev-ref HEAD)"
#npm run-script build #npm run-script build
cp -r {.env,app.js,package.json,server,public,doc,Dockerfile} dist/ cp -r {.env,app.js,package.json,server,public,doc,Dockerfile} dist/
#cp -r ./* 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) # Generate Git log
if (( $count > 1 )); then dateString=$(date +"%Y%m%d-%H%M%S")
version=${version%%-*} git log --pretty=format:"%ad%x09%an%x09%s" --no-merges -20 > "dist/git-$dateString.log"
else
version="${version%%-*}.0" # Get Git version control
fi getGitVersion $1
if [ -f "$file_pkg" ] && [ ! -z "$version" ]; then
version=" \"version\": \"$version\"," # Add version control for pm2
sed -i "s|^.*$key.*|${version//\//\\/}|g" $file_pkg cd dist
text=$(cat $file_pkg | grep -c "$version") addVersionPm2
if [ $text -eq 0 ]; then
echo "Version couldn't be set"
else
echo "Version $version successfully applied to App"
fi
fi
## POST BUILD ## POST BUILD