Skip to content
Snippets Groups Projects
Commit 00f05f88 authored by Cédric OLIVIER's avatar Cédric OLIVIER
Browse files

Merge branch '52-bump2version-not-maintained-anymore' into 'master'

fix: switch from bumpversion to bump-my-version

Closes #52

See merge request to-be-continuous/python!87
parents 66e5e348 8b5c2992
No related branches found
No related tags found
No related merge requests found
...@@ -295,7 +295,7 @@ This job is **disabled by default** and allows to perform a complete release of ...@@ -295,7 +295,7 @@ This job is **disabled by default** and allows to perform a complete release of
The Python template supports two packaging systems: The Python template supports two packaging systems:
* [Poetry](https://python-poetry.org/): uses Poetry-specific [version](https://python-poetry.org/docs/cli/#version), [build](https://python-poetry.org/docs/cli/#build) and [publish](https://python-poetry.org/docs/cli/#publish) commands. * [Poetry](https://python-poetry.org/): uses Poetry-specific [version](https://python-poetry.org/docs/cli/#version), [build](https://python-poetry.org/docs/cli/#build) and [publish](https://python-poetry.org/docs/cli/#publish) commands.
* [Setuptools](https://setuptools.pypa.io/): uses [Bumpversion](https://github.com/peritus/bumpversion) as version management, [build](https://pypa-build.readthedocs.io/) as package builder and [Twine](https://twine.readthedocs.io/) to publish. * [Setuptools](https://setuptools.pypa.io/): uses [bump-my-version](https://github.com/callowayproject/bump-my-version) as version management, [build](https://pypa-build.readthedocs.io/) as package builder and [Twine](https://twine.readthedocs.io/) to publish.
The release job is bound to the `publish` stage, appears only on production and integration branches and uses the following variables: The release job is bound to the `publish` stage, appears only on production and integration branches and uses the following variables:
...@@ -314,19 +314,30 @@ The release job is bound to the `publish` stage, appears only on production and ...@@ -314,19 +314,30 @@ The release job is bound to the `publish` stage, appears only on production and
#### Setuptools tip #### Setuptools tip
If you're using a `setup.cfg` declarative file for your project Setuptools configuration, then you will have to write a If you're using a Setuptools configuration, then you will have to write a `.bumpversion.toml` or `pyproject.toml` file.
`.bumpversion.cfg` file to workaround a bug that prevents Bumpversion from updating the project version in your `setup.cfg` file.
Example of `.bumpversion.cfg` file: Example of `.bumpversion.toml` file:
```ini ```toml
[bumpversion] [tool.bumpversion]
# same version as in your setup.cfg current_version = "0.0.0"
current_version = 0.5.0 ```
Example of `pyproject.toml` file:
```toml
[project]
name = "project-name"
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
[tool.bumpversion]
current_version = "0.0.0"
[bumpversion:file:setup.cfg] [[tool.bumpversion.files]]
# any additional config here filename = "project-name/__init__.py"
# see: https://github.com/peritus/bumpversion#file-specific-configuration
``` ```
#### `semantic-release` integration #### `semantic-release` integration
......
...@@ -524,7 +524,7 @@ variables: ...@@ -524,7 +524,7 @@ variables:
fi fi
fi fi
# 2: bumpversion (+ Git commit & tag) # 2: bump-my-version (+ Git commit & tag)
if [[ "$PYTHON_BUILD_SYSTEM" == poetry* ]] if [[ "$PYTHON_BUILD_SYSTEM" == poetry* ]]
then then
maybe_install_poetry maybe_install_poetry
...@@ -539,34 +539,37 @@ variables: ...@@ -539,34 +539,37 @@ variables:
py_next_version=$(poetry version --short) py_next_version=$(poetry version --short)
# Git commit and tag # Git commit and tag
git add pyproject.toml git add pyproject.toml
# emulate Bumpversion to generate commit message # emulate bump-my-version to generate commit message
py_commit_message=$(python -c "print('$PYTHON_RELEASE_COMMIT_MESSAGE'.format(current_version='$py_cur_version', new_version='$py_next_version'))") py_commit_message=$(python -c "print('$PYTHON_RELEASE_COMMIT_MESSAGE'.format(current_version='$py_cur_version', new_version='$py_next_version'))")
git commit -m "$py_commit_message" git commit -m "$py_commit_message"
git tag "$py_next_version" git tag "$py_next_version"
else else
# Setuptools / bumpversion # Setuptools / bump-my-version
# shellcheck disable=SC2086 # shellcheck disable=SC2086
pip install ${PIP_OPTS} bumpversion pip install ${PIP_OPTS} bump-my-version
if [[ "$py_next_version" ]] if [[ "$py_next_version" ]]
then then
# explicit release version (semantic-release) # explicit release version (semantic-release)
log_info "[bumpversion] change version \\e[1;94m${py_cur_version}\\e[0m → \\e[1;94m${py_next_version}\\e[0m" log_info "[bumpversion] change version \\e[1;94m${py_cur_version}\\e[0m → \\e[1;94m${py_next_version}\\e[0m"
# create cfg in case it doesn't exist - will be updated by bumpversion # create cfg in case it doesn't exist - will be updated by bumpversion
touch .bumpversion.cfg if [[ ! "$py_cur_version" && ! -f ".bumpversion.cfg" && ! -f ".bumpversion.toml" && ! -f "pyproject.toml" && ! -f "setup.cfg" ]]
bumpversion ${TRACE+--verbose} --current-version "$py_cur_version" --commit ${PYTHON_RELEASE_COMMIT_MESSAGE+--message "$PYTHON_RELEASE_COMMIT_MESSAGE"} --tag --tag-name "{new_version}" "$py_release_part" then
log_error "Current version not defined and not version file found, set initial version at least in .bumpversion.toml or pyproject.toml"
fi
bump-my-version bump ${TRACE+--verbose} --current-version "${py_cur_version:-${PYTHON_RELEASE_START_VERSION:-0.0.0}}" --new-version "$py_next_version" --commit ${PYTHON_RELEASE_COMMIT_MESSAGE+--message "$PYTHON_RELEASE_COMMIT_MESSAGE"} --tag --tag-name "{new_version}" "$py_release_part"
elif [[ -f ".bumpversion.cfg" ]] elif [[ -f ".bumpversion.cfg" ]]
then then
# current version shall be set in .bumpversion.cfg # current version shall be set in .bumpversion.cfg
py_release_part="$PYTHON_RELEASE_NEXT" py_release_part="$PYTHON_RELEASE_NEXT"
log_info "[bumpversion] increase \\e[1;94m${py_release_part}\\e[0m" log_info "[bump-my-version bump] increase \\e[1;94m${py_release_part}\\e[0m"
bumpversion ${TRACE+--verbose} --commit ${PYTHON_RELEASE_COMMIT_MESSAGE+--message "$PYTHON_RELEASE_COMMIT_MESSAGE"} --tag --tag-name "{new_version}" "$py_release_part" bump-my-version bump ${TRACE+--verbose} --commit ${PYTHON_RELEASE_COMMIT_MESSAGE+--message "$PYTHON_RELEASE_COMMIT_MESSAGE"} --tag --tag-name "{new_version}" "$py_release_part"
elif [[ -f "setup.py" ]] elif [[ -f "setup.py" ]]
then then
# retrieve current version from setup.py # retrieve current version from setup.py
py_cur_version=$(python setup.py --version) py_cur_version=$(python setup.py --version)
py_release_part="$PYTHON_RELEASE_NEXT" py_release_part="$PYTHON_RELEASE_NEXT"
log_info "[bumpversion] increase \\e[1;94m${py_release_part}\\e[0m (from current \\e[1;94m${py_cur_version}\\e[0m)" log_info "[bump-my-version] increase \\e[1;94m${py_release_part}\\e[0m (from current \\e[1;94m${py_cur_version}\\e[0m)"
bumpversion ${TRACE+--verbose} --current-version "$py_cur_version" --commit ${PYTHON_RELEASE_COMMIT_MESSAGE+--message "$PYTHON_RELEASE_COMMIT_MESSAGE"} --tag --tag-name "{new_version}" "$py_release_part" setup.py bump-my-version bump ${TRACE+--verbose} --current-version "$py_cur_version" --commit ${PYTHON_RELEASE_COMMIT_MESSAGE+--message "$PYTHON_RELEASE_COMMIT_MESSAGE"} --tag --tag-name "{new_version}" "$py_release_part" setup.py
else else
log_error "--- setup.py or .bumpversion.cfg file required to retrieve current version: cannot perform release" log_error "--- setup.py or .bumpversion.cfg file required to retrieve current version: cannot perform release"
exit 1 exit 1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment