Skip to content

Commit

Permalink
Make bumpversion work via git tags
Browse files Browse the repository at this point in the history
  • Loading branch information
akashisama committed Sep 17, 2021
1 parent f130bd9 commit dc054fc
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 44 deletions.
16 changes: 3 additions & 13 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
[bumpversion]
current_version = 1.4.11
commit = False
tag = False
tag_name = {new_version}
tag_message = Bump version to {new_version}
message = Bump version to {new_version}
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.(?P<release>[a-z]+)(?P<dev>\d+))?
serialize =
{major}.{minor}.{patch}.{release}{dev}
serialize =
{major}.{minor}.{patch}

[bumpversion:part:release]
optional_value = prod
values =
dev
prod

[bumpversion:part:dev]

[bumpversion:file:setup.py]
search = version='{current_version}'
search = version='0.0.0'
replace = version='{new_version}'

[bumpversion:file:aodntools/__init__.py]
search = __version__ = '{current_version}'
search = __version__ = '0.0.0'
replace = __version__ = '{new_version}'

8 changes: 1 addition & 7 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,11 @@ pipeline {
sh 'git clean -xffd'
}
}
stage('set_version') {
when { not { branch "master" } }
steps {
sh './bumpversion.sh build'
}
}
stage('release') {
when { branch 'master' }
steps {
withCredentials([usernamePassword(credentialsId: env.GIT_CREDENTIALS_ID, passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
sh './bumpversion.sh release'
sh './bumpversion.sh'
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion aodntools/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.4.11'
__version__ = '0.0.0'
26 changes: 4 additions & 22 deletions bumpversion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,11 @@

set -euxo pipefail

RELEASE_BRANCH=master

bumpversion_build() {
bump2version patch
}

bumpversion_release() {
git fetch --prune origin "+refs/tags/*:refs/tags/*"
bump2version patch
VERSION=$(bump2version --list --tag --commit --allow-dirty release | grep -oP '^new_version=\K.*$')
git push --atomic origin HEAD:$RELEASE_BRANCH tag $VERSION
}

main() {
local mode=$1; shift

if [ "x${mode}" == "xbuild" ]
then
bumpversion_build
elif [ "x${mode}" == "xrelease" ]
then
bumpversion_release
fi
git fetch --prune origin "+refs/tags/*:refs/tags/*"
OLD_VERSION=$(git tag -l '*.*.*' --sort=-version:refname | head -n 1)
NEW_VERSION=$(bump2version --current-version $OLD_VERSION --list --tag --commit --allow-dirty patch | grep -oP '^new_version=\K.*$')
git push origin tag $NEW_VERSION

exit 0
}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

setup(
name=PACKAGE_NAME,
version='1.4.11',
version='0.0.0',
packages=find_packages(exclude=PACKAGE_EXCLUDES),
package_data=PACKAGE_DATA,
url='https://github.com/aodn',
Expand Down

0 comments on commit dc054fc

Please sign in to comment.