#!/bin/bash declare newversion declare current_version declare sure current_version="$(grep -E version ./httpretty/version.py | sed 's,version *= *.\(\([0-9]*[.]*\)\{3\,4\}\).,\1,g')" echo -en "The current version is \033[1;33m$current_version\033[0m, type a new one\n\033[1;32mnew version:\033[0m " read -r newversion function find_files () { for name in $(find . -name 'README.rst' -or -name version.py -or -name conf.py | grep -v '\(\.venv\|build\)[/]'); do echo "${name}" done } function update_files (){ find_files | xargs gsed -i "s,$current_version,$newversion,g" } function revert_files (){ find_files | xargs gsed -i "s,$newversion,$current_version,g" } echo -en "\033[A\033[A\rI will make a new commit named \033[1;33m'New release $newversion'\033[0m\n" echo -en "Are you sure? [\033[1;32myes\033[0m or \033[1;31mno\033[0m]\n" read -r sure if [ "${sure}" == "yes" ]; then echo "updating relevant files with new version..." if update_files; then echo "committing and pushing changes..." echo -en "New release: \033[1;32m$newversion\033[0m\n" if git add -f $(find_files); then if git commit $(find_files) -m "New release: $newversion"; then if git push; then echo "creating tag ${newversion}..." if git tag "${newversion}"; then echo "pushing tag ${newversion}..." git push --tags else echo "failed to create tag ${newversion}" echo "you might want to revert the last commit and check what happened" exit 1 fi else echo "failed to push, skipping release and reverting changes" revert_files exit 1 fi else echo "failed to commit, skipping release and reverting changes" revert_files exit 1 fi else echo "no files to git add, skipping release" exit 1 fi; else echo "no files were updated, skipping release" exit 1 fi else echo "kthankxbye" fi