chore: bin/publish shell script fixes (#2162)

* fix use of `cargo --list` in bin/publish
* fix shellcheck lints in bin/publish
* set -euo pipefail
* fix cargo hack exit status check
* fix wrong emptystring args
* prompt before installing cargo-hack

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
This commit is contained in:
Eliza Weisman 2022-06-11 12:34:09 -07:00
parent 5d90bdc48e
commit e793b0b06a

View File

@ -1,5 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e
USAGE="Publish a new release of a tokio crate USAGE="Publish a new release of a tokio crate
USAGE: USAGE:
@ -10,11 +9,15 @@ OPTIONS:
-d, --dry-run Perform a dry run (do not publish or tag the release) -d, --dry-run Perform a dry run (do not publish or tag the release)
-h, --help Show this help text and exit" -h, --help Show this help text and exit"
set -euo pipefail
cd "$(dirname "$0")"/..
DRY_RUN="" DRY_RUN=""
VERBOSE="" VERBOSE=""
err() { err() {
echo -e "\e[31m\e[1merror:\e[0m $@" 1>&2; echo -e "\e[31m\e[1merror:\e[0m" "$@" 1>&2;
} }
status() { status() {
@ -31,20 +34,40 @@ verify() {
exit 1 exit 1
fi fi
if ! cargo list | grep -q "hack"; then if ! cargo --list | grep -q "hack"; then
status "Installing" "cargo-hack" err "missing cargo-hack executable"
cargo install cargo-hack read -r -p "install it? [Y/n] " INPUT
case "$INPUT" in
[yY][eE][sS]|[yY])
status "Installing" "cargo-hack"
cargo install cargo-hack
;;
[nN][oO]|[nN])
echo "okay, exiting"
exit 1
;;
*)
err "invalid input $INPUT"
exit 1
;;
esac
fi fi
status "Checking" "if $CRATE builds across feature combinations" status "Checking" "if $CRATE builds across feature combinations"
CARGO_HACK=(cargo hack check $VERBOSE --feature-powerset --no-dev-deps) CARGO_HACK=(cargo hack check --feature-powerset --no-dev-deps)
if [[ "$VERBOSE" ]]; then
CARGO_HACK+=("$VERBOSE")
fi
case "$CRATE" in case "$CRATE" in
tracing-subscriber) tracing-subscriber)
# for tracing-subscriber, don't test a complete powerset because # for tracing-subscriber, don't test a complete powerset because
# there are lots of feature flags # there are lots of feature flags
INCLUDE_FEATURES=(fmt ansi json registry env-filter) INCLUDE_FEATURES=(fmt ansi json registry env-filter)
${CARGO_HACK[@]} --include-features "${INCLUDE_FEATURES[*]}" "${CARGO_HACK[@]}" --include-features "${INCLUDE_FEATURES[*]}"
CARGO_HACK_STATUS="$?" CARGO_HACK_STATUS="$?"
;; ;;
tracing) tracing)
@ -58,17 +81,17 @@ verify() {
release_max_level_info release_max_level_debug release_max_level_info release_max_level_debug
release_max_level_trace release_max_level_trace
) )
${CARGO_HACK[@]} --exclude-features "${EXCLUDE_FEATURES[*]}" "${CARGO_HACK[@]}" --exclude-features "${EXCLUDE_FEATURES[*]}"
CARGO_HACK_STATUS="$?" CARGO_HACK_STATUS="$?"
;; ;;
*) *)
${CARGO_HACK[@]} "${CARGO_HACK[@]}"
CARGO_HACK_STATUS="$?" CARGO_HACK_STATUS="$?"
;; ;;
esac esac
if "$CARGO_HACK_STATUS" ; then if [[ "$CARGO_HACK_STATUS" != "0" ]] ; then
err "$CRATE did not build with all feature combinations!" err "$CRATE did not build with all feature combinations (cargo hack exited with $CARGO_HACK_STATUS)!"
exit 1 exit 1
fi fi
@ -81,11 +104,25 @@ verify() {
release() { release() {
status "Releasing" "$CRATE v$VERSION" status "Releasing" "$CRATE v$VERSION"
cargo package $VERBOSE local CARGO_PACKAGE=(cargo package)
cargo publish $VERBOSE $DRY_RUN local CARGO_PUBLISH=(cargo publish)
if [[ "$VERBOSE" ]]; then
CARGO_PACKAGE+=("$VERBOSE")
CARGO_PUBLISH+=("$VERBOSE")
fi
if [[ "$DRY_RUN" ]]; then
CARGO_PUBLISH+=("$DRY_RUN")
fi
"${CARGO_PACKAGE[@]}"
"${CARGO_PUBLISH[@]}"
cargo publish "$VERBOSE" "$DRY_RUN"
status "Tagging" "$TAG" status "Tagging" "$TAG"
if [ -n "$DRY_RUN" ]; then if [[ "$DRY_RUN" ]]; then
echo "# git tag $TAG && git push --tags" echo "# git tag $TAG && git push --tags"
else else
git tag "$TAG" && git push --tags git tag "$TAG" && git push --tags
@ -111,9 +148,9 @@ case "$1" in
exit 1 exit 1
;; ;;
*) # crate or version *) # crate or version
if [ -z "$CRATE" ]; then if [[ -z "${CRATE+crate}" ]]; then
CRATE="$1" CRATE="$1"
elif [ -z "$VERSION" ]; then elif [[ -z "${VERSION+version}" ]]; then
VERSION="$1" VERSION="$1"
else else
err "unknown positional argument \"$1\"" err "unknown positional argument \"$1\""
@ -126,19 +163,19 @@ esac
done done
# set -- "${POSITIONAL[@]}" # set -- "${POSITIONAL[@]}"
if [ -z "$VERSION" ]; then if [[ -z "${VERSION+version}" ]]; then
err "no version specified!" err "no version specified!"
HELP=1 HELP=1
fi fi
if [ -n "$CRATE" ]; then if [[ "${CRATE+crate}" ]]; then
TAG="$CRATE-$VERSION" TAG="$CRATE-$VERSION"
else else
err "no crate specified!" err "no crate specified!"
HELP=1 HELP=1
fi fi
if [ -n "$HELP" ]; then if [[ "${HELP+help}" ]]; then
echo "$USAGE" echo "$USAGE"
exit 1 exit 1
fi fi