Skip to content

Commit

Permalink
Improve do-release script
Browse files Browse the repository at this point in the history
  • Loading branch information
ayufan committed Jul 8, 2018
1 parent d853794 commit 2909b6c
Showing 1 changed file with 60 additions and 12 deletions.
72 changes: 60 additions & 12 deletions do-release.bash
Original file line number Diff line number Diff line change
@@ -1,17 +1,63 @@
#!/bin/bash

if [[ $# -lt 1 ]] || [[ $# -gt 3 ]]; then
echo "usage: $0 <release-version> [--force] [--dry-run]"
if [[ "$DEBUG" == 1 ]]; then
set -x
fi

usage() {
echo "usage: $0 <release-version> [--amend] [--force] [--dry-run]"
exit 1
}

if [[ $# -lt 1 ]]; then
usage
fi

if [[ " $@ " =~ " --force " ]] && ! git diff-files --quiet; then
RELEASE="$1"
COMMIT_FLAGS=""
TAG_FLAGS=""
PUSH_FLAGS=""
NO_DIRTY=1
AMEND=0
shift

for arg; do
case "$arg" in
--force)
TAG_FLAGS="$TAG_FLAGS --force"
PUSH_FLAGS="$PUSH_FLAGS --force"
NO_DIRTY=0
;;

--dry-run)
PUSH_FLAGS="$PUSH_FLAGS --dry-run"
;;

--amend)
COMMIT_FLAGS="$COMMIT_FLAGS --amend"
TAG_FLAGS="$TAG_FLAGS --force"
PUSH_FLAGS="$PUSH_FLAGS --force"
AMEND=1
;;

*)
usage
;;
esac
done

if [[ "$NO_DIRTY" == "1" ]] && ! git diff-files --quiet; then
echo "dirty working tree, commit changes"
exit 1
fi

set -e

if [[ "$AMEND" == "1" ]] && ! git show -s --format=%B | grep --quiet "^LATEST_"; then
echo "can only amend release commit"
exit 1
fi

echo "Edit changeset:"
if which editor &>/dev/null; then
editor RELEASE.md
Expand All @@ -29,20 +75,22 @@ cat Makefile.versions.mk
echo "Adding changes..."
git add RELEASE.md Makefile.versions.mk

echo "Committing $1..."
cat <<EOF | git commit -F -
v$1
echo "Creating temporary branch..."
git checkout $(git rev-parse HEAD) >/dev/null

echo "Committing $RELEASE..."
cat <<EOF | git commit $COMMIT_FLAGS -F -
v$RELEASE
$(cat Makefile.versions.mk)
EOF

if [[ " $@ " =~ " --force " ]]; then
git tag "$1" -f
else
git tag "$1"
fi
git tag "$RELEASE" $TAG_FLAGS

echo "Checking master again..."
git checkout "master"

echo "Pushing..."
git push origin "master" "$@"
git push origin "$RELEASE" $PUSH_FLAGS

echo "Done."

0 comments on commit 2909b6c

Please sign in to comment.