automate release with scripts. #20

Merged
merged 7 commits into from Mar 19, 2017
View
@@ -3,3 +3,4 @@ work/
bin/
vendor/
.DS_Store
+rnzoo
View
@@ -0,0 +1,98 @@
+#!/bin/bash
+
+function usage() {
+ cat <<_EOB
+Create Pull Request that homebrew-rnzoo for new version.
+Usage:
+ $(basename $0) <version> <sha256hash>
+
+_EOB
+}
+
+function err_exit() {
+ echo $* >&2
+ exit 1
+}
+
+function main() {
+ # TODO check version format
+ ver=$1
+ if [ -z "$ver" ]; then
+ err_exit "version is empty. it is required"
+ fi
+
+ # TODO check hex format
+ s256=$2
+ if [ -z "$s256" ]; then
+ err_exit "sha256 is empty. it is required"
+ fi
+
+ tmpdir=$(mktemp -d /tmp/genpr.XXXXXX)
+ echo "made" $tmpdir
+
+ echo "clone homebrew-rnzoo repo..."
+ tmprepo="$tmpdir/homebrew-rnzoo"
+ git clone git@github.com:reiki4040/homebrew-rnzoo.git $tmprepo
+
+ echo "creating version branch and editing version and sha256 hash..."
+ cd $tmprepo
+ bname="version/${ver}"
+ git checkout -b ${bname}
+
+ echo $ver | grep -q "-"
+ if [ $? == 1 ]; then
+ # replace version and sha256 (version is homebrew variable. so do not use '=')
+ # version format is not allow v prefix (NG: v0.1.0, OK: 0.1.0)
+ v=${ver/v/}
+ cat rnzoo.rb | sed -e "s/version \".*\"/version \"${v}\"/" | sed -e "s/normal_sha256 = \".*\"/normal_sha256 = \"${s256}\"/" > rnzoo.rb.new
+ else
+ # replace devel_version and sha256
+ cat rnzoo.rb | sed -e "s/devel_version = \".*\"/devel_version = \"${ver}\"/" | sed -e "s/devel_sha256 = \".*\"/devel_sha256 = \"${s256}\"/" > rnzoo.rb.new
+ fi
+
+ mv rnzoo.rb.new rnzoo.rb
+
+ echo "brew audit..."
+ brew audit --strict --online rnzoo.rb
+ if [ $? != 0 ]; then
+ err_exit "failed brew audit, so stop."
+ fi
+ echo "brew audit is OK"
+
+ echo "git commit..."
+ git commit -a -m "rnzoo version ${ver}"
+
+ if [ -z "$push_origin" ]; then
+ echo "commit done. if you want create pull request, then specify -p option."
+ exit 0
+ fi
+
+ echo "pushing to github..."
+ git push origin ${bname}
+
+ echo "creating Pull Request"
+ hub pull-request -m "update rnzoo ${ver}" -b "reiki4040:master" -h "reiki4040:${bname}"
+
+ echo "done."
+ echo "if you want remove temp files, please remove $tmprepo manually"
+}
+
+push_origin=""
+while getopts hp OPT
+do
+ case $OPT in
+ h) usage
+ exit 0
+ ;;
+ p)
+ push_origin="1"
+ ;;
+ *) echo "unknown option."
+ usage
+ exit 1
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+main $1 $2
View
@@ -1,46 +0,0 @@
-#!/bin/sh
-version=0.4.0
-
-WORK_DIR="work"
-DEST_DIR="archives"
-current=$(pwd)
-if [ -z "$current" ]; then
- exit 1
-fi
-oss="darwin"
-archs="amd64"
-
-files="LICENSE README.md"
-
-mkdir -p $current/$DEST_DIR
-
-for os in $oss
-do
- for arch in $archs
- do
- echo "start $os/$arch build and create archive file."
- rnzoo_prefix="rnzoo-$version-$os-$arch"
- archive_dir="$current/$WORK_DIR/$rnzoo_prefix"
- mkdir -p "$archive_dir"
-
- # build
- cd $current
- HASH=$(git rev-parse --verify HEAD)
- GOVERSION=$(go version)
- GOOS="$os" GOARCH="$arch" go build -o "$archive_dir/rnzoo" -ldflags "-X main.version=$version -X main.hash=$HASH -X \"main.goversion=$GOVERSION\""
-
- # something
- for f in $files
- do
- cp -a $current/$f $archive_dir/
- done
-
- echo "creating zip archive..."
- cd $current/$WORK_DIR
- zip -r "$rnzoo_prefix".zip "./$rnzoo_prefix"
- mv "$rnzoo_prefix".zip $current/$DEST_DIR/
- shasum -a 256 "$current/$DEST_DIR/$rnzoo_prefix.zip"
- echo "finished $os/$arch build and create archive file."
- echo ""
- done
-done
View
@@ -0,0 +1,55 @@
+#!/bin/bash
+
+function usage() {
+ cat <<_EOB
+rnzoo release script.
+
+ - build rnzoo binary and create archive. (call build_with_docker.sh)
+ - create github release and upload archive. (call hub command)
+ - create homebrew pull request that new version (call gen_brew_pr.sh)
+
+[Options]
+ -d: develop version release
+
+_EOB
+}
+
+function releaseflow() {
+ bash build_with_docker.sh -a
+
+ # TODO get version and archive path from build_with_docker...
+ version=$(git describe --tags)
+ archive="archives/rnzoo-${version}-darwin-amd64.tar.gz"
+ ls $archive> /dev/null 2>&1
+ if [ $? != 0 ]; then
+ err_exit "not found archive $archive"
+ fi
+
+ # create github release. dev version is pre release
+ echo $version | grep -q "-"
+ pre_release=""
+ if [ $? == 1 ]; then
+ pre_release="-p"
+ fi
+ hub release create $pre_release -a $archive -m "$version" "$version"
+
+ # create homebrew Pull Request
+ sha256=$(shasum -a 256 $archive | cut -d' ' -f1)
+ bash gen_brew_pr.sh -p "$version" "$sha256"
+}
+
+while getopts h OPT
+do
+ case $OPT in
+ h) usage
+ exit 0
+ ;;
+ *) echo "unknown option."
+ usage
+ exit 1
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+releaseflow