2022-11-12 02:19:09pm
This commit is contained in:
parent
bebbdefa87
commit
ee86426ef2
8 changed files with 213 additions and 126 deletions
|
|
@ -7,7 +7,10 @@ help() {
|
|||
cat <<EOF
|
||||
usage: $0 [--rebuild] [--local]
|
||||
|
||||
$0 builds D2 release archives into ./ci/release/build/<ref>/d2-<ref>.tar.gz
|
||||
$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.
|
||||
|
||||
Flags:
|
||||
|
||||
|
|
@ -23,16 +26,22 @@ EOF
|
|||
}
|
||||
|
||||
build() {
|
||||
BUILD_DIR="$BUILD_DIR/$OS/$ARCH"
|
||||
HW_BUILD_DIR="$BUILD_DIR/$OS/$ARCH/d2-$VERSION"
|
||||
|
||||
mkdir -p "$BUILD_DIR/bin"
|
||||
sh_c cp LICENSE.txt "$BUILD_DIR"
|
||||
sh_c "./ci/release/template/README.md.sh > $BUILD_DIR"
|
||||
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 {} \;
|
||||
|
||||
export GOOS=$(goos "$OS")
|
||||
export GOARCH="$ARCH"
|
||||
sh_c go build -ldflags "-X lib/version.Version=$VERSION" \
|
||||
-o "$BUILD_DIR/bin/d2" ./cmd/d2
|
||||
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"
|
||||
}
|
||||
|
||||
main() {
|
||||
|
|
@ -41,11 +50,44 @@ main() {
|
|||
FLAGARG \
|
||||
FLAGSHIFT \
|
||||
VERSION \
|
||||
BUILD_DIR \
|
||||
HW_BUILD_DIR \
|
||||
REBUILD \
|
||||
DEST \
|
||||
LOCAL \
|
||||
DRYRUN
|
||||
VERSION="$(git_describe_ref)"
|
||||
BUILD_DIR="ci/release/build/$VERSION"
|
||||
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
|
||||
|
||||
if [ $# -gt 0 ]; then
|
||||
flag_errusage "no arguments are accepted"
|
||||
|
|
@ -55,7 +97,7 @@ main() {
|
|||
runjob linux-arm64 'OS=linux ARCH=arm64 build' &
|
||||
runjob macos-amd64 'OS=macos ARCH=amd64 build' &
|
||||
runjob macos-arm64 'OS=macos ARCH=arm64 build' &
|
||||
wait_jobs
|
||||
waitjobs
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
|
|
|||
|
|
@ -4,11 +4,23 @@ set -eu
|
|||
cat <<EOF
|
||||
# d2
|
||||
|
||||
For docs, more installation options and the source code see https://oss.terrastruct.com/d2
|
||||
|
||||
version: $VERSION
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
PREFIX=/usr/local ./install.sh
|
||||
```
|
||||
\`\`\`sh
|
||||
make install PREFIX=/usr/local DRYRUN=1
|
||||
# If it looks right, run:
|
||||
make install PREFIX=/usr/local
|
||||
\`\`\`
|
||||
|
||||
## Uninstall
|
||||
|
||||
\`\`\`sh
|
||||
make uninstall PREFIX=/usr/local DRYRUN=1
|
||||
# If it looks right, run:
|
||||
make uninstall PREFIX=/usr/local
|
||||
\`\`\`
|
||||
EOF
|
||||
|
|
|
|||
|
|
@ -1,105 +0,0 @@
|
|||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
_echo() {
|
||||
printf '%s\n' "$*"
|
||||
}
|
||||
|
||||
tput() {
|
||||
if [ -n "$TERM" ]; then
|
||||
command tput "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
setaf() {
|
||||
tput setaf "$1"
|
||||
shift
|
||||
printf '%s' "$*"
|
||||
tput sgr0
|
||||
}
|
||||
|
||||
echoerr() {
|
||||
COLOR=1 echop err "$*" >&2
|
||||
}
|
||||
|
||||
printferr() {
|
||||
COLOR=1 printfp err "$@" >&2
|
||||
}
|
||||
|
||||
sh_c() {
|
||||
COLOR=3 echop exec "$*"
|
||||
"$@"
|
||||
}
|
||||
|
||||
get_rand_color() {
|
||||
# 1-6 are regular and 9-14 are bright.
|
||||
# 1,2 and 9,10 are red and green but we use those for success and failure.
|
||||
pick "$*" 3 4 5 6 11 12 13 14
|
||||
}
|
||||
|
||||
echop() {(
|
||||
prefix="$1"
|
||||
shift
|
||||
|
||||
if [ -z "${COLOR:-}" ]; then
|
||||
COLOR="$(get_rand_color "$prefix")"
|
||||
fi
|
||||
printf '%s: %s\n' "$(setaf "$COLOR" "$prefix")" "$*"
|
||||
)}
|
||||
|
||||
printfp() {(
|
||||
PREFIX="$1"
|
||||
shift
|
||||
echop "$PREFIX" "$(printf "$@")"
|
||||
)}
|
||||
|
||||
hide() {
|
||||
out="$(mktemp)"
|
||||
set +e
|
||||
"$@" >"$out" 2>&1
|
||||
code="$?"
|
||||
set -e
|
||||
if [ "$code" -eq 0 ]; then
|
||||
return
|
||||
fi
|
||||
cat "$out" >&2
|
||||
exit "$code"
|
||||
}
|
||||
|
||||
echo_dur() {
|
||||
local dur=$1
|
||||
local h=$((dur/60/60))
|
||||
local m=$((dur/60%60))
|
||||
local s=$((dur%60))
|
||||
printf '%dh%dm%ds' "$h" "$m" "$s"
|
||||
}
|
||||
|
||||
sponge() {
|
||||
dst="$1"
|
||||
tmp="$(mktemp)"
|
||||
cat > "$tmp"
|
||||
cat "$tmp" > "$dst"
|
||||
}
|
||||
|
||||
stripansi() {
|
||||
# First regex gets rid of standard xterm escape sequences for controlling
|
||||
# visual attributes.
|
||||
# The second regex I'm not 100% sure, the reference says it selects the US
|
||||
# encoding but I'm not sure why that's necessary or why it always occurs
|
||||
# in tput sgr0 before the standard escape sequence.
|
||||
# See tput sgr0 | xxd
|
||||
sed -e $'s/\x1b\[[0-9;]*m//g' -e $'s/\x1b(.//g'
|
||||
}
|
||||
|
||||
runtty() {
|
||||
case "$(uname)" in
|
||||
Darwin)
|
||||
script -q /dev/null "$@"
|
||||
;;
|
||||
Linux)
|
||||
script -eqc "$*"
|
||||
;;
|
||||
*)
|
||||
echoerr "runtty: unsupported OS $(uname)"
|
||||
esac
|
||||
}
|
||||
|
|
@ -1,15 +1,15 @@
|
|||
#!/bin/sh
|
||||
set -eu
|
||||
. "$(dirname "$0")/lib.sh"
|
||||
cd -- "$(dirname "$0")/.."
|
||||
. ./scripts/lib.sh
|
||||
|
||||
main() {
|
||||
if [ ! -e "${PREFIX:-}" ]; then
|
||||
if [ ! -e "${PREFIX-}" ]; then
|
||||
echoerr "\$PREFIX must be set to a unix prefix directory in which to install d2 like /usr/local"
|
||||
exit 1
|
||||
return 1
|
||||
fi
|
||||
|
||||
mkdir -p "$PREFIX"
|
||||
|
||||
sh_c mkdir -p "$PREFIX"
|
||||
sh_c install ./bin/d2 "$PREFIX/bin/d2"
|
||||
}
|
||||
|
||||
137
ci/release/template/scripts/lib.sh
Normal file
137
ci/release/template/scripts/lib.sh
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
#!/bin/sh
|
||||
|
||||
rand() {
|
||||
seed="$1"
|
||||
range="$2"
|
||||
|
||||
seed_file="$(mktemp)"
|
||||
_echo "$seed" | md5sum > "$seed_file"
|
||||
shuf -i "$range" -n 1 --random-source="$seed_file"
|
||||
}
|
||||
|
||||
pick() {
|
||||
seed="$1"
|
||||
shift
|
||||
i="$(rand "$seed" "1-$#")"
|
||||
eval "_echo \"\$$i\""
|
||||
}
|
||||
|
||||
tput() {
|
||||
if [ -n "$TERM" ]; then
|
||||
command tput "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
setaf() {
|
||||
tput setaf "$1"
|
||||
shift
|
||||
printf '%s' "$*"
|
||||
tput sgr0
|
||||
}
|
||||
|
||||
_echo() {
|
||||
printf '%s\n' "$*"
|
||||
}
|
||||
|
||||
get_rand_color() {
|
||||
# 1-6 are regular and 9-14 are bright.
|
||||
# 1,2 and 9,10 are red and green but we use those for success and failure.
|
||||
pick "$*" 3 4 5 6 11 12 13 14
|
||||
}
|
||||
|
||||
echop() {
|
||||
prefix="$1"
|
||||
shift
|
||||
|
||||
if [ "$#" -gt 0 ]; then
|
||||
printfp "$prefix" "%s\n" "$*"
|
||||
else
|
||||
printfp "$prefix"
|
||||
printf '\n'
|
||||
fi
|
||||
}
|
||||
|
||||
printfp() {(
|
||||
prefix="$1"
|
||||
shift
|
||||
|
||||
if [ -z "${COLOR:-}" ]; then
|
||||
COLOR="$(get_rand_color "$prefix")"
|
||||
fi
|
||||
printf '%s' "$(setaf "$COLOR" "$prefix")"
|
||||
|
||||
if [ $# -gt 0 ]; then
|
||||
printf ': '
|
||||
printf "$@"
|
||||
fi
|
||||
)}
|
||||
|
||||
catp() {
|
||||
prefix="$1"
|
||||
shift
|
||||
|
||||
printfp "$prefix"
|
||||
printf ': '
|
||||
read -r line
|
||||
_echo "$line"
|
||||
|
||||
indent=$(repeat ' ' 2)
|
||||
sed "s/^/$indent/"
|
||||
}
|
||||
|
||||
repeat() {
|
||||
char="$1"
|
||||
times="$2"
|
||||
seq -s "$char" "$times" | tr -d '[:digit:]'
|
||||
}
|
||||
|
||||
strlen() {
|
||||
printf %s "$1" | wc -c
|
||||
}
|
||||
|
||||
echoerr() {
|
||||
COLOR=1 echop err "$*" >&2
|
||||
}
|
||||
|
||||
caterr() {
|
||||
COLOR=1 catp err "$@" >&2
|
||||
}
|
||||
|
||||
printferr() {
|
||||
COLOR=1 printfp err "$@" >&2
|
||||
}
|
||||
|
||||
logp() {
|
||||
echop "$@" >&2
|
||||
}
|
||||
|
||||
logfp() {
|
||||
printfp "$@" >&2
|
||||
}
|
||||
|
||||
logpcat() {
|
||||
catp "$@" >&2
|
||||
}
|
||||
|
||||
log() {
|
||||
COLOR=5 logp log "$@"
|
||||
}
|
||||
|
||||
logf() {
|
||||
COLOR=5 logfp log "$@"
|
||||
}
|
||||
|
||||
logcat() {
|
||||
COLOR=5 catp log "$@" >&2
|
||||
}
|
||||
|
||||
sh_c() {
|
||||
COLOR=3 logp exec "$*"
|
||||
if [ -z "${DRYRUN-}" ]; then
|
||||
"$@"
|
||||
fi
|
||||
}
|
||||
|
||||
header() {
|
||||
logp "/* $1 */"
|
||||
}
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
#!/bin/sh
|
||||
set -eu
|
||||
. "$(dirname "$0")/lib.sh"
|
||||
cd -- "$(dirname "$0")/.."
|
||||
. ./scripts/lib.sh
|
||||
|
||||
main() {
|
||||
if [ ! -e "${PREFIX:-}" ]; then
|
||||
if [ ! -e "${PREFIX-}" ]; then
|
||||
echoerr "\$PREFIX must be set to a unix prefix directory from which to uninstall d2 like /usr/local"
|
||||
exit 1
|
||||
return 1
|
||||
fi
|
||||
|
||||
sh_c rm -f "$PREFIX/bin/d2"
|
||||
2
ci/sub
2
ci/sub
|
|
@ -1 +1 @@
|
|||
Subproject commit d95383e2ed77d82ffc34b8ecd0a90b5cc7b89d97
|
||||
Subproject commit 4760501f65c5abace1790a501f34a7b1e3223b2f
|
||||
Loading…
Reference in a new issue