bumpver icon indicating copy to clipboard operation
bumpver copied to clipboard

[Feature request] Support for KeepAChangelog

Open XF-FW opened this issue 3 years ago • 3 comments

Hey. I'm using KeepAChangelog to track of the changes of a project.

I wanted to use bumpver to update the Unreleased part to the just bumped version, but it doesn't seem like the current replacement system can do this, for a few reasons:

  • Can't replace arbitrary text.
  • Doesn't have a placeholder, for the current date.
  • I don't think it needs group capturing, but it was handy, using it, writing the script below.

For reference, this is my (really ugly) script, that does that for me:

#script.sh (lines 1-8)
#!/usr/bin/env bash

NEW_VERSION=$(grep "^current_version =" pyproject.toml | grep -o '".*"' | sed 's/"//g' | sed 's/^v//')

sed -i "s/\[Unreleased\]: \(.*\)/[Unreleased]: \1\n\[$NEW_VERSION\]: \1/" CHANGELOG.md
sed -i -z "s/HEAD/v$NEW_VERSION/2" CHANGELOG.md
sed -i -z "s/compare\/.*\.\.\.HEAD/compare\/v$NEW_VERSION...HEAD/1" CHANGELOG.md
sed -i "s/## \[Unreleased\]/## \[Unreleased\]\n\n## \[$NEW_VERSION\] - $(date --iso)/" CHANGELOG.md

It's far from ideal. First, I'm sure it has a few bugs (although, you know, it works for me). Second, I need to use no-commit, so that I can manually commit the changes from the script.

Is this something, you would be open to? If so, I guess, there's a worthy discussion to have, if you would prefer making the current replacement system, quite a bit more powerful (maybe too much so), or a dedicated solution for KeepAChangelog. Personally, I think the first solution would be more appropriate, but lmk what you think. Thank you.

Quick edit: Another option would be to allow to run arbitrary scripts when running update and git adding the changed files before commiting.

XF-FW avatar Apr 26 '22 18:04 XF-FW

Doesn't seem like an easy change. Could you start by specifying how you think the configuration might look for this?

mbarkhau avatar Apr 28 '22 07:04 mbarkhau

I thought about it for a while (I'm the original author of the issue - The account I've used to post it is my work account) and these are my thoughts on it:

My 3rd option - allow to run arbitrary scripts when running update is likely the one with the best tradeoffs. It allows bumpver to be decoupled with whatever changelog format that the users want to use and it doesn't add the complexity of making a replacement system more powerful - which could also become confusing. One thing I have in mind, is to use a different package (maybe python-kacl), to handle such update. If this worked properly, we could also add a recipe in the README.md for people to copy into their configuration.

My proposed configuration, with that in mind, is a simple one:

[bumpver]
...
before_commit = './executable'

The value could be a path to an executable or an executable in PATH. It would run after the changes are made to the version strings, but before git commit. It would not run if commit = false.

What do you think?

If you're okay with it, I can try to create a pull request. It might take me a while, between work and life in general, but I think I should be able to do it. If you can think of any issues I might face, I would be happy to hear them.

Thanks!

Qu4tro avatar May 08 '22 00:05 Qu4tro

What do you think?

If you're okay with it, I can try to create a pull request.

Sounds like a plan.

  1. Presumably the path is relative to the config file.
  2. If the script has exit code != 0, maybe the further execution is aborted.

The places you likely want to add your code: https://github.com/mbarkhau/bumpver/blob/master/src/bumpver/config.py#L121 https://github.com/mbarkhau/bumpver/blob/master/src/bumpver/cli.py#L601

mbarkhau avatar Jun 04 '22 22:06 mbarkhau

I'm going to take this up. I think I will add a pre_commit_hook and a post_commit_hook. The reason behind this is if you modify a file in the pre_commit_hook the state of the repository is considered dirty and you must commit those changes in order to continue. This way you will always end up with two commits. While in the post_commit_hook you can use git commit --amend which results in only one commit in the end, e.g. Release 1.2.3.

I think it's also a good idea to set two environment variables BUMPVER_CURRENT_VERSION and BUMPVER_NEW_VERSION so those can be used in the hook scripts.

malnvenshorn avatar Jul 18 '23 10:07 malnvenshorn