Skip to content

Commit

Permalink
fix: Revert "feat(helm-values): Support for bumpVersion" (#8926)
Browse files Browse the repository at this point in the history
This reverts commit 662a60a.
  • Loading branch information
rarkins authored Mar 1, 2021
1 parent e3ccc26 commit 57ac935
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 410 deletions.
2 changes: 1 addition & 1 deletion docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ This is an advance field and it's recommend you seek a config review before appl

## bumpVersion

Currently this setting supports `helmv3`, `helm-values`, `npm` and `sbt` only, so raise a feature request if you have a use for it with other package managers.
Currently this setting supports `helmv3`, `npm` and `sbt` only, so raise a feature request if you have a use for it with other package managers.
Its purpose is if you want Renovate to update the `version` field within your file's `package.json` any time it updates dependencies within.
Usually this is for automatic release purposes, so that you don't need to add another step after Renovate before you can release a new version.

Expand Down
10 changes: 1 addition & 9 deletions lib/manager/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,6 @@ export interface UpdateDependencyConfig<T = Record<string, any>> {

export interface BumpPackageVersionResult {
bumpedContent: string | null;
// describes files that was changed instead of or in addition to the packageFile
bumpedFiles?: BumpedPackageFile[];
}

export interface BumpedPackageFile {
fileName: string;
newContent: string;
}

export interface UpdateLockedConfig {
Expand All @@ -255,8 +248,7 @@ export interface ManagerApi {
bumpPackageVersion?(
content: string,
currentValue: string,
bumpVersion: ReleaseType | string,
packageFile?: string
bumpVersion: ReleaseType | string
): Result<BumpPackageVersionResult>;

extractAllPackageFiles?(
Expand Down
15 changes: 0 additions & 15 deletions lib/manager/helm-values/__snapshots__/update.spec.ts.snap

This file was deleted.

60 changes: 10 additions & 50 deletions lib/manager/helm-values/extract.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { readFileSync } from 'fs';
import { fs } from '../../../test/util';
import { extractPackageFile } from './extract';

const helmDefaultChartInitValues = readFileSync(
Expand All @@ -16,66 +15,27 @@ describe('lib/manager/helm-values/extract', () => {
describe('extractPackageFile()', () => {
beforeEach(() => {
jest.resetAllMocks();
fs.readLocalFile = jest.fn();
});
it('returns null for invalid yaml file content', async () => {
const result = await extractPackageFile('nothing here: [');
it('returns null for invalid yaml file content', () => {
const result = extractPackageFile('nothing here: [');
expect(result).toBeNull();
});
it('returns null for empty yaml file content', async () => {
const result = await extractPackageFile('');
it('returns null for empty yaml file content', () => {
const result = extractPackageFile('');
expect(result).toBeNull();
});
it('returns null for no file content', async () => {
const result = await extractPackageFile(null);
it('returns null for no file content', () => {
const result = extractPackageFile(null);
expect(result).toBeNull();
});
it('extracts from values.yaml correctly with same structure as "helm create"', async () => {
const result = await extractPackageFile(helmDefaultChartInitValues);
it('extracts from values.yaml correctly with same structure as "helm create"', () => {
const result = extractPackageFile(helmDefaultChartInitValues);
expect(result).toMatchSnapshot();
});
it('extracts from complex values file correctly"', async () => {
const result = await extractPackageFile(helmMultiAndNestedImageValues);
it('extracts from complex values file correctly"', () => {
const result = extractPackageFile(helmMultiAndNestedImageValues);
expect(result).toMatchSnapshot();
expect(result.deps).toHaveLength(4);
});
it('returns the package file version from the sibling Chart.yaml"', async () => {
fs.readLocalFile.mockResolvedValueOnce(`
apiVersion: v2
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: example
version: 0.1.0
`);
const result = await extractPackageFile(
helmMultiAndNestedImageValues,
'values.yaml'
);
expect(result.packageFileVersion).toBe('0.1.0');
});
it('does not fail if the sibling Chart.yaml is invalid', async () => {
fs.readLocalFile.mockResolvedValueOnce(`
invalidYaml: [
`);
const result = await extractPackageFile(
helmMultiAndNestedImageValues,
'values.yaml'
);
expect(result).not.toBeNull();
expect(result.packageFileVersion).toBeUndefined();
});
it('does not fail if the sibling Chart.yaml does not contain the required fields', async () => {
fs.readLocalFile.mockResolvedValueOnce(`
apiVersion: v2
name: test
version-is: missing
`);
const result = await extractPackageFile(
helmMultiAndNestedImageValues,
'values.yaml'
);
expect(result).not.toBeNull();
expect(result.packageFileVersion).toBeUndefined();
});
});
});
22 changes: 2 additions & 20 deletions lib/manager/helm-values/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { getDep } from '../dockerfile/extract';

import {
HelmDockerImageDependency,
getParsedSiblingChartYaml,
matchesHelmValuesDockerHeuristic,
} from './util';

Expand Down Expand Up @@ -54,10 +53,7 @@ function findDependencies(
return packageDependencies;
}

export async function extractPackageFile(
content: string,
fileName?: string
): Promise<PackageFile> {
export function extractPackageFile(content: string): PackageFile {
let parsedContent: Record<string, unknown> | HelmDockerImageDependency;
try {
// a parser that allows extracting line numbers would be preferable, with
Expand All @@ -72,21 +68,7 @@ export async function extractPackageFile(
const deps = findDependencies(parsedContent, []);
if (deps.length) {
logger.debug({ deps }, 'Found dependencies in helm-values');

// in Helm, the current package version is the version of the chart.
// This fetches this version by reading it from the Chart.yaml
// found in the same folder as the currently processed values file.
const siblingChart = await getParsedSiblingChartYaml(fileName);
const packageFileVersion = siblingChart?.version;
if (packageFileVersion) {
return {
deps,
packageFileVersion,
};
}
return {
deps,
};
return { deps };
}
} catch (err) /* istanbul ignore next */ {
logger.error({ err }, 'Error parsing helm-values parsed content');
Expand Down
1 change: 0 additions & 1 deletion lib/manager/helm-values/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export { extractPackageFile } from './extract';
export { bumpPackageVersion } from './update';

export const defaultConfig = {
commitMessageTopic: 'helm values {{depName}}',
Expand Down
85 changes: 0 additions & 85 deletions lib/manager/helm-values/update.spec.ts

This file was deleted.

51 changes: 0 additions & 51 deletions lib/manager/helm-values/update.ts

This file was deleted.

52 changes: 0 additions & 52 deletions lib/manager/helm-values/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import yaml from 'js-yaml';
import { logger } from '../../logger';
import { getSiblingFileName, readLocalFile } from '../../util/fs';
import { hasKey } from '../../util/object';

export type HelmDockerImageDependency = {
Expand Down Expand Up @@ -38,52 +35,3 @@ export function matchesHelmValuesDockerHeuristic(
hasKey('tag', data)
);
}

/**
* This function looks for a Chart.yaml in the same directory as @param fileName and
* returns its raw contents.
*
* @param fileName
*/
export async function getSiblingChartYamlContent(
fileName: string
): Promise<string> {
try {
const chartFileName = getSiblingFileName(fileName, 'Chart.yaml');
return await readLocalFile(chartFileName, 'utf8');
} catch (err) {
logger.debug({ fileName }, 'Failed to read helm Chart.yaml');
return null;
}
}

/**
* This function looks for a Chart.yaml in the same directory as @param fileName and
* if it looks like a valid Helm Chart.yaml, it is parsed and returned as an object.
*
* @param fileName
*/
export async function getParsedSiblingChartYaml(
fileName: string
): Promise<any> {
try {
const chartContents = await getSiblingChartYamlContent(fileName);
if (!chartContents) {
logger.debug({ fileName }, 'Failed to find helm Chart.yaml');
return null;
}
// TODO: fix me
const chart = yaml.safeLoad(chartContents, { json: true }) as any;
if (!(chart?.apiVersion && chart.name && chart.version)) {
logger.debug(
{ fileName },
'Failed to find required fields in Chart.yaml'
);
return null;
}
return chart;
} catch (err) {
logger.debug({ fileName }, 'Failed to parse helm Chart.yaml');
return null;
}
}
Loading

0 comments on commit 57ac935

Please sign in to comment.