Skip to content

Commit

Permalink
Add publish script
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Jun 23, 2022
1 parent 0256b26 commit 9f6d0c6
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tools/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
cd "$(dirname "$0")"/..

# Publish a new release.
#
# USAGE:
# ./tools/publish.sh <CRATE> <VERSION>

bail() {
echo >&2 "error: $*"
exit 1
}

crate="${1:?}"
version="${2:?}"
version="${version#v}"
tag="${crate}-${version}"
if [[ ! "${version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z\.-]+)?(\+[0-9A-Za-z\.-]+)?$ ]]; then
bail "invalid version format '${version}'"
fi
if [[ $# -gt 2 ]]; then
bail "invalid argument '$3'"
fi

# Make sure there is no uncommitted change.
git diff --exit-code
git diff --exit-code --staged

# Make sure the same release has not been created in the past.
if gh release view "${tag}" &>/dev/null; then
bail "tag '${tag}' has already been created and pushed"
fi

if ! git branch | grep -q '\* master'; then
bail "current branch is not 'master'"
fi

git tag "${tag}"

(
if [[ "${crate}" != "crossbeam" ]]; then
cd "${crate}"
fi
cargo publish
)

git push origin --tags

0 comments on commit 9f6d0c6

Please sign in to comment.