-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompile.sh
More file actions
executable file
·101 lines (83 loc) · 2.41 KB
/
Copy pathcompile.sh
File metadata and controls
executable file
·101 lines (83 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
function DumbLog {
if [ "$#" -ne 2 ]; then
echo "Bad Programming, DumbLog expect two arguments (prefix, message)"
exit 1
fi
RESET="\033[0m"
BOLD="\033[1m"
echo -e "$1 $RESET $BOLD $2 $RESET"
}
function SuccessLog {
if [ "$#" -ne 1 ]; then
echo "Bad Programming, SuccessLog expect one argument"
exit 1
fi
GREEN="\033[32m"
SuccessPrefix="$GREEN::SUCCESS::"
DumbLog "$SuccessPrefix" "$1"
}
function InfoLog {
if [ "$#" -ne 1 ]; then
echo "Bad Programming, InfoLog expect one argument"
exit 1
fi
BLUE="\033[34m"
InfoPrefix="$BLUE::INFO::"
DumbLog "$InfoPrefix" "$1"
}
# i'm still not writing a main func tbh
set -e
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <File/or/Folder/To/Compile> <VERSION>"
echo "Note: include ./ if it's a folder"
exit 1
fi
app_name="balafetch"
PLATFORMS=(
"windows/amd64"
"windows/arm64"
"linux/amd64"
"linux/arm64"
"linux/arm"
"darwin/amd64"
"darwin/arm64"
"freebsd/arm64"
"freebsd/amd64"
"freebsd/arm"
)
TARGET_FOLDER="dist"
CHECKSUMS_FILE="$TARGET_FOLDER/checksums.txt"
COMPILE_PATH_TARGET="$1"
VERSION="$2"
DATE_FORMAT="%Y-%m-%dT%TZ"
DATA_MODULE_PATH="github.com/gitmobkab/balafetch/internal/data"
InfoLog "Creating $TARGET_FOLDER Folder"
mkdir -p $TARGET_FOLDER
InfoLog "Cleaning $CHECKSUMS_FILE"
> $CHECKSUMS_FILE
InfoLog "\n=== Starting compilation of $COMPILE_PATH_TARGET with version $VERSION ===\n"
declare -i current=1
for platform in ${PLATFORMS[@]}; do
OS="${platform%/*}"
ARCH="${platform#*/}"
export GOOS=$OS
export GOARCH=$ARCH
output_file="$app_name-$OS-$ARCH"
if [ $OS = "windows" ]; then
output_file+='.exe'
fi
InfoLog "Compiling $output_file from $COMPILE_PATH_TARGET"
go build -ldflags "\
-X $DATA_MODULE_PATH.Version=$VERSION\
-X $DATA_MODULE_PATH.CommitHash=$(git rev-parse --short HEAD)\
-X $DATA_MODULE_PATH.BuildTime=$(date -u +$DATE_FORMAT)"\
-o $TARGET_FOLDER/$output_file $COMPILE_PATH_TARGET
SuccessLog "Compiling Done ($current/${#PLATFORMS[@]})"
current_checksum=$(cd $TARGET_FOLDER && sha256sum $output_file)
InfoLog "$current_checksum\n________________"
echo "$current_checksum" >> $CHECKSUMS_FILE
current+=1
done
SuccessLog "Compilation to all platforms successful"
SuccessLog "All checksums have been written, check $CHECKSUMS_FILE"