Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
Update pack script
Browse files Browse the repository at this point in the history
  • Loading branch information
dhaavi committed Nov 24, 2020
1 parent 25212d2 commit 8a0fc36
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions pack
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
baseDir="$( cd "$(dirname "$0")" && pwd )"
cd "$baseDir"

COL_OFF="\033[00m"
COL_OFF="\033[0m"
COL_BOLD="\033[01;01m"
COL_RED="\033[31m"
COL_GREEN="\033[32m"
COL_YELLOW="\033[33m"

destDirPart1="./dist"
destDirPart2="hub"

function check {
function prep {
# output
output="main"
# get version
Expand All @@ -25,46 +27,47 @@ function check {
fi
# build destination path
destPath=${destDirPart1}/${platform}/${destDirPart2}/$filename
}

function check {
prep

# check if file exists
if [[ -f $destPath ]]; then
echo "[hub] $platform $version already built"
echo "[hub] $platform v$version already built"
else
echo -e "${COL_BOLD}[hub] $platform $version${COL_OFF}"
echo -e "${COL_BOLD}[hub] $platform v$version${COL_OFF}"
fi
}

function build {
# output
output="main"
# get version
version=$(grep "info.Set" main.go | cut -d'"' -f4)
# build versioned file name
filename="spn-hub_v${version//./-}"
# platform
platform="${GOOS}_${GOARCH}"
if [[ $GOOS == "windows" ]]; then
filename="${filename}.exe"
output="${output}.exe"
fi
# build destination path
destPath=${destDirPart1}/${platform}/${destDirPart2}/$filename
prep

# check if file exists
if [[ -f $destPath ]]; then
echo "[hub] $platform already built in version $version, skipping..."
echo "[hub] $platform already built in v$version, skipping..."
return
fi

# build
./build main.go
if [[ $? -ne 0 ]]; then
echo -e "\n${COL_BOLD}[hub] $platform: ${COL_RED}BUILD FAILED.${COL_OFF}"
echo -e "\n${COL_BOLD}[hub] $platform v$version: ${COL_RED}BUILD FAILED.${COL_OFF}"
exit 1
fi
mkdir -p $(dirname $destPath)
cp $output $destPath
echo -e "\n${COL_BOLD}[hub] $platform: successfully built.${COL_OFF}"
echo -e "\n${COL_BOLD}[hub] $platform v$version: ${COL_GREEN}successfully built.${COL_OFF}"
}

function reset {
prep

# delete if file exists
if [[ -f $destPath ]]; then
rm $destPath
echo "[hub] $platform v$version deleted."
fi
}

function check_all {
Expand All @@ -79,13 +82,22 @@ function build_all {
GOOS=darwin GOARCH=amd64 build
}

function reset_all {
GOOS=linux GOARCH=amd64 reset
GOOS=windows GOARCH=amd64 reset
GOOS=darwin GOARCH=amd64 reset
}

case $1 in
"check" )
check_all
;;
"build" )
build_all
;;
"reset" )
reset_all
;;
* )
echo ""
echo "build list:"
Expand Down

0 comments on commit 8a0fc36

Please sign in to comment.