All checks were successful
continuous-integration/drone/push Build is passing
49 lines
1.5 KiB
Bash
Executable File
49 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# disable CGO for cross-compiling
|
|
export CGO_ENABLED=0
|
|
|
|
package_name=vctp
|
|
package=./
|
|
commit=$(git rev-parse HEAD)
|
|
buildtime=$(date +%Y-%m-%dT%T%z)
|
|
#Extract the version from yml
|
|
package_version=$(grep 'version:' "$package_name.yml" | awk '{print $2}' | tr -d '"' | sed 's/^v//')
|
|
|
|
host_os=$(uname -s | tr '[:upper:]' '[:lower:]')
|
|
host_arch=$(uname -m)
|
|
platforms=("linux/amd64")
|
|
if [[ "$host_os" == "darwin" && ( "$host_arch" == "x86_64" || "$host_arch" == "amd64" || "$host_arch" == "arm64" ) ]]; then
|
|
platforms+=("darwin/amd64")
|
|
fi
|
|
#platforms=("linux/amd64")
|
|
|
|
echo Building::
|
|
echo - Version $package_version
|
|
echo - Commit $commit
|
|
echo - Build Time $buildtime
|
|
mkdir -p build
|
|
for platform in "${platforms[@]}"
|
|
do
|
|
platform_split=(${platform//\// })
|
|
GOOS=${platform_split[0]}
|
|
GOARCH=${platform_split[1]}
|
|
output_name=$package_name'-'$GOOS'-'$GOARCH
|
|
if [ $GOOS = "windows" ]; then
|
|
output_name+='.exe'
|
|
fi
|
|
|
|
starttime=$(TZ=Australia/Sydney date +%Y-%m-%dT%T%z)
|
|
echo "build commences at $starttime"
|
|
env GOOS=$GOOS GOARCH=$GOARCH go build -trimpath -ldflags="-X main.version=$package_version -X main.sha1ver=$commit -X main.buildTime=$buildtime" -o build/$output_name $package
|
|
if [ $? -ne 0 ]; then
|
|
echo 'An error has occurred! Aborting the script execution...'
|
|
exit 1
|
|
fi
|
|
#gzip build/$output_name
|
|
echo "build complete at $buildtime : $output_name"
|
|
#sha256sum build/${output_name}.gz > build/${output_name}_checksum.txt
|
|
done
|
|
|
|
ls -lah build
|