added build commit no #31
76
build.sh
76
build.sh
@ -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,37 +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
|
|
||||||
if [[ "$1" == "dev" ]];then
|
# Get Git version control
|
||||||
cleanprefix=${version#*-}
|
getGitVersion $1
|
||||||
cleansuffix=${cleanprefix%-*}
|
|
||||||
version="${version%%-*}.${cleansuffix}"
|
# Add version control for pm2
|
||||||
else
|
cd dist
|
||||||
version="${version%%-*}.0" # one `%` remove everything after last `-`, two `%%` remove everything after all `-`
|
addVersionPm2
|
||||||
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
|
|
||||||
|
|
||||||
## POST BUILD
|
## POST BUILD
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user