2022-11-11 09:17:06 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
set -eu
|
|
|
|
|
cd -- "$(dirname "$0")/../.."
|
2022-11-12 19:53:54 +00:00
|
|
|
. ./ci/sub/lib.sh
|
2022-11-11 09:17:06 +00:00
|
|
|
|
2022-11-12 21:38:54 +00:00
|
|
|
help() {
|
|
|
|
|
cat <<EOF
|
|
|
|
|
usage: $0 [--rebuild] [--local]
|
|
|
|
|
|
2022-11-12 22:19:09 +00:00
|
|
|
$0 builds D2 release archives into ./ci/release/build/<version>/d2-<version>.tar.gz
|
|
|
|
|
|
|
|
|
|
The version is detected via git describe which will use the git tag for the current
|
|
|
|
|
commit if available.
|
2022-11-12 21:38:54 +00:00
|
|
|
|
|
|
|
|
Flags:
|
|
|
|
|
|
|
|
|
|
--rebuild: By default build.sh will avoid rebuilding finished assets if they
|
|
|
|
|
already exist but if you changed something and need to force rebuild, use
|
|
|
|
|
this flag.
|
|
|
|
|
--local: By default build.sh uses \$TSTRUCT_MACOS_BUILDER and \$TSTRUCT_LINUX_BUILDER
|
|
|
|
|
to build the release archives. It's required for now due to the following
|
|
|
|
|
issue: https://github.com/terrastruct/d2/issues/31
|
|
|
|
|
With --local, build.sh will cross compile locally.
|
|
|
|
|
warning: This is only for testing purposes, do not use in production!
|
|
|
|
|
EOF
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-12 19:53:54 +00:00
|
|
|
build() {
|
2022-11-12 22:19:09 +00:00
|
|
|
HW_BUILD_DIR="$BUILD_DIR/$OS/$ARCH/d2-$VERSION"
|
2022-11-11 09:17:06 +00:00
|
|
|
|
2022-11-12 22:19:09 +00:00
|
|
|
sh_c mkdir -p "$HW_BUILD_DIR"
|
|
|
|
|
sh_c rsync --recursive --perms --delete \
|
|
|
|
|
--human-readable --copy-links ./ci/release/template/ "$HW_BUILD_DIR/"
|
|
|
|
|
VERSION=$VERSION sh_c eval "'$HW_BUILD_DIR/README.md.sh'" \> "'$HW_BUILD_DIR/README.md'"
|
|
|
|
|
sh_c rm -f "$HW_BUILD_DIR/README.md.sh"
|
|
|
|
|
sh_c find "$HW_BUILD_DIR" -exec touch {} \;
|
2022-11-11 09:17:06 +00:00
|
|
|
|
|
|
|
|
export GOOS=$(goos "$OS")
|
|
|
|
|
export GOARCH="$ARCH"
|
2022-11-12 22:19:09 +00:00
|
|
|
sh_c mkdir -p "$HW_BUILD_DIR/bin"
|
|
|
|
|
sh_c go build -ldflags "-X oss.terrastruct.com/d2/lib/version.Version=$VERSION" \
|
|
|
|
|
-o "$HW_BUILD_DIR/bin/d2" ./cmd/d2
|
|
|
|
|
|
|
|
|
|
sh_c tar czf "$BUILD_DIR/d2-$OS-$ARCH-$VERSION.tar.gz" "$HW_BUILD_DIR"
|
2022-11-12 19:53:54 +00:00
|
|
|
}
|
2022-11-11 09:17:06 +00:00
|
|
|
|
|
|
|
|
main() {
|
2022-11-12 21:38:54 +00:00
|
|
|
unset FLAG \
|
|
|
|
|
FLAGRAW \
|
|
|
|
|
FLAGARG \
|
|
|
|
|
FLAGSHIFT \
|
|
|
|
|
VERSION \
|
2022-11-12 22:19:09 +00:00
|
|
|
BUILD_DIR \
|
|
|
|
|
HW_BUILD_DIR \
|
2022-11-12 21:38:54 +00:00
|
|
|
REBUILD \
|
|
|
|
|
LOCAL \
|
2022-11-12 22:19:09 +00:00
|
|
|
DRYRUN
|
2022-11-11 09:17:06 +00:00
|
|
|
VERSION="$(git_describe_ref)"
|
|
|
|
|
BUILD_DIR="ci/release/build/$VERSION"
|
2022-11-12 22:19:09 +00:00
|
|
|
while :; do
|
|
|
|
|
flag_parse "$@"
|
|
|
|
|
case "$FLAG" in
|
|
|
|
|
h|help)
|
|
|
|
|
help
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
rebuild)
|
|
|
|
|
flag_noarg
|
|
|
|
|
REBUILD=1
|
|
|
|
|
shift "$FLAGSHIFT"
|
|
|
|
|
;;
|
|
|
|
|
local)
|
|
|
|
|
flag_noarg
|
|
|
|
|
LOCAL=1
|
|
|
|
|
shift "$FLAGSHIFT"
|
|
|
|
|
;;
|
|
|
|
|
dryrun)
|
|
|
|
|
flag_noarg
|
|
|
|
|
DRYRUN=1
|
|
|
|
|
shift "$FLAGSHIFT"
|
|
|
|
|
;;
|
|
|
|
|
'')
|
|
|
|
|
shift "$FLAGSHIFT"
|
|
|
|
|
break
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
flag_errusage "unrecognized flag $FLAGRAW"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
2022-11-11 09:17:06 +00:00
|
|
|
|
2022-11-12 21:38:54 +00:00
|
|
|
if [ $# -gt 0 ]; then
|
|
|
|
|
flag_errusage "no arguments are accepted"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
runjob linux-amd64 'OS=linux ARCH=amd64 build' &
|
|
|
|
|
runjob linux-arm64 'OS=linux ARCH=arm64 build' &
|
|
|
|
|
runjob macos-amd64 'OS=macos ARCH=amd64 build' &
|
|
|
|
|
runjob macos-arm64 'OS=macos ARCH=arm64 build' &
|
2022-11-12 22:19:09 +00:00
|
|
|
waitjobs
|
2022-11-11 09:17:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main "$@"
|