Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File search and replace fails with Helm charts #117

Closed
jpettit opened this issue Jan 10, 2020 · 12 comments
Closed

File search and replace fails with Helm charts #117

jpettit opened this issue Jan 10, 2020 · 12 comments
Labels

Comments

@jpettit
Copy link

jpettit commented Jan 10, 2020

I'm attempting to use bump2version to update a Helm chart. A helm chart is a yaml file that contains the following two version fields on two separate lines:

version: {semver}
appVersion: {semver}

A .bumpversion.cfg that contains a file search and replace will work if only patching any of [major|minor|patch], but doesn't seem to work when patching something like build.

What does work when bumping [major|minor|patch] via bump2version patch:

# .bumpversion.cfg
...

[bumpversion:file:./Chart.yaml]
search = version: {current_version}
replace = version: {new_version}

# only changes version line and not appVersion
# version: 0.0.0 becomes version: 0.0.1 in the file

What does NOT work when bumping build via bump2version build

# .bumpversion.cfg same as above irrelevant if I define a build part config or not

# changes both version and appVersion lines like so:
version: version: 0.0.1
appVersion: version: 0.0.1

😕

@florisla
Copy link
Collaborator

florisla commented Jan 11, 2020

Could you share your full bumpversion.cfg content, and show the output of bumpversion with the --verbose flag?

@c4urself
Copy link
Owner

you can do multiple lines with the search/replace as long as you format it correctly in your bumpversion.cfg:

[bumpversion]
current_version = 0.0.1

[bumpversion:file:./Chart.yaml]
search = version: {current_version}
	appVersion: {current_version}
replace = version: {new_version}
	appVersion: {new_version}

@florisla
Copy link
Collaborator

@jpettit For full semver support, you could use

parse = (?P<major>\d+).(?P<minor>\d+).(?P<patch>\d+)(-(?P<pre_release>[^\+]+))?(\+(?P<meta>.*))?
serialize =
    {major}.{minor}.{patch}-{pre_release}+{meta}
    {major}.{minor}.{patch}-{pre_release}
    {major}.{minor}.{patch}

If version and appVersion should both have the same version, you could use the multi-line trick as suggested above by @c4urself, or duplicate the file part of your configuration as shown in #111 (comment).

[bumpversion:file:./Chart.yaml]
search = version: {current_version}
replace = version: {new_version}

[bumpversion:file:././Chart.yaml]
search = appVersion: {current_version}
replace = appVersion: {new_version}

@jpettit
Copy link
Author

jpettit commented Jan 13, 2020

@florisla @c4urself

When I attempt the multi-line search and replace I get the following, which seems to duplicate the old version context:

$ bump2version patch --allow-dirty --list
current_version=0.0.2
commit=False
tag=False
parse=(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(-(?P<pre_release>[^\+]+)?(?P<meta>.*))?
serialize=
{major}.{minor}.{patch}-{pre_release}+{meta}
{major}.{minor}.{patch}-{pre_release}
{major}.{minor}.{patch}
new_version=0.0.3

 # This is the chart version. This version number should be incremented each time you make changes
 # to the chart and its templates, including the app version.
-version: 0.0.2
+version: version: 0.0.3
+appVersion: 0.0.3

 # This is the version number of the application being deployed. This version number should be
 # incremented each time you make changes to the application.
-appVersion: 0.0.2
+appVersion: version: 0.0.3
+appVersion: 0.0.3

My configuration:

[bumpversion]
current_version = 0.0.3
commit = False
tag = False
parse = (?P<major>\d+).(?P<minor>\d+).(?P<patch>\d+)(-(?P<pre_release>[^\+]+)?(?P<meta>.*))?
serialize =
	{major}.{minor}.{patch}-{pre_release}+{meta}
	{major}.{minor}.{patch}-{pre_release}
	{major}.{minor}.{patch}

[bumpversion:file:./path/to_helm/Chart.yaml]
search = version: {current_version}
	appVersion: {current_version}
replace = version: {new_version}
	appVersion: {new_version}

@c4urself
Copy link
Owner

the multiline is tricky and requires an indentation, could you share the full .bumpversion.cfg?

@jpettit
Copy link
Author

jpettit commented Jan 13, 2020

Just added - sorry.

@jpettit
Copy link
Author

jpettit commented Jan 13, 2020

Okay, the multiple [bumpversion:file:././path/to_helm/Chart.yaml] definitions works as @florisla described. I had tried this previously with a path/to_helm/Chart.yaml and it didn't work. But the ././ trick worked.

@c4urself
Copy link
Owner

weird just did a check and it works locally for me, are you on the latest version?

@jpettit
Copy link
Author

jpettit commented Jan 13, 2020

$ pip3 install --upgrade bump2version
Requirement already up-to-date: bump2version in /usr/local/lib/python3.7/site-packages (0.5.11)

Python 3.7

# /usr/local/bin/bump2version
# restore sys.stderr
  1 #!/usr/local/opt/python/bin/python3.7
...
  6 from bumpversion.cli import main
...

May want to add a --version to bump2version to spit out version info

@c4urself
Copy link
Owner

--help does that, adding --version isn't a bad idea but could get confusing

@jpettit
Copy link
Author

jpettit commented Jan 17, 2020

The solution for me was to do the following to avoid these strange issues. I got the tip from #122 to just treat pre-release and build semver parts as a commit style parse of .*.

bump2version --verbose \
            --parse "(?P<major>\d+).(?P<minor>\d+).(?P<patch>\d+)(\-(?P<commit>.*))?" \
            --serialize "{major}.{minor}.{patch}-{commit}" \
            --serialize "{major}.{minor}.{patch}" \
            --message "CICD Automatic Version {current_version} → {new_version} [skip ci]" \
            --allow-dirty --list \
            --new-version ${NEW_VERSION} \
            commit 

The above assumes I explicitly set my .bumpversion.cfg as follows:

[bumpversion]
current_version = 0.0.2-jpettit/branch+25
commit = True
tag = False
parse = (?P<major>\d+).(?P<minor>\d+).(?P<patch>\d+)(\-(?P<commit>.*))?
serialize = 
	{major}.{minor}.{patch}-{commit}
	{major}.{minor}.{patch}

[bumpversion:file:./helm/project/Chart.yaml]
search = version: {current_version}
replace = version: {new_version}

[bumpversion:file:././helm/project/Chart.yaml]
search = appVersion: {current_version}
replace = appVersion: {new_version}

And it's all working quite beautifully.

@florisla
Copy link
Collaborator

Nice to hear.

For people trying similar things, it's also an option to deliver the commit ID as an environment variable and use {$THE_ENV_VARIABLE} in your serialize.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants