Created
September 18, 2022 14:50
-
-
Save coordt/57b3146d6e5d1f5256ed66cb8861a05b to your computer and use it in GitHub Desktop.
Generate a release using generate-changelog and bump version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Generate the changelog, make a release if necessary and return the version number | |
# Pass in the path to the source repo so the appropriate __init__.py file is changed | |
SOURCE_DIR=$1 | |
# The first 20 characters of the branch name for development releases | |
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD | cut -c 1-20) | |
# Generate the changelog and get the release hint | |
RELEASE_KIND=$(generate-changelog --output release-hint) | |
# Default bumpversion options (changed when it is a development release) | |
BUMPVERSION_OPTIONS="" | |
# Default files for bumpversion to change | |
# leave blank to use the configured files | |
# overridden if it is a development release | |
CHANGE_FILES="" | |
if [[ $RELEASE_KIND == "no-release" ]]; then | |
# If no release is necessary, return the current version | |
CURRENT_VERSION=$(awk '/\[/{prefix=$0; next} $1{print prefix $0}' setup.cfg | grep "^\[bumpversion\]current_version.*" | sed -r s,"^.*= *",,) | |
echo $CURRENT_VERSION | |
exit 0 | |
elif [[ $RELEASE_KIND == "dev" ]]; then | |
# If this is a development release, don't tag the commit and only change the __init__.py file | |
BUMPVERSION_OPTIONS="$BUMPVERSION_OPTIONS --no-tag --no-configured-files" | |
CHANGE_FILES="$SOURCE_DIR/__init__.py" | |
fi | |
export BRANCH_NAME | |
NEW_VERSION=$(bumpversion $BUMPVERSION_OPTIONS --list --allow-dirty "$RELEASE_KIND" $CHANGE_FILES | grep new_version= | sed -r s,"^.*=",,) | |
echo $NEW_VERSION |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment