-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
36 lines (29 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
33
34
35
36
#!/bin/bash
APP_NAME="gobeats"
VERSION="1.0.0"
OUTPUT_DIR="bin"
MAIN_FILE="./cmd/main/main.go"
PLATFORMS=("windows/386" "windows/amd64" "linux/386" "linux/amd64" "darwin/amd64" "linux/arm")
# Clean and create the output directory
rm -rf "$OUTPUT_DIR"
mkdir -p "$OUTPUT_DIR"
touch "$OUTPUT_DIR/.gitkeep"
# Iterate through platforms and compile the application
for PLATFORM in "${PLATFORMS[@]}"; do
GOOS=${PLATFORM%/*}
GOARCH=${PLATFORM#*/}
OUTPUT_NAME="$OUTPUT_DIR/${APP_NAME}_${VERSION}_${GOOS}_${GOARCH}"
# Compile for the current platform
if [[ "$GOOS" == "windows" ]]; then
env GOOS=$GOOS GOARCH=$GOARCH go build -o "$OUTPUT_NAME".exe "$MAIN_FILE"
else
env GOOS=$GOOS GOARCH=$GOARCH go build -o "$OUTPUT_NAME" "$MAIN_FILE"
fi
# Check if the compilation was successful
if [ $? -eq 0 ]; then
echo "Compilation successful for $PLATFORM"
else
echo "Error compiling for $PLATFORM"
fi
done
echo "Compilation complete. Binaries are available in the $OUTPUT_DIR directory."