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

Bumping version clears all previous yaml comments #17

Open
jgsmarques opened this issue May 28, 2021 · 1 comment
Open

Bumping version clears all previous yaml comments #17

jgsmarques opened this issue May 28, 2021 · 1 comment

Comments

@jgsmarques
Copy link

Hi,

I'm using this plugin to bump a chart version, and event though it works as intended, it removes all comments that I have in the chart. Is there any way to prevent this?

Original file:

apiVersion: v2
name: testchart
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# 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.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
appVersion: 1.16.0

Modified file after plugin is executed:

apiVersion: v2
appVersion: 1.16.0
description: A Helm chart for Kubernetes
name: testchart
type: application
version: 0.1.1

Thank you!

@mbenabda
Copy link
Owner

Hi there,

Sorry for the (way way) overdue response.

To change the version of a Chart, this CLI parses the Chart.yml file, changes the value of its "version" key, then re-writes the Chart.yml file back to disk, and leverages the https://github.com/krishicks/yaml-patch library to do so.

That library doesn't keep the comments in its internal representation of the read YAML document, and at the time, I didn't find any go yaml parser implementation that would. Now, it appears that https://github.com/go-yaml/yaml/tree/v3 supports YAML comments.

I will give the migration a go, but I cannot commit on a deadline since i do not use Helm these days. I am happy to accept a PR though :)

In the meantime, one can use a combination of the two following CLIs to achieve results similar to this one, while preserving comments:

To increment the patch segment of a chart's version, run:

yq -i ".version = \"$(semver -i patch `yq '.version' Chart.yml`)\"" Chart.yml

@mbenabda mbenabda reopened this Feb 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants