drive-health/build.sh

50 lines
1.2 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2024-01-22 01:49:13 +02:00
set -o pipefail
set -u
2024-01-20 02:11:59 +02:00
# Function to display messages in color
echo_color() {
color=$1
text=$2
case $color in
"green") echo -e "\033[0;32m$text\033[0m" ;;
"yellow") echo -e "\033[0;33m$text\033[0m" ;;
"red") echo -e "\033[0;31m$text\033[0m" ;;
*) echo "$text" ;;
esac
}
# Getting GIT_VERSION from the most recent tag or commit hash
GIT_VERSION=$(git describe --tags --always)
if [ -z "$GIT_VERSION" ]; then
echo_color red "Error: Unable to determine GIT_VERSION."
exit 1
fi
2024-01-20 02:11:59 +02:00
APP_NAME="drive-health"
2024-01-22 01:49:13 +02:00
DIST_DIR="${DIST_DIR:-dist}"
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# make sure we are in the source dir
cd $SCRIPT_DIR;
2024-01-20 02:11:59 +02:00
# Create the dist directory if it doesn't exist
mkdir -p $DIST_DIR
# Build the application
echo_color yellow "[🦝] Building the application..."
2024-01-22 01:49:13 +02:00
GOOS=linux CGO_ENABLED=1 GOARCH=amd64 go build -o $DIST_DIR/$APP_NAME
2024-01-20 02:11:59 +02:00
# Copying additional resources...
2024-01-22 01:49:13 +02:00
cp -r static templates $DIST_DIR/
2024-01-20 02:11:59 +02:00
echo_color yellow "[🦝] Compilation and packaging completed, archiving..."
cd $DIST_DIR/
zip "drive-health_$GIT_VERSION.zip" -r .
# TODO: Add reliable method of cleaning up the compiled files optionally
cd $SCRIPT_DIR;