Skip to content

Commit

Permalink
fix(manager/helm-values): Revert "feat(manager/helm-values): Add supp…
Browse files Browse the repository at this point in the history
…ort for bumpVersion" (renovatebot#26758)

Co-authored-by: Michael Kriese <[email protected]>
  • Loading branch information
2 people authored and zT-1337 committed Jan 24, 2024
1 parent ffa1493 commit 359dcec
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 256 deletions.
1 change: 0 additions & 1 deletion docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@ This is an advanced field, and it's recommend you seek a config review before ap
Currently, this config option only works with these managers:

- `helmv3`
- `helm-values`
- `npm`
- `nuget`
- `maven`
Expand Down
71 changes: 10 additions & 61 deletions lib/modules/manager/helm-values/extract.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { Fixtures } from '../../../../test/fixtures';
import { fs } from '../../../../test/util';
import { extractPackageFile } from '.';

jest.mock('../../../util/fs');

const helmDefaultChartInitValues = Fixtures.get(
'default_chart_init_values.yaml',
);
Expand All @@ -14,21 +11,18 @@ const helmMultiAndNestedImageValues = Fixtures.get(

describe('modules/manager/helm-values/extract', () => {
describe('extractPackageFile()', () => {
it('returns null for invalid yaml file content', async () => {
const result = await extractPackageFile('nothing here: [', 'some file');
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('', 'some file');
it('returns null for empty yaml file content', () => {
const result = extractPackageFile('');
expect(result).toBeNull();
});

it('extracts from values.yaml correctly with same structure as "helm create"', async () => {
const result = await extractPackageFile(
helmDefaultChartInitValues,
'some file',
);
it('extracts from values.yaml correctly with same structure as "helm create"', () => {
const result = extractPackageFile(helmDefaultChartInitValues);
expect(result).toMatchSnapshot({
deps: [
{
Expand All @@ -39,20 +33,17 @@ describe('modules/manager/helm-values/extract', () => {
});
});

it('extracts from complex values file correctly"', async () => {
const result = await extractPackageFile(
helmMultiAndNestedImageValues,
'some file',
);
it('extracts from complex values file correctly"', () => {
const result = extractPackageFile(helmMultiAndNestedImageValues);
expect(result).toMatchSnapshot();
expect(result?.deps).toHaveLength(5);
});

it('extract data from file with multiple documents', async () => {
it('extract data from file with multiple documents', () => {
const multiDocumentFile = Fixtures.get(
'single_file_with_multiple_documents.yaml',
);
const result = await extractPackageFile(multiDocumentFile, 'some file');
const result = extractPackageFile(multiDocumentFile);
expect(result).toMatchObject({
deps: [
{
Expand All @@ -70,47 +61,5 @@ describe('modules/manager/helm-values/extract', () => {
],
});
});

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).not.toBeNull();
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();
});
});
});
18 changes: 3 additions & 15 deletions lib/modules/manager/helm-values/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { getDep } from '../dockerfile/extract';
import type { PackageDependency, PackageFileContent } from '../types';
import type { HelmDockerImageDependency } from './types';
import {
getParsedSiblingChartYaml,
matchesHelmValuesDockerHeuristic,
matchesHelmValuesInlineImage,
} from './util';
Expand Down Expand Up @@ -58,10 +57,10 @@ function findDependencies(
return packageDependencies;
}

export async function extractPackageFile(
export function extractPackageFile(
content: string,
packageFile: string,
): Promise<PackageFileContent | null> {
packageFile?: string,
): PackageFileContent | null {
let parsedContent: Record<string, unknown>[] | HelmDockerImageDependency[];
try {
// a parser that allows extracting line numbers would be preferable, with
Expand All @@ -80,17 +79,6 @@ export async function extractPackageFile(
}

if (deps.length) {
// 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(packageFile);
const packageFileVersion = siblingChart?.version;
if (packageFileVersion) {
return {
deps,
packageFileVersion,
};
}
return { deps };
}
} catch (err) /* istanbul ignore next */ {
Expand Down
1 change: 0 additions & 1 deletion lib/modules/manager/helm-values/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Category } from '../../../constants';
import { DockerDatasource } from '../../datasource/docker';
export { extractPackageFile } from './extract';
export { bumpPackageVersion } from './update';

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

This file was deleted.

78 changes: 0 additions & 78 deletions lib/modules/manager/helm-values/update.spec.ts

This file was deleted.

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

This file was deleted.

43 changes: 0 additions & 43 deletions lib/modules/manager/helm-values/util.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { logger } from '../../../logger';
import { getSiblingFileName, readLocalFile } from '../../../util/fs';
import { hasKey } from '../../../util/object';
import { regEx } from '../../../util/regex';
import { type ChartDefinition, ChartDefinitionYaml } from './schema';
import type { HelmDockerImageDependency } from './types';

const parentKeyRe = regEx(/image$/i);
Expand Down Expand Up @@ -44,43 +41,3 @@ export function matchesHelmValuesInlineImage(
): data is string {
return !!(parentKeyRe.test(parentKey) && data && typeof data === 'string');
}

/**
* 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 | null> {
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<ChartDefinition | null> {
try {
const chartContents = await getSiblingChartYamlContent(fileName);
if (!chartContents) {
logger.debug({ fileName }, 'Failed to find helm Chart.yaml');
return null;
}
return ChartDefinitionYaml.parse(chartContents);
} catch (err) {
logger.debug({ fileName }, 'Failed to parse helm Chart.yaml');
return null;
}
}

0 comments on commit 359dcec

Please sign in to comment.