Skip to content

Commit

Permalink
fix(helm): maintain any existing comments in Chart.yaml (#1968)
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-foxmoore authored May 31, 2023
1 parent d1f891c commit 77de40e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
17 changes: 16 additions & 1 deletion __snapshots__/chart-yaml.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
exports['ChartYaml updateContent updates version in Chart.yaml 1'] = `
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: helm-test-repo
version: 1.1.0
apiVersion: v2
# renovate: image=imageName
appVersion: 2.0.0
dependencies:
- name: another-repo
version: 0.15.3
repository: linkToHelmChartRepo
repository: "linkToHelmChartRepo"
maintainers:
- Abhinav Khanna
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"unist-util-visit": "^2.0.3",
"unist-util-visit-parents": "^3.1.1",
"xpath": "^0.0.32",
"yaml": "^2.2.2",
"yargs": "^17.0.0"
},
"engines": {
Expand Down
14 changes: 7 additions & 7 deletions src/updaters/helm/chart-yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import * as yaml from 'js-yaml';
import * as yaml from 'yaml';
import {logger as defaultLogger, Logger} from '../../util/logger';
import {DefaultUpdater} from '../default';

Expand All @@ -26,13 +26,13 @@ export class ChartYaml extends DefaultUpdater {
* @returns {string} The updated content
*/
updateContent(content: string, logger: Logger = defaultLogger): string {
const data = yaml.load(content, {json: true});
if (data === null || data === undefined) {
const chart = yaml.parseDocument(content);
if (chart === null || chart === undefined) {
return '';
}
const parsed = JSON.parse(JSON.stringify(data));
logger.info(`updating from ${parsed.version} to ${this.version}`);
parsed.version = this.version.toString();
return yaml.dump(parsed);
const oldVersion = chart.get('version');
logger.info(`updating from ${oldVersion} to ${this.version}`);
chart.set('version', this.version.toString());
return chart.toString();
}
}
1 change: 1 addition & 0 deletions test/updaters/fixtures/helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
name: helm-test-repo
version: 1.0.0
apiVersion: v2
# renovate: image=imageName
appVersion: 2.0.0
dependencies:
- name: another-repo
Expand Down

0 comments on commit 77de40e

Please sign in to comment.