|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +function check() { |
| 4 | + if [ $? != 0 ] |
| 5 | + then |
| 6 | + abort "$1 failed." |
| 7 | + fi |
| 8 | +} |
| 9 | + |
| 10 | +function abort() { |
| 11 | + echo -e "\033[33m$1\033[0m" |
| 12 | + echo -e "\033[31;1mTAGGING FAILED\033[0m" |
| 13 | + exit 1 |
| 14 | +} |
| 15 | + |
| 16 | +function info() { |
| 17 | + echo -e "\033[34m$1\033[0m" |
| 18 | +} |
| 19 | + |
| 20 | +# check if everything is committed |
| 21 | +CLEAN=`git status -s` |
| 22 | +if [ ! -z "$CLEAN" ] |
| 23 | +then |
| 24 | + abort "Working directory not clean. Please commit all changes before tagging." |
| 25 | +fi |
| 26 | + |
| 27 | +info "Fetching origin..." |
| 28 | +git fetch origin > /dev/null |
| 29 | + |
| 30 | +# get current branch |
| 31 | +BRANCH=`git branch | grep "^*" | cut -d " " -f 2` |
| 32 | +info "Current branch is $BRANCH." |
| 33 | + |
| 34 | +# check if local branch is origin branch |
| 35 | +LOCAL_COMMIT=`git show --format="%H" $BRANCH` |
| 36 | +ORIGIN_COMMIT=`git show --format="%H" origin/$BRANCH` |
| 37 | + |
| 38 | +if [ "$LOCAL_COMMIT" != "$ORIGIN_COMMIT" ] |
| 39 | +then |
| 40 | + abort "Local $BRANCH is not up to date." |
| 41 | +fi |
| 42 | + |
| 43 | +pytest -vs --cache-clear |
| 44 | +check "pytest" |
| 45 | + |
| 46 | +python setup.py sdist bdist_wheel |
| 47 | +twine check dist/*.whl |
| 48 | +check "packaging" |
| 49 | + |
| 50 | +# get the version |
| 51 | +VERSION=`python setup.py --version` |
| 52 | +info "Current version $VERSION" |
| 53 | + |
| 54 | +# check if tag to create has already been created |
| 55 | +EXISTS=`git tag | grep $VERSION` |
| 56 | +if [ "$VERSION" == "$EXISTS" ] |
| 57 | +then |
| 58 | + abort "Revision $VERSION already tagged." |
| 59 | +fi |
| 60 | + |
| 61 | +# check if VERSION is in head of CHANGES.rst |
| 62 | +REV_NOTE=`grep "$VERSION" CHANGES.rst` |
| 63 | +if [ -z "$REV_NOTE" ] |
| 64 | +then |
| 65 | + abort "No notes for revision $VERSION found in CHANGES.rst" |
| 66 | +fi |
| 67 | + |
| 68 | +info "Creating tag $VERSION..." |
| 69 | +git tag -a "$VERSION" -m "Tag release for revision $VERSION" |
| 70 | +git push --tags |
| 71 | +info "Done." |
0 commit comments