Skip to content

Instantly share code, notes, and snippets.

@mojavelinux
Created January 19, 2020 00:04

Revisions

  1. mojavelinux created this gist Jan 19, 2020.
    40 changes: 40 additions & 0 deletions cut-release.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    #!/usr/bin/bash

    # GEM_VERSION=1.5.0.alpha.10 NEXT_GEM_VERSION=1.5.0.alpha.11.dev ./cut-release.sh -p

    PUSH=false
    while getopts "p" option; do
    case $option in
    p) PUSH=true ;;
    esac
    done

    if [ -z "$GEM_VERSION" ]; then
    GEM_VERSION=$(bundle exec ruby -e "print (Gem::Version.new Asciidoctor::Epub3::VERSION).release")
    fi

    # TODO make sure copyright year is correct in README.adoc and LICENSE.adoc
    sed -i "/VERSION/s/'[^']\+'/'$GEM_VERSION'/" lib/*/version.rb
    sed -i "3i v$GEM_VERSION, $(date +%Y-%m-%d)" README.adoc
    #sed -i "s/^:release-version:.*/:release-version: $GEM_VERSION/" README*.adoc
    sed -i "s/^== Unreleased/== $GEM_VERSION ($(date +%Y-%m-%d)) - @mojavelinux/" CHANGELOG.adoc
    git commit -a -m "Release $GEM_VERSION"
    git tag -m "Version $GEM_VERSION" v$GEM_VERSION

    if [ $PUSH == true ]; then
    git push origin $(git describe --tags --exact-match)
    fi

    if [ -z "$NEXT_GEM_VERSION" ]; then
    NEXT_GEM_VERSION=$(bundle exec ruby -e "print (Gem::Version.new Asciidoctor::Epub3::VERSION).segments.tap {|s| s.pop if s.size == 4; s[-1] += 1 }.join('.') + '.dev'")
    fi

    sed -i "/VERSION/s/'[^']\+'/'$NEXT_GEM_VERSION'/" lib/*/version.rb
    sed -i 3d README.adoc

    read -p 'Press <Enter> once release finishes...'

    git commit -m "Begin development on next version [skip ci]" .
    if [ $PUSH == true ]; then
    git push origin $(git rev-parse --abbrev-ref HEAD)
    fi