2023-09-14 06:54:09 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-03-13 06:08:30 +00:00
|
|
|
# Fetch the latest tag that starts with "cli-"
|
|
|
|
# shellcheck disable=SC2046
|
|
|
|
# shellcheck disable=SC2006
|
|
|
|
LATEST_TAG=$(git describe --tags `git rev-list --tags='cli-*' --max-count=1`)
|
|
|
|
|
|
|
|
# Check if the LATEST_TAG variable is empty
|
|
|
|
if [ -z "$LATEST_TAG" ]; then
|
|
|
|
echo "No 'cli-' tag found. Exiting..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
VERSION=${LATEST_TAG#cli-}
|
2023-09-14 06:54:09 +00:00
|
|
|
# Create a "bin" directory if it doesn't exist
|
|
|
|
mkdir -p bin
|
|
|
|
|
|
|
|
# List of target operating systems
|
|
|
|
OS_TARGETS=("windows" "linux" "darwin")
|
|
|
|
|
2023-10-20 09:26:13 +00:00
|
|
|
# Corresponding architectures for each OS
|
|
|
|
ARCH_TARGETS=("386 amd64" "386 amd64 arm arm64" "amd64 arm64")
|
|
|
|
|
2024-03-07 06:26:54 +00:00
|
|
|
export CGO_ENABLED=0
|
2023-09-14 06:54:09 +00:00
|
|
|
# Loop through each OS target
|
2023-10-20 09:26:13 +00:00
|
|
|
for index in "${!OS_TARGETS[@]}"
|
2023-09-14 06:54:09 +00:00
|
|
|
do
|
2023-10-20 09:26:13 +00:00
|
|
|
OS=${OS_TARGETS[$index]}
|
|
|
|
for ARCH in ${ARCH_TARGETS[$index]}
|
|
|
|
do
|
|
|
|
# Set the GOOS environment variable for the current target OS
|
|
|
|
export GOOS="$OS"
|
|
|
|
export GOARCH="$ARCH"
|
2023-09-14 06:54:09 +00:00
|
|
|
|
2023-10-20 09:26:13 +00:00
|
|
|
# Set the output binary name to "ente-cli" for the current OS and architecture
|
2023-10-25 11:52:22 +00:00
|
|
|
BINARY_NAME="ente-$OS-$ARCH"
|
2023-09-14 06:54:09 +00:00
|
|
|
|
|
|
|
# Add .exe extension for Windows
|
2023-10-20 09:26:13 +00:00
|
|
|
if [ "$OS" == "windows" ]; then
|
2023-10-25 11:52:22 +00:00
|
|
|
BINARY_NAME="ente-$OS-$ARCH.exe"
|
2023-10-20 09:26:13 +00:00
|
|
|
fi
|
2023-09-14 06:54:09 +00:00
|
|
|
|
2023-10-20 09:26:13 +00:00
|
|
|
# Build the binary and place it in the "bin" directory
|
2024-03-13 06:08:30 +00:00
|
|
|
go build -ldflags="-X main.AppVersion=${VERSION} -s -w" -trimpath -o "bin/$BINARY_NAME" main.go
|
2023-09-14 06:54:09 +00:00
|
|
|
|
2023-10-20 09:26:13 +00:00
|
|
|
# Print a message indicating the build is complete for the current OS and architecture
|
|
|
|
echo "Built for $OS ($ARCH) as bin/$BINARY_NAME"
|
|
|
|
done
|
2023-09-14 06:54:09 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# Print a message indicating the build process is complete
|
2023-10-20 09:26:13 +00:00
|
|
|
echo "Build process completed for all platforms and architectures. Binaries are in the 'bin' directory."
|