Skip to content

Commit 77de40e

Browse files
authored
fix(helm): maintain any existing comments in Chart.yaml (#1968)
1 parent d1f891c commit 77de40e

4 files changed

Lines changed: 25 additions & 8 deletions

File tree

__snapshots__/chart-yaml.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
exports['ChartYaml updateContent updates version in Chart.yaml 1'] = `
2+
# Copyright 2021 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
216
name: helm-test-repo
317
version: 1.1.0
418
apiVersion: v2
19+
# renovate: image=imageName
520
appVersion: 2.0.0
621
dependencies:
722
- name: another-repo
823
version: 0.15.3
9-
repository: linkToHelmChartRepo
24+
repository: "linkToHelmChartRepo"
1025
maintainers:
1126
- Abhinav Khanna
1227

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"unist-util-visit": "^2.0.3",
101101
"unist-util-visit-parents": "^3.1.1",
102102
"xpath": "^0.0.32",
103+
"yaml": "^2.2.2",
103104
"yargs": "^17.0.0"
104105
},
105106
"engines": {

src/updaters/helm/chart-yaml.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

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

@@ -26,13 +26,13 @@ export class ChartYaml extends DefaultUpdater {
2626
* @returns {string} The updated content
2727
*/
2828
updateContent(content: string, logger: Logger = defaultLogger): string {
29-
const data = yaml.load(content, {json: true});
30-
if (data === null || data === undefined) {
29+
const chart = yaml.parseDocument(content);
30+
if (chart === null || chart === undefined) {
3131
return '';
3232
}
33-
const parsed = JSON.parse(JSON.stringify(data));
34-
logger.info(`updating from ${parsed.version} to ${this.version}`);
35-
parsed.version = this.version.toString();
36-
return yaml.dump(parsed);
33+
const oldVersion = chart.get('version');
34+
logger.info(`updating from ${oldVersion} to ${this.version}`);
35+
chart.set('version', this.version.toString());
36+
return chart.toString();
3737
}
3838
}

test/updaters/fixtures/helm/Chart.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
name: helm-test-repo
1616
version: 1.0.0
1717
apiVersion: v2
18+
# renovate: image=imageName
1819
appVersion: 2.0.0
1920
dependencies:
2021
- name: another-repo

0 commit comments

Comments
 (0)