#!/bin/bash

printf "\n#######################################################\n"
echo have you confirmed that directory is ready for release?
echo make docs
echo make coverage
echo make dist
echo git commit ...
printf "#######################################################\n\n"
echo -n "proceed to release (y/n)? "
read -r answer

if [ "$answer" != "${answer#[Yy]}" ] ;then
    clean=$(git status --porcelain --untracked-files=no | wc -l)
    if [ "$clean" -lt 1 ]; then
        if [[ $# == 1 && ($1 == "patch" || $1 == "minor" || $1 == "major") ]]; then
            git checkout release
            git merge master
            bumpversion --tag --commit "$1"
            make dist
            make coverall
            twine upload dist/*.tar.gz
            git push
            git checkout master
            git merge release
            git push
            printf "\n#######################################################\n"
            echo check that remote builds are successful than push tags
            printf "\n#######################################################\n"
        else
            echo usage: ./release.sh "[patch/minor/major]"
        fi
    else
        echo working directory is not clean!
        git status --porcelain --untracked-files=no
    fi
else
    echo aborted
fi


