Update tools/publish.sh

This commit is contained in:
Taiki Endo
2021-12-30 21:55:24 +09:00
parent 0a6b5bf893
commit 6132093ff5

View File

@@ -16,42 +16,20 @@ bail() {
echo >&2 "error: $*"
exit 1
}
warn() {
echo >&2 "warning: $*"
}
info() {
echo >&2 "info: $*"
}
tools=(
cargo-hack
cargo-llvm-cov
cargo-minimal-versions
parse-changelog
cross
shellcheck
shfmt
)
# Parse arguments.
version="${1:?}"
version="${version#v}"
tag="v${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 [[ "${2:-}" == "--dry-run" ]]; then
dry_run="--dry-run"
shift
bail "invalid version format '${version}'"
fi
if [[ $# -gt 1 ]]; then
bail "invalid argument: '$2'"
bail "invalid argument '$2'"
fi
if [[ -z "${dry_run:-}" ]]; then
git diff --exit-code
git diff --exit-code --staged
fi
# Make sure there is no uncommitted change.
git diff --exit-code
git diff --exit-code --staged
# Make sure that a valid release note for this version exists.
# https://github.com/taiki-e/parse-changelog
@@ -64,13 +42,15 @@ if gh release view "${tag}" &>/dev/null; then
bail "tag '${tag}' has already been created and pushed"
fi
# Exit if dry run.
if [[ -n "${dry_run:-}" ]]; then
warn "skip creating a new tag '${tag}' due to dry run"
exit 0
fi
info "creating and pushing a new tag '${tag}'"
tools=(
cargo-hack
cargo-llvm-cov
cargo-minimal-versions
parse-changelog
cross
shellcheck
shfmt
)
(
set -x
@@ -80,9 +60,9 @@ info "creating and pushing a new tag '${tag}'"
git push origin --tags
sleep 10
version_tag=v1
version_tag="v${version%%.*}"
git checkout -b "${version_tag}"
git push origin -f refs/heads/"${version_tag}"
git push origin refs/heads/"${version_tag}"
if git --no-pager tag | grep -E "^${version_tag}$" &>/dev/null; then
git tag -d "${version_tag}"
git push --delete origin refs/tags/"${version_tag}"