Skip to content

Commit

Permalink
Add tools/publish.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Jul 20, 2021
1 parent 0199662 commit 1094c80
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tools/fmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
set -euo pipefail
IFS=$'\n\t'

cd "$(cd "$(dirname "${0}")" && pwd)"/..
cd "$(cd "$(dirname "$0")" && pwd)"/..

# shellcheck disable=SC2046
if [[ -z "${CI:-}" ]]; then
Expand Down
70 changes: 70 additions & 0 deletions tools/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

set -euo pipefail
IFS=$'\n\t'

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

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

git diff --exit-code
git diff --exit-code --staged

# Parse arguments.
version="${1:?}"
tag="v${version}"
if [[ ! "${version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z_0-9\.-]+)?(\+[a-zA-Z_0-9\.-]+)?$ ]]; then
error "invalid version format: '${version}'"
exit 1
fi
if [[ "${2:-}" == "--dry-run" ]]; then
dryrun="--dry-run"
shift
fi
if [[ -n "${2:-}" ]]; then
error "invalid argument: '$2'"
exit 1
fi

# Make sure that a valid release note for this version exists.
# https://github.com/taiki-e/parse-changelog
echo "========== changes =========="
parse-changelog CHANGELOG.md "${version}"
echo "============================="

# Make sure the same release has not been created in the past.
if gh release view "${tag}" &>/dev/null; then
error "tag '${tag}' has already been created and pushed"
exit 1
fi
if git --no-pager tag | grep "${tag}" &>/dev/null; then
error "tag '${tag}' has already been created"
exit 1
fi

# Create and push tag.
if [[ -n "${dryrun:-}" ]]; then
echo "warning: skip creating a new tag '${tag}' due to dry run"
exit 0
fi

echo "info: creating and pushing a new tag '${tag}'"

set -x

git push origin main
git checkout v1
git merge main
git push origin refs/heads/v1

if git --no-pager tag | grep "v1" &>/dev/null; then
git tag -d v1
git push --delete origin refs/tags/v1
fi

git tag v1
git tag "${tag}"
git push origin --tags
git checkout main

0 comments on commit 1094c80

Please sign in to comment.