callowayproject / bump-my-version

A small command line tool to simplify releasing software by updating all version strings in your source code by the correct increment and optionally commit and tag the changes.
https://callowayproject.github.io/bump-my-version/
MIT License
341 stars 22 forks source link

Feature Request: bump-my-version show-bump --type <major/minor/patch> [VERSION] #231

Open hongjiaherng opened 2 months ago

hongjiaherng commented 2 months ago

Description

None

What I Did

Here's the current CLI options for show-bump in bump-my-version.

 Usage: bump-my-version show-bump [OPTIONS] [VERSION]

 Show the possible versions resulting from the bump subcommand.

╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --config-file      FILE           Config file to read most of the variables from.                                                      │
│ --ascii                           Use ASCII characters only.                                                                           │
│ --verbose      -v  INTEGER RANGE  Print verbose logging to stderr. Can specify several times for more verbosity.                       │
│ --help         -h                 Show this message and exit.                                                                          │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Is it possible to add a new option for specifying the exact bump type? For example:

bump-my-version show-bump --type patch v1.0.0 # it should gives v1.0.1 to stdout

It would be helpful for using it in CI as I don't want to have a actual file like __init__.py to track the version (no new commit in main branch after bumping version is created/needed).

So the following is what I hope to achieve:

python --version
python -m venv .venv && source .venv/bin/activate && pip install --upgrade pip --quiet
pip install -U bump-my-version --quiet

git config user.email "${CI_BOT_EMAIL}"
git config user.name "${CI_BOT_USERNAME}"

git remote set-url --push origin https://${CI_BOT_TOKEN_NAME}:${CI_BOT_ACCESS_TOKEN}@gitlab.example.com/${CI_PROJECT_PATH}.git
git push origin tag v$(bump-my-version show-bump --type ${RELEASE_TYPE})     // by default, bump-my-version already can read latest version from git tag

Or even better, allow bump-my-version to create new tag without writing to a file. Then this can be achieved:

python --version
python -m venv .venv && source .venv/bin/activate && pip install --upgrade pip --quiet
pip install -U bump-my-version --quiet

git config user.email "${CI_BOT_EMAIL}"
git config user.name "${CI_BOT_USERNAME}"

bump-my-version bump $RELEASE_TYPE    // this will create a new git tag without explicit write to any file
git remote set-url --push origin https://${CI_BOT_TOKEN_NAME}:${CI_BOT_ACCESS_TOKEN}@gitlab.example.com/${CI_PROJECT_PATH}.git
git push origin tag v$(bump-my-version show current_version)
coordt commented 2 months ago

Two things::

  1. The current, most straightforward way to get the version of a potential bump as you want it is with the show command. bump-my-version show --increment minor new_version. The show command is a legacy command that displays configuration information and allows one to show specific keys.
  2. Your question about this demonstrates the overlap of the two commands. I may not be able to get to this for a week or two.
hongjiaherng commented 2 months ago

Hey @coordt, appreciate the prompt reply!

I can achieve what I'm trying to do with the provided command. Would you deprecate the legacy command in a very near future? If this ever get deprecated, this is my current workaround:

bump-my-version show-bump --ascii | grep $RELEASE_TYPE | awk '{print $NF}'     # $RELEASE_TYPE is either 'major', 'minor', or 'patch'

For 2, I'm willing to contribute if you need another helping hand on this. Anyway, this is not a very rushed requirement on my project too.

reneleonhardt commented 1 month ago

@hongjiaherng FYI my PR last year provided that exact functionality (show the next number for specific type): https://github.com/callowayproject/bump-my-version/pull/88