2020-12-09 15:31:34 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# This script builds the application from source for multiple platforms.
|
|
|
|
# Inspired from hashicorp/terraform build script
|
2021-07-15 15:33:35 +00:00
|
|
|
# https://github.com/hashicorp/terraform/blob/83e6703bf77f60660db4465ef50d30c633f800f1/scripts/build.sh
|
2020-12-14 15:13:47 +00:00
|
|
|
set -eo pipefail
|
2020-12-09 15:31:34 +00:00
|
|
|
|
2021-07-15 15:33:35 +00:00
|
|
|
if ! which goreleaser >/dev/null; then
|
|
|
|
echo "+ Installing goreleaser..."
|
|
|
|
go install github.com/goreleaser/goreleaser@v0.173.2
|
2020-12-09 15:31:34 +00:00
|
|
|
fi
|
|
|
|
|
2021-07-27 14:47:17 +00:00
|
|
|
export ENV="${ENV:-dev}"
|
|
|
|
SINGLE_TARGET="${SINGLE_TARGET:-false}"
|
2021-07-22 08:43:35 +00:00
|
|
|
|
2021-07-22 09:05:08 +00:00
|
|
|
# Check configuration
|
|
|
|
goreleaser check
|
|
|
|
|
2021-07-27 14:47:17 +00:00
|
|
|
FLAGS=""
|
|
|
|
FLAGS+="--rm-dist "
|
|
|
|
FLAGS+="--parallelism 2 "
|
|
|
|
|
|
|
|
CMD="release"
|
2021-07-22 08:43:35 +00:00
|
|
|
|
2021-07-27 14:47:17 +00:00
|
|
|
if [ "$SINGLE_TARGET" == "true" ]; then
|
|
|
|
CMD="build"
|
|
|
|
FLAGS+="--single-target "
|
|
|
|
fi
|
2021-07-22 08:43:35 +00:00
|
|
|
|
|
|
|
# Only CI system should publish artifacts
|
2021-07-22 09:05:08 +00:00
|
|
|
# We may not want to sign artifacts in dev environments
|
2021-08-04 14:19:57 +00:00
|
|
|
if [ "$CI" != true ] && [ "$CMD" == "release" ]; then
|
2021-07-27 14:47:17 +00:00
|
|
|
FLAGS+="--skip-announce "
|
|
|
|
FLAGS+="--skip-publish "
|
|
|
|
FLAGS+="--skip-sign "
|
2021-08-04 14:20:50 +00:00
|
|
|
FLAGS+="--snapshot "
|
2021-07-22 08:43:35 +00:00
|
|
|
fi
|
|
|
|
|
2021-07-27 14:47:17 +00:00
|
|
|
CMD="goreleaser ${CMD} ${FLAGS}"
|
|
|
|
|
|
|
|
echo "+ Building using goreleaser"
|
|
|
|
echo "+ ENV=${ENV}"
|
|
|
|
echo "+ CMD=${CMD}"
|
|
|
|
|
|
|
|
$CMD
|