ci: Many fixes and updates

This commit is contained in:
Anmol Sethi 2022-11-20 02:09:32 -08:00
parent 84141efe37
commit 0df3d4d15b
No known key found for this signature in database
GPG key ID: 25BC68888A99A8BA
8 changed files with 104 additions and 47 deletions

View file

@ -9,6 +9,9 @@ endif
.PHONY: fmt .PHONY: fmt
fmt: fmt:
prefix "$@" ./ci/sub/fmt/make.sh prefix "$@" ./ci/sub/fmt/make.sh
.PHONY: fmt-release
fmt-release_sh:
prefix "$@" ./ci/release/gen_sh.sh
.PHONY: lint .PHONY: lint
lint: lint:
prefix "$@" go vet --composites=false ./... prefix "$@" go vet --composites=false ./...

View file

@ -167,13 +167,14 @@ build_remote_macos() {
trap unlockfile_ssh EXIT trap unlockfile_ssh EXIT
sh_c ssh "$REMOTE_HOST" mkdir -p src sh_c ssh "$REMOTE_HOST" mkdir -p src
sh_c rsync --archive --human-readable --delete ./ "$REMOTE_HOST:src/d2/" sh_c rsync --archive --human-readable --delete ./ "$REMOTE_HOST:src/d2/"
sh_c ssh "$REMOTE_HOST" "DRY_RUN=${DRY_RUN-} \ sh_c ssh "$REMOTE_HOST" "COLOR=${COLOR-} \
TERM=${TERM-} \
DRY_RUN=${DRY_RUN-} \
HW_BUILD_DIR=$HW_BUILD_DIR \ HW_BUILD_DIR=$HW_BUILD_DIR \
VERSION=$VERSION \ VERSION=$VERSION \
OS=$OS \ OS=$OS \
ARCH=$ARCH \ ARCH=$ARCH \
ARCHIVE=$ARCHIVE \ ARCHIVE=$ARCHIVE \
TERM=$TERM \
PATH=\\\"/usr/local/bin:/usr/local/sbin:/opt/homebrew/bin:/opt/homebrew/sbin\\\${PATH+:\\\$PATH}\\\" \ PATH=\\\"/usr/local/bin:/usr/local/sbin:/opt/homebrew/bin:/opt/homebrew/sbin\\\${PATH+:\\\$PATH}\\\" \
./src/d2/ci/release/_build.sh" ./src/d2/ci/release/_build.sh"
sh_c mkdir -p "$HW_BUILD_DIR" sh_c mkdir -p "$HW_BUILD_DIR"
@ -185,13 +186,14 @@ build_remote_linux() {
trap unlockfile_ssh EXIT trap unlockfile_ssh EXIT
sh_c ssh "$REMOTE_HOST" mkdir -p src sh_c ssh "$REMOTE_HOST" mkdir -p src
sh_c rsync --archive --human-readable --delete ./ "$REMOTE_HOST:src/d2/" sh_c rsync --archive --human-readable --delete ./ "$REMOTE_HOST:src/d2/"
sh_c ssh "$REMOTE_HOST" "DRY_RUN=${DRY_RUN-} \ sh_c ssh "$REMOTE_HOST" "COLOR=${COLOR-} \
TERM=${TERM-} \
DRY_RUN=${DRY_RUN-} \
HW_BUILD_DIR=$HW_BUILD_DIR \ HW_BUILD_DIR=$HW_BUILD_DIR \
VERSION=$VERSION \ VERSION=$VERSION \
OS=$OS \ OS=$OS \
ARCH=$ARCH \ ARCH=$ARCH \
ARCHIVE=$ARCHIVE \ ARCHIVE=$ARCHIVE \
TERM=$TERM \
./src/d2/ci/release/build_docker.sh" ./src/d2/ci/release/build_docker.sh"
sh_c mkdir -p "$HW_BUILD_DIR" sh_c mkdir -p "$HW_BUILD_DIR"
sh_c rsync --archive --human-readable "$REMOTE_HOST:src/d2/$ARCHIVE" "$ARCHIVE" sh_c rsync --archive --human-readable "$REMOTE_HOST:src/d2/$ARCHIVE" "$ARCHIVE"

View file

@ -13,5 +13,4 @@ docker_run \
-e OS \ -e OS \
-e ARCH \ -e ARCH \
-e ARCHIVE \ -e ARCHIVE \
-e TERM \
"$tag" ./src/d2/ci/release/_build.sh "$tag" ./src/d2/ci/release/_build.sh

View file

@ -37,3 +37,7 @@ sh_c cat \
sh_c cat ./ci/release/_install.sh \ sh_c cat ./ci/release/_install.sh \
\| sed -n "'/cd -- \"\$(dirname/,/cd -/!p'" \>\> install.sh \| sed -n "'/cd -- \"\$(dirname/,/cd -/!p'" \>\> install.sh
sh_c chmod -w install.sh sh_c chmod -w install.sh
if [ -n "${CI-}" ]; then
git_assert_clean
fi

11
ci/release/gen_sh.sh Executable file
View file

@ -0,0 +1,11 @@
#!/bin/sh
set -eu
cd -- "$(dirname "$0")/../.."
. ./ci/sub/lib.sh
./ci/release/gen_install.sh
./ci/release/gen_template_lib.sh
if [ -n "${CI-}" ]; then
git_assert_clean
fi

View file

@ -27,3 +27,7 @@ sh_c cat \
./ci/sub/lib/log.sh \ ./ci/sub/lib/log.sh \
\| sed "-e'/^\. /d'" \>\>./ci/release/template/scripts/lib.sh \| sed "-e'/^\. /d'" \>\>./ci/release/template/scripts/lib.sh
sh_c chmod -w ./ci/release/template/scripts/lib.sh sh_c chmod -w ./ci/release/template/scripts/lib.sh
if [ -n "${CI-}" ]; then
git_assert_clean
fi

View file

@ -47,23 +47,32 @@ if [ -n "${DEBUG-}" ]; then
set -x set -x
fi fi
export COLOR
if ! [ "${COLOR-}" = 0 -o "${COLOR-}" = false ]; then
if [ "${COLOR-}" = 1 -o "${COLOR-}" = true -o -t 1 ]; then
export _COLOR=1
fi
fi
tput() { tput() {
if [ "${COLOR-}" = 0 -o "${COLOR-}" = false ]; then if should_color; then
return 0
fi
if [ "${COLOR-}" = 1 -o "${COLOR-}" = true -o -t 1 ]; then
TERM=${TERM:-xterm-256color} command tput "$@" TERM=${TERM:-xterm-256color} command tput "$@"
fi fi
} }
should_color() {
if [ -n "${COLOR-}" ]; then
if [ "${COLOR-}" = 0 -o "${COLOR-}" = false ]; then
_COLOR=0
return 1
elif [ "${COLOR-}" = 1 -o "${COLOR-}" = true ]; then
_COLOR=1
return 0
else
printf '$COLOR must be 0, 1, false or true but got %s' "$COLOR" >&2
fi
fi
if [ -t 1 ]; then
_COLOR=1
return 0
else
return 1
fi
}
setaf() { setaf() {
tput setaf "$1" tput setaf "$1"
shift shift
@ -100,10 +109,10 @@ printfp() {(
if [ -z "${FGCOLOR-}" ]; then if [ -z "${FGCOLOR-}" ]; then
FGCOLOR="$(get_rand_color "$prefix")" FGCOLOR="$(get_rand_color "$prefix")"
fi fi
printf '%s' "$(setaf "$FGCOLOR" "$prefix")" setaf "$FGCOLOR" "[$prefix]"
if [ $# -gt 0 ]; then if [ $# -gt 0 ]; then
printf ': ' printf ' '
printf "$@" printf "$@"
fi fi
)} )}
@ -112,7 +121,8 @@ catp() {
prefix="$1" prefix="$1"
shift shift
sed "s/^/$(printfp "$prefix" '')/" should_color || true
sed "s/^/$(COLOR=${_COLOR-} printfp "$prefix" '')/"
} }
repeat() { repeat() {
@ -126,27 +136,30 @@ strlen() {
} }
echoerr() { echoerr() {
FGCOLOR=1 echop err "$*" | humanpath>&2 FGCOLOR=1 logp err "$*" | humanpath>&2
} }
caterr() { caterr() {
FGCOLOR=1 catp err "$@" | humanpath >&2 FGCOLOR=1 logpcat err "$@" | humanpath >&2
} }
printferr() { printferr() {
FGCOLOR=1 printfp err "$@" | humanpath >&2 FGCOLOR=1 logfp err "$@" | humanpath >&2
} }
logp() { logp() {
echop "$@" | humanpath >&2 should_color >&2 || true
COLOR=${_COLOR-} echop "$@" | humanpath >&2
} }
logfp() { logfp() {
printfp "$@" | humanpath >&2 should_color >&2 || true
COLOR=${_COLOR-} printfp "$@" | humanpath >&2
} }
logpcat() { logpcat() {
catp "$@" | humanpath >&2 should_color >&2 || true
COLOR=${_COLOR-} catp "$@" | humanpath >&2
} }
log() { log() {
@ -169,6 +182,10 @@ warnf() {
FGCOLOR=3 logfp warn "$@" FGCOLOR=3 logfp warn "$@"
} }
warncat() {
FGCOLOR=3 logpcat warn "$@"
}
sh_c() { sh_c() {
FGCOLOR=3 logp exec "$*" FGCOLOR=3 logp exec "$*"
if [ -z "${DRY_RUN-}" ]; then if [ -z "${DRY_RUN-}" ]; then

View file

@ -53,23 +53,32 @@ if [ -n "${DEBUG-}" ]; then
set -x set -x
fi fi
export COLOR
if ! [ "${COLOR-}" = 0 -o "${COLOR-}" = false ]; then
if [ "${COLOR-}" = 1 -o "${COLOR-}" = true -o -t 1 ]; then
export _COLOR=1
fi
fi
tput() { tput() {
if [ "${COLOR-}" = 0 -o "${COLOR-}" = false ]; then if should_color; then
return 0
fi
if [ "${COLOR-}" = 1 -o "${COLOR-}" = true -o -t 1 ]; then
TERM=${TERM:-xterm-256color} command tput "$@" TERM=${TERM:-xterm-256color} command tput "$@"
fi fi
} }
should_color() {
if [ -n "${COLOR-}" ]; then
if [ "${COLOR-}" = 0 -o "${COLOR-}" = false ]; then
_COLOR=0
return 1
elif [ "${COLOR-}" = 1 -o "${COLOR-}" = true ]; then
_COLOR=1
return 0
else
printf '$COLOR must be 0, 1, false or true but got %s' "$COLOR" >&2
fi
fi
if [ -t 1 ]; then
_COLOR=1
return 0
else
return 1
fi
}
setaf() { setaf() {
tput setaf "$1" tput setaf "$1"
shift shift
@ -106,10 +115,10 @@ printfp() {(
if [ -z "${FGCOLOR-}" ]; then if [ -z "${FGCOLOR-}" ]; then
FGCOLOR="$(get_rand_color "$prefix")" FGCOLOR="$(get_rand_color "$prefix")"
fi fi
printf '%s' "$(setaf "$FGCOLOR" "$prefix")" setaf "$FGCOLOR" "[$prefix]"
if [ $# -gt 0 ]; then if [ $# -gt 0 ]; then
printf ': ' printf ' '
printf "$@" printf "$@"
fi fi
)} )}
@ -118,7 +127,8 @@ catp() {
prefix="$1" prefix="$1"
shift shift
sed "s/^/$(printfp "$prefix" '')/" should_color || true
sed "s/^/$(COLOR=${_COLOR-} printfp "$prefix" '')/"
} }
repeat() { repeat() {
@ -132,27 +142,30 @@ strlen() {
} }
echoerr() { echoerr() {
FGCOLOR=1 echop err "$*" | humanpath>&2 FGCOLOR=1 logp err "$*" | humanpath>&2
} }
caterr() { caterr() {
FGCOLOR=1 catp err "$@" | humanpath >&2 FGCOLOR=1 logpcat err "$@" | humanpath >&2
} }
printferr() { printferr() {
FGCOLOR=1 printfp err "$@" | humanpath >&2 FGCOLOR=1 logfp err "$@" | humanpath >&2
} }
logp() { logp() {
echop "$@" | humanpath >&2 should_color >&2 || true
COLOR=${_COLOR-} echop "$@" | humanpath >&2
} }
logfp() { logfp() {
printfp "$@" | humanpath >&2 should_color >&2 || true
COLOR=${_COLOR-} printfp "$@" | humanpath >&2
} }
logpcat() { logpcat() {
catp "$@" | humanpath >&2 should_color >&2 || true
COLOR=${_COLOR-} catp "$@" | humanpath >&2
} }
log() { log() {
@ -175,6 +188,10 @@ warnf() {
FGCOLOR=3 logfp warn "$@" FGCOLOR=3 logfp warn "$@"
} }
warncat() {
FGCOLOR=3 logpcat warn "$@"
}
sh_c() { sh_c() {
FGCOLOR=3 logp exec "$*" FGCOLOR=3 logp exec "$*"
if [ -z "${DRY_RUN-}" ]; then if [ -z "${DRY_RUN-}" ]; then