-
Notifications
You must be signed in to change notification settings - Fork 31
/
build.sh
executable file
·32 lines (26 loc) · 1.03 KB
/
build.sh
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
#!/usr/bin/env bash
# Get the program name and version
MOCKERFILE="mock.go"
PROGRAMNAME=`grep "programName " ${MOCKERFILE} | cut -d'=' -f2 | sed 's/"//g' | sed -e 's/^[[:space:]]*//'`
PROGRAMVERSION=`grep "programVersion" ${MOCKERFILE} | cut -d'=' -f2 | sed 's/"//g' | sed -e 's/^[[:space:]]*//'`
PLATFORM=("windows/amd64" "darwin/amd64" "linux/amd64")
# Loop through the platform and build a package
for platform in "${PLATFORM[@]}"
do
# Extract the os and architecture
platform_split=(${platform//\// })
GOOS=${platform_split[0]}
GOARCH=${platform_split[1]}
echo "Building package for platform ${GOOS} architecture ${GOARCH}"
# Build the package name
output_name=${PROGRAMNAME}'-'${GOOS}'-'${GOARCH}'-'${PROGRAMVERSION}
if [[ ${GOOS} = "windows" ]]; then
output_name+='.exe'
fi
# Build the package using go build
env GOOS=${GOOS} GOARCH=${GOARCH} go build -o ${output_name}
if [[ $? -ne 0 ]]; then
echo 'An error has occurred! Aborting the script execution...'
exit 1
fi
done