Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: bin/publish shell script fixes #2162

Merged
merged 6 commits into from
Jun 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 56 additions & 19 deletions bin/publish
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env bash
set -e
USAGE="Publish a new release of a tokio crate

USAGE:
Expand All @@ -10,11 +9,15 @@ OPTIONS:
-d, --dry-run Perform a dry run (do not publish or tag the release)
-h, --help Show this help text and exit"

set -euo pipefail

cd "$(dirname "$0")"/..

DRY_RUN=""
VERBOSE=""

err() {
echo -e "\e[31m\e[1merror:\e[0m $@" 1>&2;
echo -e "\e[31m\e[1merror:\e[0m" "$@" 1>&2;
}

status() {
Expand All @@ -31,20 +34,40 @@ verify() {
exit 1
fi

if ! cargo list | grep -q "hack"; then
status "Installing" "cargo-hack"
cargo install cargo-hack
if ! cargo --list | grep -q "hack"; then
err "missing cargo-hack executable"
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

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
tracing-subscriber)
# for tracing-subscriber, don't test a complete powerset because
# there are lots of feature flags
INCLUDE_FEATURES=(fmt ansi json registry env-filter)
${CARGO_HACK[@]} --include-features "${INCLUDE_FEATURES[*]}"
"${CARGO_HACK[@]}" --include-features "${INCLUDE_FEATURES[*]}"
CARGO_HACK_STATUS="$?"
;;
tracing)
Expand All @@ -58,17 +81,17 @@ verify() {
release_max_level_info release_max_level_debug
release_max_level_trace
)
${CARGO_HACK[@]} --exclude-features "${EXCLUDE_FEATURES[*]}"
"${CARGO_HACK[@]}" --exclude-features "${EXCLUDE_FEATURES[*]}"
CARGO_HACK_STATUS="$?"
;;
*)
${CARGO_HACK[@]}
"${CARGO_HACK[@]}"
CARGO_HACK_STATUS="$?"
;;
esac

if "$CARGO_HACK_STATUS" ; then
err "$CRATE did not build with all feature combinations!"
if [[ "$CARGO_HACK_STATUS" != "0" ]] ; then
err "$CRATE did not build with all feature combinations (cargo hack exited with $CARGO_HACK_STATUS)!"
exit 1
fi

Expand All @@ -81,11 +104,25 @@ verify() {

release() {
status "Releasing" "$CRATE v$VERSION"
cargo package $VERBOSE
cargo publish $VERBOSE $DRY_RUN
local CARGO_PACKAGE=(cargo package)
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"
if [ -n "$DRY_RUN" ]; then
if [[ "$DRY_RUN" ]]; then
echo "# git tag $TAG && git push --tags"
else
git tag "$TAG" && git push --tags
Expand All @@ -111,9 +148,9 @@ case "$1" in
exit 1
;;
*) # crate or version
if [ -z "$CRATE" ]; then
if [[ -z "${CRATE+crate}" ]]; then
CRATE="$1"
elif [ -z "$VERSION" ]; then
elif [[ -z "${VERSION+version}" ]]; then
VERSION="$1"
else
err "unknown positional argument \"$1\""
Expand All @@ -126,19 +163,19 @@ esac
done
# set -- "${POSITIONAL[@]}"

if [ -z "$VERSION" ]; then
if [[ -z "${VERSION+version}" ]]; then
err "no version specified!"
HELP=1
fi

if [ -n "$CRATE" ]; then
if [[ "${CRATE+crate}" ]]; then
TAG="$CRATE-$VERSION"
else
err "no crate specified!"
HELP=1
fi

if [ -n "$HELP" ]; then
if [[ "${HELP+help}" ]]; then
echo "$USAGE"
exit 1
fi
Expand Down