Add release script

The script handles bumping up the version number, committing, tagging
and updating the Homebrew formula. The last step requires `hub` to be
installed in order to submit a pull request to Homebrew.

/cc @sferik @hsbt

[ci skip]
This commit is contained in:
Mislav Marohnić 2014-05-26 23:34:26 +07:00
parent 273be046b1
commit e2ae87877b
2 changed files with 97 additions and 0 deletions

51
script/brew-publish Executable file
View file

@ -0,0 +1,51 @@
#!/bin/bash
# Usage: script/brew-publish <name> <version> [<gh-project>]
#
# Updates the `<name>.rb` Homebrew formula to `<version>` and sends a pull
# request with the change.
set -e
brew_name="${1?}"
version="${2?}"
if ! type -p hub >/dev/null; then
"ERROR: You have to install hub to proceed." >&2
exit 1
fi
if [ -n "$3" ]; then
gh_project="github.com/${3}"
else
gh_project="$(git remote -v | grep '^origin' | grep -oE 'github.com[:/][^/]+/[^/ ]+')"
gh_project="${gh_project%.git}"
fi
url="https://${gh_project/:/\/}/archive/${version}.tar.gz"
checksum="$(curl -fsSL "$url" | shasum | awk '{print $1}')"
if [ -z "$checksum" ]; then
echo "ERROR: calculating the checksum failed for $url" >&2
exit 1
fi
pushd "$(brew --prefix)"
git fetch -q origin master
formula="Library/Formula/${brew_name}.rb"
sed -i.bak -E "
s!^( url ).+!\\1\"${url}\"!
s!^( sha1 ).+!\\1\"${checksum}\"!
" "$formula"
rm -f "${formula}.bak"
branch="${brew_name}-${version}"
git checkout -q -B "$branch" origin/master
git commit -m "${brew_name} ${version#v}" -- "$formula"
# hackish way of getting the git remote name for user's fork
fork_remote="$(hub fork 2>&1 | grep -oE 'remote:? \S+' | tail -1 | awk '{print $2}')"
git push -u "$fork_remote" "$branch"
hub pull-request -m "${brew_name} ${version#v}"
git checkout -q -

46
script/release Executable file
View file

@ -0,0 +1,46 @@
#!/bin/bash
# Usage: script/release
#
# - checks out the master branch
# - changes version in `bin/ruby-build` to current date
# - commits and tags the change
# - pushes master + tag to GitHub
# - opens pull request to update the Homebrew formula
#
# TODO: handle making multiple releases on the same date
# TODO: publish release notes to GitHub
set -e
git fetch -q --tags origin master
existing="$(git tag --points-at HEAD)"
if [ -n "$existing" ]; then
echo "Aborting: HEAD is already tagged as '${existing}'" >&2
exit 1
fi
git checkout -q master
binfile="bin/ruby-build"
new_version="$(date '+%Y%m%d')"
version_tag="v${new_version}"
previous_tag="$(git tag | grep '^v' | sort | tail -1)"
if git diff --quiet "${previous_tag}..HEAD" -- bin share; then
echo "Aborting: No features to release since '${previous_tag}'" >&2
exit 1
fi
# current="$($binfile --version | awk '{print $2}')"
sed -i.bak -E "s!^(RUBY_BUILD_VERSION=).+!\\1\"${new_version}\"!" "$binfile"
rm -f "${binfile}.bak"
git commit -m "ruby-build ${new_version}" "$binfile"
git tag "$version_tag"
git push origin master "${version_tag}"
# git log --no-merges --format='%w(0,0,2)* %B' --reverse "${previous_tag}..HEAD^" -- bin share
script/brew-publish ruby-build "$version_tag"