added build commit no #31
70
build.sh
70
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,31 +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
|
||||
version="${version%%-*}.0"
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user