From 0dbae8a23cfbdf29a750dc65463cf39c5e6bbe99 Mon Sep 17 00:00:00 2001 From: kvanzuijlen <8818390+kvanzuijlen@users.noreply.github.com> Date: Wed, 27 Dec 2023 23:19:17 +0100 Subject: [PATCH 01/13] feat(helm-values): Add support for bumpVersion Signed-off-by: kvanzuijlen <8818390+kvanzuijlen@users.noreply.github.com> --- lib/modules/manager/helm-values/extract.ts | 18 +++++- lib/modules/manager/helm-values/index.ts | 1 + lib/modules/manager/helm-values/update.ts | 56 +++++++++++++++++ lib/modules/manager/helm-values/util.ts | 51 ++++++++++++++++ lib/modules/manager/types.ts | 7 +++ .../repository/update/branch/get-updated.ts | 60 ++++++++++++++----- 6 files changed, 174 insertions(+), 19 deletions(-) create mode 100644 lib/modules/manager/helm-values/update.ts diff --git a/lib/modules/manager/helm-values/extract.ts b/lib/modules/manager/helm-values/extract.ts index 61437fdbb79571..7e707aab22327b 100644 --- a/lib/modules/manager/helm-values/extract.ts +++ b/lib/modules/manager/helm-values/extract.ts @@ -5,6 +5,7 @@ import { getDep } from '../dockerfile/extract'; import type { PackageDependency, PackageFileContent } from '../types'; import type { HelmDockerImageDependency } from './types'; import { + getParsedSiblingChartYaml, matchesHelmValuesDockerHeuristic, matchesHelmValuesInlineImage, } from './util'; @@ -57,10 +58,10 @@ function findDependencies( return packageDependencies; } -export function extractPackageFile( +export async function extractPackageFile( content: string, - packageFile?: string, -): PackageFileContent | null { + packageFile: string, +): Promise { let parsedContent: Record[] | HelmDockerImageDependency[]; try { // a parser that allows extracting line numbers would be preferable, with @@ -79,6 +80,17 @@ export 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 */ { diff --git a/lib/modules/manager/helm-values/index.ts b/lib/modules/manager/helm-values/index.ts index 6d96f591c1b390..61290829cab14b 100644 --- a/lib/modules/manager/helm-values/index.ts +++ b/lib/modules/manager/helm-values/index.ts @@ -1,6 +1,7 @@ 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}}', diff --git a/lib/modules/manager/helm-values/update.ts b/lib/modules/manager/helm-values/update.ts new file mode 100644 index 00000000000000..493abda86e10f0 --- /dev/null +++ b/lib/modules/manager/helm-values/update.ts @@ -0,0 +1,56 @@ +import { ReleaseType, inc } from 'semver'; +import { logger } from '../../../logger'; +import { getSiblingFileName } from '../../../util/fs'; +import type { BumpPackageVersionResult } from '../types'; +import { getSiblingChartYamlContent } from './util'; + +export async function bumpPackageVersion( + content: string, + currentValue: string, + bumpVersion: ReleaseType, + packageFile: string, +): Promise { + logger.debug( + { bumpVersion, currentValue }, + 'Checking if we should bump Chart.yaml version', + ); + const chartFileName = getSiblingFileName(packageFile, 'Chart.yaml'); + const chartYamlContent = await getSiblingChartYamlContent(packageFile); + try { + const newChartVersion = inc(currentValue, bumpVersion); + if (!newChartVersion) { + throw new Error('semver inc failed'); + } + if (chartYamlContent === null) { + throw new Error( + 'Cannot bump chart version because Chart.yaml could not be read.', + ); + } + logger.debug({ newChartVersion }); + const bumpedContent = chartYamlContent?.replace( + /^(version:\s*).*$/m, + `$1${newChartVersion}`, + ); + if (bumpedContent === chartYamlContent) { + logger.debug('Version was already bumped'); + } else { + logger.debug('Bumped Chart.yaml version'); + } + return { + bumpedContent: content, + bumpedFiles: [{ fileName: chartFileName, newContent: bumpedContent }], + }; + } catch (err) { + logger.warn( + { + chartYamlContent, + currentValue, + bumpVersion, + }, + 'Failed to bumpVersion', + ); + return { + bumpedContent: content, + }; + } +} diff --git a/lib/modules/manager/helm-values/util.ts b/lib/modules/manager/helm-values/util.ts index 34b6c2dabc86ab..c5c253b783288e 100644 --- a/lib/modules/manager/helm-values/util.ts +++ b/lib/modules/manager/helm-values/util.ts @@ -1,3 +1,6 @@ +import yaml from 'js-yaml'; +import { logger } from '../../../logger'; +import { getSiblingFileName, readLocalFile } from '../../../util/fs'; import { hasKey } from '../../../util/object'; import { regEx } from '../../../util/regex'; import type { HelmDockerImageDependency } from './types'; @@ -41,3 +44,51 @@ 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 { + 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 { + try { + const chartContents = await getSiblingChartYamlContent(fileName); + if (!chartContents) { + logger.debug({ fileName }, 'Failed to find helm Chart.yaml'); + return null; + } + const chart = yaml.load(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; + } +} diff --git a/lib/modules/manager/types.ts b/lib/modules/manager/types.ts index 8435b4e9b9d467..ee6cccebe25522 100644 --- a/lib/modules/manager/types.ts +++ b/lib/modules/manager/types.ts @@ -199,6 +199,12 @@ export interface UpdateDependencyConfig> { 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 { @@ -235,6 +241,7 @@ export interface ManagerApi extends ModuleApi { content: string, currentValue: string, bumpVersion: ReleaseType, + packageFile?: string, ): Result; detectGlobalConfig?(): Result; diff --git a/lib/workers/repository/update/branch/get-updated.ts b/lib/workers/repository/update/branch/get-updated.ts index 648f107c25b213..a4fb441be3e2d4 100644 --- a/lib/workers/repository/update/branch/get-updated.ts +++ b/lib/workers/repository/update/branch/get-updated.ts @@ -6,6 +6,7 @@ import { get } from '../../../../modules/manager'; import type { ArtifactError, PackageDependency, + BumpedPackageFile, } from '../../../../modules/manager/types'; import { getFile } from '../../../../util/git'; import type { FileAddition, FileChange } from '../../../../util/git/types'; @@ -20,6 +21,21 @@ export interface PackageFilesResult { updatedArtifacts: FileChange[]; } +async function getFileContent( + updatedFileContents: Record, + filePath: string, + config: BranchConfig, +): Promise { + let fileContent: string | null = updatedFileContents[filePath]; + if (!fileContent) { + fileContent = await getFile( + filePath, + config.reuseExistingBranch ? config.branchName : config.baseBranch, + ); + } + return fileContent; +} + export async function getUpdatedPackageFiles( config: BranchConfig, ): Promise { @@ -46,23 +62,19 @@ export async function getUpdatedPackageFiles( packageFileUpdatedDeps[packageFile] = packageFileUpdatedDeps[packageFile] || []; packageFileUpdatedDeps[packageFile].push({ ...upgrade }); - let packageFileContent: string | null = updatedFileContents[packageFile]; - if (!packageFileContent) { - packageFileContent = await getFile( - packageFile, - reuseExistingBranch ? config.branchName : config.baseBranch, - ); - } + const packageFileContent = await getFileContent( + updatedFileContents, + packageFile, + config, + ); let lockFileContent: string | null = null; const lockFile = upgrade.lockFile ?? upgrade.lockFiles?.[0] ?? ''; if (lockFile) { - lockFileContent = updatedFileContents[lockFile]; - if (!lockFileContent) { - lockFileContent = await getFile( - lockFile, - reuseExistingBranch ? config.branchName : config.baseBranch, - ); - } + lockFileContent = await getFileContent( + updatedFileContents, + lockFile, + config, + ); } // istanbul ignore if if ( @@ -174,17 +186,20 @@ export async function getUpdatedPackageFiles( ); firstUpdate = false; if (res) { + let bumpedPackageFiles: BumpedPackageFile[] = []; if ( bumpPackageVersion && upgrade.bumpVersion && upgrade.packageFileVersion ) { - const { bumpedContent } = await bumpPackageVersion( + const bumpResult = await bumpPackageVersion( res, upgrade.packageFileVersion, upgrade.bumpVersion, + packageFile, ); - res = bumpedContent; + res = bumpResult.bumpedContent; + bumpedPackageFiles = bumpResult.bumpedFiles ?? []; } if (res === packageFileContent) { logger.debug({ packageFile, depName }, 'No content changed'); @@ -192,6 +207,18 @@ export async function getUpdatedPackageFiles( logger.debug({ packageFile, depName }, 'Contents updated'); updatedFileContents[packageFile] = res!; delete nonUpdatedFileContents[packageFile]; + // indicates that the version was bumped in one or more files in + // addition to or instead of the packageFile + if (bumpedPackageFiles) { + for (const bumpedPackageFile of bumpedPackageFiles) { + logger.debug( + { bumpedPackageFile, depName }, + 'Updating bumpedPackageFile content', + ); + updatedFileContents[bumpedPackageFile.fileName] = + bumpedPackageFile.newContent; + } + } } continue; } else if (reuseExistingBranch) { @@ -217,6 +244,7 @@ export async function getUpdatedPackageFiles( newContent, upgrade.packageFileVersion, upgrade.bumpVersion, + packageFile, ); newContent = bumpedContent; } From 2a01fcea945d3c7f7b1d52b972aff4d5e70f9418 Mon Sep 17 00:00:00 2001 From: kvanzuijlen <8818390+kvanzuijlen@users.noreply.github.com> Date: Wed, 27 Dec 2023 23:47:34 +0100 Subject: [PATCH 02/13] chore: added tests Signed-off-by: kvanzuijlen <8818390+kvanzuijlen@users.noreply.github.com> --- docs/usage/configuration-options.md | 5 +- .../__snapshots__/update.spec.ts.snap | 29 ++++++ .../manager/helm-values/extract.spec.ts | 73 +++++++++++++-- .../manager/helm-values/update.spec.ts | 82 +++++++++++++++++ .../__snapshots__/get-updated.spec.ts.snap | 65 +++++++++++++ .../update/branch/get-updated.spec.ts | 91 +++++++++++++++---- .../repository/update/branch/get-updated.ts | 2 +- 7 files changed, 314 insertions(+), 33 deletions(-) create mode 100644 lib/modules/manager/helm-values/__snapshots__/update.spec.ts.snap create mode 100644 lib/modules/manager/helm-values/update.spec.ts diff --git a/docs/usage/configuration-options.md b/docs/usage/configuration-options.md index f93316f3c55efb..10b9d2aba47482 100644 --- a/docs/usage/configuration-options.md +++ b/docs/usage/configuration-options.md @@ -406,12 +406,11 @@ Instead, set the old `branchPrefix` value as `branchPrefixOld` to allow Renovate ## branchTopic This field is combined with `branchPrefix` and `additionalBranchPrefix` to form the full `branchName`. `branchName` uniqueness is important for dependency update grouping or non-grouping so be cautious about ever editing this field manually. -This is an advance field and it's recommend you seek a config review before applying it. +This is an advanced field, and it's recommend you seek a config review before applying it. ## bumpVersion -Currently this setting supports `helmv3`, `npm`, `nuget`, `maven`, `pep621` 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`, `nuget`, `maven`, `pep621`, `poetry` and `sbt` only, so raise a feature request if you have a use for it with other package managers. +Currently, this setting supports `helmv3`, `helm-values`, `npm`, `nuget`, `maven`, `pep621`, `poetry` 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 package file 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. diff --git a/lib/modules/manager/helm-values/__snapshots__/update.spec.ts.snap b/lib/modules/manager/helm-values/__snapshots__/update.spec.ts.snap new file mode 100644 index 00000000000000..5dbbba6cd29b03 --- /dev/null +++ b/lib/modules/manager/helm-values/__snapshots__/update.spec.ts.snap @@ -0,0 +1,29 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`lib/manager/helm-values/update .bumpPackageVersion() increments 1`] = ` +"apiVersion: v2 +name: test +version: 0.0.3 +" +`; + +exports[`lib/manager/helm-values/update .bumpPackageVersion() updates 1`] = ` +"apiVersion: v2 +name: test +version: 0.1.0 +" +`; + +exports[`modules/manager/helm-values/update .bumpPackageVersion() increments 1`] = ` +"apiVersion: v2 +name: test +version: 0.0.3 +" +`; + +exports[`modules/manager/helm-values/update .bumpPackageVersion() updates 1`] = ` +"apiVersion: v2 +name: test +version: 0.1.0 +" +`; diff --git a/lib/modules/manager/helm-values/extract.spec.ts b/lib/modules/manager/helm-values/extract.spec.ts index d8eb805db86f7a..8a19153924c94b 100644 --- a/lib/modules/manager/helm-values/extract.spec.ts +++ b/lib/modules/manager/helm-values/extract.spec.ts @@ -1,4 +1,5 @@ import { Fixtures } from '../../../../test/fixtures'; +import { fs } from '../../../../test/util'; import { extractPackageFile } from '.'; const helmDefaultChartInitValues = Fixtures.get( @@ -11,18 +12,25 @@ const helmMultiAndNestedImageValues = Fixtures.get( describe('modules/manager/helm-values/extract', () => { describe('extractPackageFile()', () => { - it('returns null for invalid yaml file content', () => { - const result = extractPackageFile('nothing here: ['); + beforeEach(() => { + fs.readLocalFile = jest.fn(); + }); + + it('returns null for invalid yaml file content', async () => { + const result = await extractPackageFile('nothing here: [', 'some file'); expect(result).toBeNull(); }); - it('returns null for empty yaml file content', () => { - const result = extractPackageFile(''); + it('returns null for empty yaml file content', async () => { + const result = await extractPackageFile('', 'some file'); expect(result).toBeNull(); }); - it('extracts from values.yaml correctly with same structure as "helm create"', () => { - const result = extractPackageFile(helmDefaultChartInitValues); + it('extracts from values.yaml correctly with same structure as "helm create"', async () => { + const result = await extractPackageFile( + helmDefaultChartInitValues, + 'some file', + ); expect(result).toMatchSnapshot({ deps: [ { @@ -33,17 +41,20 @@ describe('modules/manager/helm-values/extract', () => { }); }); - it('extracts from complex values file correctly"', () => { - const result = extractPackageFile(helmMultiAndNestedImageValues); + it('extracts from complex values file correctly"', async () => { + const result = await extractPackageFile( + helmMultiAndNestedImageValues, + 'some file', + ); expect(result).toMatchSnapshot(); expect(result?.deps).toHaveLength(5); }); - it('extract data from file with multiple documents', () => { + it('extract data from file with multiple documents', async () => { const multiDocumentFile = Fixtures.get( 'single_file_with_multiple_documents.yaml', ); - const result = extractPackageFile(multiDocumentFile); + const result = await extractPackageFile(multiDocumentFile, 'some file'); expect(result).toMatchObject({ deps: [ { @@ -61,5 +72,47 @@ 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(); + }); }); }); diff --git a/lib/modules/manager/helm-values/update.spec.ts b/lib/modules/manager/helm-values/update.spec.ts new file mode 100644 index 00000000000000..b2418c825ec7a1 --- /dev/null +++ b/lib/modules/manager/helm-values/update.spec.ts @@ -0,0 +1,82 @@ +import yaml from 'js-yaml'; +import { fs } from '../../../../test/util'; +import * as helmValuesUpdater from './update'; + +describe('modules/manager/helm-values/update', () => { + describe('.bumpPackageVersion()', () => { + const chartContent = yaml.dump({ + apiVersion: 'v2', + name: 'test', + version: '0.0.2', + }); + const helmValuesContent = yaml.dump({ + image: { + registry: 'docker.io', + repository: 'docker/whalesay', + tag: '1.0.0', + }, + }); + + beforeEach(() => { + jest.resetAllMocks(); + fs.readLocalFile = jest.fn(); + fs.readLocalFile.mockResolvedValueOnce(chartContent); + }); + + it('increments', async () => { + const { bumpedContent, bumpedFiles } = + await helmValuesUpdater.bumpPackageVersion( + helmValuesContent, + '0.0.2', + 'patch', + 'values.yaml', + ); + expect(bumpedContent).toEqual(helmValuesContent); + expect(bumpedFiles).toHaveLength(1); + const bumpedFile = bumpedFiles![0]; + expect(bumpedFile.fileName).toBe('Chart.yaml'); + expect(bumpedFile.newContent).toMatchSnapshot(); + }); + + it('no ops', async () => { + const { bumpedContent, bumpedFiles } = + await helmValuesUpdater.bumpPackageVersion( + helmValuesContent, + '0.0.1', + 'patch', + 'values.yaml', + ); + expect(bumpedContent).toEqual(helmValuesContent); + expect(bumpedFiles).toHaveLength(1); + const bumpedFile = bumpedFiles![0]; + expect(bumpedFile.newContent).toEqual(chartContent); + }); + + it('updates', async () => { + const { bumpedContent, bumpedFiles } = + await helmValuesUpdater.bumpPackageVersion( + helmValuesContent, + '0.0.1', + 'minor', + 'values.yaml', + ); + expect(bumpedContent).toEqual(helmValuesContent); + expect(bumpedFiles).toHaveLength(1); + const bumpedFile = bumpedFiles![0]; + expect(bumpedFile.fileName).toBe('Chart.yaml'); + expect(bumpedFile.newContent).toMatchSnapshot(); + }); + + it('returns content if bumping errors', async () => { + const { bumpedContent, bumpedFiles } = + await helmValuesUpdater.bumpPackageVersion( + helmValuesContent, + '0.0.2', + true as any, + 'values.yaml', + ); + expect(bumpedContent).toEqual(helmValuesContent); + expect(bumpedFiles).toBeUndefined(); + }); + }); +}); diff --git a/lib/workers/repository/update/branch/__snapshots__/get-updated.spec.ts.snap b/lib/workers/repository/update/branch/__snapshots__/get-updated.spec.ts.snap index 55675aa4f8d44a..35dad3be3ef892 100644 --- a/lib/workers/repository/update/branch/__snapshots__/get-updated.spec.ts.snap +++ b/lib/workers/repository/update/branch/__snapshots__/get-updated.spec.ts.snap @@ -1,5 +1,37 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`workers/branch/get-updated getUpdatedPackageFiles() in autoReplace managers bumps versions in all files if multiple files were bumped 1`] = ` +Object { + "artifactErrors": Array [], + "reuseExistingBranch": undefined, + "updatedArtifacts": Array [], + "updatedPackageFiles": Array [ + Object { + "contents": "version: 0.0.2", + "name": "/test/Chart.yaml", + }, + Object { + "contents": "# Version 0.0.2", + "name": "/test/README.md", + }, + ], +} +`; + +exports[`workers/branch/get-updated getUpdatedPackageFiles() in autoReplace managers bumps versions with a bumpPackageFile different from the packageFile 1`] = ` +Object { + "artifactErrors": Array [], + "reuseExistingBranch": undefined, + "updatedArtifacts": Array [], + "updatedPackageFiles": Array [ + Object { + "contents": "version: 0.0.2", + "name": "/test/Chart.yaml", + }, + ], +} +`; + exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() bumps versions in autoReplace managers 1`] = ` { "artifactErrors": [], @@ -190,6 +222,39 @@ exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() h } `; +exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() in autoReplace managers bumps versions 1`] = ` +{ + "artifactErrors": [], + "reuseExistingBranch": undefined, + "updatedArtifacts": [], + "updatedPackageFiles": [ + { + "contents": "version: 0.0.2", + "path": "Chart.yaml", + "type": "addition", + }, + ], +} +`; + +exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() in autoReplace managers bumps versions in all files if multiple files were bumped 1`] = ` +{ + "artifactErrors": [], + "reuseExistingBranch": undefined, + "updatedArtifacts": [], + "updatedPackageFiles": [], +} +`; + +exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() in autoReplace managers bumps versions with a bumpPackageFile different from the packageFile 1`] = ` +{ + "artifactErrors": [], + "reuseExistingBranch": undefined, + "updatedArtifacts": [], + "updatedPackageFiles": [], +} +`; + exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() update artifacts on update-lockfile strategy 1`] = ` { "artifactErrors": [], diff --git a/lib/workers/repository/update/branch/get-updated.spec.ts b/lib/workers/repository/update/branch/get-updated.spec.ts index 4a6590790e6734..5bb517ac0ad80c 100644 --- a/lib/workers/repository/update/branch/get-updated.spec.ts +++ b/lib/workers/repository/update/branch/get-updated.spec.ts @@ -4,6 +4,7 @@ import * as _batectWrapper from '../../../../modules/manager/batect-wrapper'; import * as _bundler from '../../../../modules/manager/bundler'; import * as _composer from '../../../../modules/manager/composer'; import * as _gitSubmodules from '../../../../modules/manager/git-submodules'; +import * as _helmValues from '../../../../modules/manager/helm-values'; import * as _helmv3 from '../../../../modules/manager/helmv3'; import * as _npm from '../../../../modules/manager/npm'; import type { BranchConfig, BranchUpgradeConfig } from '../../../types'; @@ -13,6 +14,7 @@ import { getUpdatedPackageFiles } from './get-updated'; const bundler = mocked(_bundler); const composer = mocked(_composer); const gitSubmodules = mocked(_gitSubmodules); +const helmValues = mocked(_helmValues); const helmv3 = mocked(_helmv3); const npm = mocked(_npm); const batectWrapper = mocked(_batectWrapper); @@ -20,6 +22,7 @@ const autoReplace = mocked(_autoReplace); jest.mock('../../../../modules/manager/bundler'); jest.mock('../../../../modules/manager/composer'); +jest.mock('../../../../modules/manager/helm-values'); jest.mock('../../../../modules/manager/helmv3'); jest.mock('../../../../modules/manager/npm'); jest.mock('../../../../modules/manager/git-submodules'); @@ -492,27 +495,77 @@ describe('workers/repository/update/branch/get-updated', () => { }); }); - it('bumps versions in autoReplace managers', async () => { - config.upgrades.push({ - packageFile: 'Chart.yaml', - branchName: '', - bumpVersion: 'patch', - manager: 'helmv3', - packageFileVersion: '0.0.1', + describe('in autoReplace managers', () => { + it('bumps versions', async () => { + config.upgrades.push({ + packageFile: 'Chart.yaml', + branchName: '', + bumpVersion: 'patch', + manager: 'helmv3', + packageFileVersion: '0.0.1', + }); + autoReplace.doAutoReplace.mockResolvedValueOnce('version: 0.0.1'); + helmv3.bumpPackageVersion.mockReturnValue({ + bumpedContent: 'version: 0.0.2', + }); + const res = await getUpdatedPackageFiles(config); + expect(res).toMatchSnapshot({ + updatedPackageFiles: [ + { + type: 'addition', + path: 'Chart.yaml', + contents: 'version: 0.0.2', + }, + ], + }); }); - autoReplace.doAutoReplace.mockResolvedValueOnce('version: 0.0.1'); - helmv3.bumpPackageVersion.mockReturnValue({ - bumpedContent: 'version: 0.0.2', + + it('bumps versions with a bumpPackageFile different from the packageFile', async () => { + config.upgrades.push({ + packageFile: 'values.yaml', + branchName: '', + bumpVersion: 'patch', + manager: 'helm-values', + packageFileVersion: '0.0.1', + }); + autoReplace.doAutoReplace.mockResolvedValueOnce('existing content'); + helmValues.bumpPackageVersion.mockResolvedValue({ + bumpedContent: 'existing content', + bumpedFiles: [ + { + fileName: '/test/Chart.yaml', + newContent: 'version: 0.0.2', + }, + ], + }); + const res = await getUpdatedPackageFiles(config); + expect(res).toMatchSnapshot(); }); - const res = await getUpdatedPackageFiles(config); - expect(res).toMatchSnapshot({ - updatedPackageFiles: [ - { - type: 'addition', - path: 'Chart.yaml', - contents: 'version: 0.0.2', - }, - ], + + it('bumps versions in all files if multiple files were bumped', async () => { + config.upgrades.push({ + packageFile: 'values.yaml', + branchName: '', + bumpVersion: 'patch', + manager: 'helm-values', + packageFileVersion: '0.0.1', + }); + autoReplace.doAutoReplace.mockResolvedValueOnce('existing content'); + helmValues.bumpPackageVersion.mockResolvedValue({ + bumpedContent: 'existing content', + bumpedFiles: [ + { + fileName: '/test/Chart.yaml', + newContent: 'version: 0.0.2', + }, + { + fileName: '/test/README.md', + newContent: '# Version 0.0.2', + }, + ], + }); + const res = await getUpdatedPackageFiles(config); + expect(res).toMatchSnapshot(); }); }); diff --git a/lib/workers/repository/update/branch/get-updated.ts b/lib/workers/repository/update/branch/get-updated.ts index a4fb441be3e2d4..4c974be418c592 100644 --- a/lib/workers/repository/update/branch/get-updated.ts +++ b/lib/workers/repository/update/branch/get-updated.ts @@ -5,8 +5,8 @@ import { logger } from '../../../../logger'; import { get } from '../../../../modules/manager'; import type { ArtifactError, - PackageDependency, BumpedPackageFile, + PackageDependency, } from '../../../../modules/manager/types'; import { getFile } from '../../../../util/git'; import type { FileAddition, FileChange } from '../../../../util/git/types'; From 6d7875d49266680872b6cf994e3e6475c338b98c Mon Sep 17 00:00:00 2001 From: kvanzuijlen <8818390+kvanzuijlen@users.noreply.github.com> Date: Wed, 27 Dec 2023 23:56:33 +0100 Subject: [PATCH 03/13] fix: fixed spec paths Signed-off-by: kvanzuijlen <8818390+kvanzuijlen@users.noreply.github.com> --- .../manager/helm-values/__snapshots__/update.spec.ts.snap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/modules/manager/helm-values/__snapshots__/update.spec.ts.snap b/lib/modules/manager/helm-values/__snapshots__/update.spec.ts.snap index 5dbbba6cd29b03..68cf16531747c6 100644 --- a/lib/modules/manager/helm-values/__snapshots__/update.spec.ts.snap +++ b/lib/modules/manager/helm-values/__snapshots__/update.spec.ts.snap @@ -1,13 +1,13 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`lib/manager/helm-values/update .bumpPackageVersion() increments 1`] = ` +exports[`modules/manager/helm-values/update .bumpPackageVersion() increments 1`] = ` "apiVersion: v2 name: test version: 0.0.3 " `; -exports[`lib/manager/helm-values/update .bumpPackageVersion() updates 1`] = ` +exports[`modules/manager/helm-values/update .bumpPackageVersion() updates 1`] = ` "apiVersion: v2 name: test version: 0.1.0 From 58ab838fa440721b1cdcae514928c4b475e1d58a Mon Sep 17 00:00:00 2001 From: kvanzuijlen <8818390+kvanzuijlen@users.noreply.github.com> Date: Thu, 28 Dec 2023 00:16:47 +0100 Subject: [PATCH 04/13] fix: removed obsolete specs Signed-off-by: kvanzuijlen <8818390+kvanzuijlen@users.noreply.github.com> --- .../__snapshots__/get-updated.spec.ts.snap | 47 ------------------- 1 file changed, 47 deletions(-) diff --git a/lib/workers/repository/update/branch/__snapshots__/get-updated.spec.ts.snap b/lib/workers/repository/update/branch/__snapshots__/get-updated.spec.ts.snap index 35dad3be3ef892..9a2914149f081f 100644 --- a/lib/workers/repository/update/branch/__snapshots__/get-updated.spec.ts.snap +++ b/lib/workers/repository/update/branch/__snapshots__/get-updated.spec.ts.snap @@ -1,52 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`workers/branch/get-updated getUpdatedPackageFiles() in autoReplace managers bumps versions in all files if multiple files were bumped 1`] = ` -Object { - "artifactErrors": Array [], - "reuseExistingBranch": undefined, - "updatedArtifacts": Array [], - "updatedPackageFiles": Array [ - Object { - "contents": "version: 0.0.2", - "name": "/test/Chart.yaml", - }, - Object { - "contents": "# Version 0.0.2", - "name": "/test/README.md", - }, - ], -} -`; - -exports[`workers/branch/get-updated getUpdatedPackageFiles() in autoReplace managers bumps versions with a bumpPackageFile different from the packageFile 1`] = ` -Object { - "artifactErrors": Array [], - "reuseExistingBranch": undefined, - "updatedArtifacts": Array [], - "updatedPackageFiles": Array [ - Object { - "contents": "version: 0.0.2", - "name": "/test/Chart.yaml", - }, - ], -} -`; - -exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() bumps versions in autoReplace managers 1`] = ` -{ - "artifactErrors": [], - "reuseExistingBranch": undefined, - "updatedArtifacts": [], - "updatedPackageFiles": [ - { - "contents": "version: 0.0.2", - "path": "Chart.yaml", - "type": "addition", - }, - ], -} -`; - exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() bumps versions in updateDependency managers 1`] = ` { "artifactErrors": [], From 88700f163fa1b9d340c9ff92fdf0bed84ccef60d Mon Sep 17 00:00:00 2001 From: kvanzuijlen <8818390+kvanzuijlen@users.noreply.github.com> Date: Thu, 28 Dec 2023 01:27:59 +0100 Subject: [PATCH 05/13] fix: Fixed tests Signed-off-by: kvanzuijlen <8818390+kvanzuijlen@users.noreply.github.com> --- .../manager/helm-values/update.spec.ts | 15 ++++++++ .../__snapshots__/get-updated.spec.ts.snap | 38 ++++++++++++++++++- .../update/branch/get-updated.spec.ts | 35 ++++++++++------- 3 files changed, 74 insertions(+), 14 deletions(-) diff --git a/lib/modules/manager/helm-values/update.spec.ts b/lib/modules/manager/helm-values/update.spec.ts index b2418c825ec7a1..205d9e6c7c8e53 100644 --- a/lib/modules/manager/helm-values/update.spec.ts +++ b/lib/modules/manager/helm-values/update.spec.ts @@ -78,5 +78,20 @@ describe('modules/manager/helm-values/update', () => { expect(bumpedContent).toEqual(helmValuesContent); expect(bumpedFiles).toBeUndefined(); }); + + it('returns content if retrieving Chart.yaml fails', async () => { + jest.resetAllMocks(); + fs.readLocalFile = jest.fn(); + fs.readLocalFile.mockRejectedValueOnce(null); + const { bumpedContent, bumpedFiles } = + await helmValuesUpdater.bumpPackageVersion( + helmValuesContent, + '0.0.2', + 'minor', + 'values.yaml', + ); + expect(bumpedContent).toEqual(helmValuesContent); + expect(bumpedFiles).toBeUndefined(); + }); }); }); diff --git a/lib/workers/repository/update/branch/__snapshots__/get-updated.spec.ts.snap b/lib/workers/repository/update/branch/__snapshots__/get-updated.spec.ts.snap index 9a2914149f081f..f13f9b6fa06eda 100644 --- a/lib/workers/repository/update/branch/__snapshots__/get-updated.spec.ts.snap +++ b/lib/workers/repository/update/branch/__snapshots__/get-updated.spec.ts.snap @@ -195,11 +195,47 @@ exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() i "artifactErrors": [], "reuseExistingBranch": undefined, "updatedArtifacts": [], - "updatedPackageFiles": [], + "updatedPackageFiles": [ + { + "contents": "new content", + "path": "values.yaml", + "type": "addition", + }, + { + "contents": "version: 0.0.2", + "path": "/test/Chart.yaml", + "type": "addition", + }, + { + "contents": "# Version 0.0.2", + "path": "/test/README.md", + "type": "addition", + }, + ], } `; exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() in autoReplace managers bumps versions with a bumpPackageFile different from the packageFile 1`] = ` +{ + "artifactErrors": [], + "reuseExistingBranch": undefined, + "updatedArtifacts": [], + "updatedPackageFiles": [ + { + "contents": "new content", + "path": "values.yaml", + "type": "addition", + }, + { + "contents": "version: 0.0.2", + "path": "/test/Chart.yaml", + "type": "addition", + }, + ], +} +`; + +exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() in autoReplace managers doesn't bump versions if content wasn't changed 1`] = ` { "artifactErrors": [], "reuseExistingBranch": undefined, diff --git a/lib/workers/repository/update/branch/get-updated.spec.ts b/lib/workers/repository/update/branch/get-updated.spec.ts index 5bb517ac0ad80c..2a4cf0342d0d9a 100644 --- a/lib/workers/repository/update/branch/get-updated.spec.ts +++ b/lib/workers/repository/update/branch/get-updated.spec.ts @@ -509,15 +509,7 @@ describe('workers/repository/update/branch/get-updated', () => { bumpedContent: 'version: 0.0.2', }); const res = await getUpdatedPackageFiles(config); - expect(res).toMatchSnapshot({ - updatedPackageFiles: [ - { - type: 'addition', - path: 'Chart.yaml', - contents: 'version: 0.0.2', - }, - ], - }); + expect(res).toMatchSnapshot(); }); it('bumps versions with a bumpPackageFile different from the packageFile', async () => { @@ -528,9 +520,9 @@ describe('workers/repository/update/branch/get-updated', () => { manager: 'helm-values', packageFileVersion: '0.0.1', }); - autoReplace.doAutoReplace.mockResolvedValueOnce('existing content'); + autoReplace.doAutoReplace.mockResolvedValueOnce('new content'); helmValues.bumpPackageVersion.mockResolvedValue({ - bumpedContent: 'existing content', + bumpedContent: 'new content', bumpedFiles: [ { fileName: '/test/Chart.yaml', @@ -550,9 +542,9 @@ describe('workers/repository/update/branch/get-updated', () => { manager: 'helm-values', packageFileVersion: '0.0.1', }); - autoReplace.doAutoReplace.mockResolvedValueOnce('existing content'); + autoReplace.doAutoReplace.mockResolvedValueOnce('new content'); helmValues.bumpPackageVersion.mockResolvedValue({ - bumpedContent: 'existing content', + bumpedContent: 'new content', bumpedFiles: [ { fileName: '/test/Chart.yaml', @@ -567,6 +559,23 @@ describe('workers/repository/update/branch/get-updated', () => { const res = await getUpdatedPackageFiles(config); expect(res).toMatchSnapshot(); }); + + it("doesn't bump versions if content wasn't changed", async () => { + config.upgrades.push({ + packageFile: 'values.yaml', + branchName: '', + bumpVersion: 'patch', + manager: 'helm-values', + packageFileVersion: '0.0.1', + }); + autoReplace.doAutoReplace.mockResolvedValueOnce('existing content'); + helmValues.bumpPackageVersion.mockResolvedValue({ + bumpedContent: 'existing content', + bumpedFiles: [], + }); + const res = await getUpdatedPackageFiles(config); + expect(res).toMatchSnapshot(); + }); }); it('handles replacement', async () => { From 0e8eedbb3f91da6fc4a0f1a277c44bc2f18b211b Mon Sep 17 00:00:00 2001 From: kvanzuijlen <8818390+kvanzuijlen@users.noreply.github.com> Date: Thu, 28 Dec 2023 15:54:40 +0100 Subject: [PATCH 06/13] chore: Improved tests + use yaml utils Signed-off-by: kvanzuijlen <8818390+kvanzuijlen@users.noreply.github.com> --- .../__snapshots__/update.spec.ts.snap | 29 ------------------- .../manager/helm-values/extract.spec.ts | 6 ++-- lib/modules/manager/helm-values/types.ts | 6 ++++ .../manager/helm-values/update.spec.ts | 21 +++++++++----- lib/modules/manager/helm-values/util.ts | 8 ++--- 5 files changed, 25 insertions(+), 45 deletions(-) delete mode 100644 lib/modules/manager/helm-values/__snapshots__/update.spec.ts.snap diff --git a/lib/modules/manager/helm-values/__snapshots__/update.spec.ts.snap b/lib/modules/manager/helm-values/__snapshots__/update.spec.ts.snap deleted file mode 100644 index 68cf16531747c6..00000000000000 --- a/lib/modules/manager/helm-values/__snapshots__/update.spec.ts.snap +++ /dev/null @@ -1,29 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`modules/manager/helm-values/update .bumpPackageVersion() increments 1`] = ` -"apiVersion: v2 -name: test -version: 0.0.3 -" -`; - -exports[`modules/manager/helm-values/update .bumpPackageVersion() updates 1`] = ` -"apiVersion: v2 -name: test -version: 0.1.0 -" -`; - -exports[`modules/manager/helm-values/update .bumpPackageVersion() increments 1`] = ` -"apiVersion: v2 -name: test -version: 0.0.3 -" -`; - -exports[`modules/manager/helm-values/update .bumpPackageVersion() updates 1`] = ` -"apiVersion: v2 -name: test -version: 0.1.0 -" -`; diff --git a/lib/modules/manager/helm-values/extract.spec.ts b/lib/modules/manager/helm-values/extract.spec.ts index 8a19153924c94b..f9397c655de745 100644 --- a/lib/modules/manager/helm-values/extract.spec.ts +++ b/lib/modules/manager/helm-values/extract.spec.ts @@ -2,6 +2,8 @@ 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', ); @@ -12,10 +14,6 @@ const helmMultiAndNestedImageValues = Fixtures.get( describe('modules/manager/helm-values/extract', () => { describe('extractPackageFile()', () => { - beforeEach(() => { - fs.readLocalFile = jest.fn(); - }); - it('returns null for invalid yaml file content', async () => { const result = await extractPackageFile('nothing here: [', 'some file'); expect(result).toBeNull(); diff --git a/lib/modules/manager/helm-values/types.ts b/lib/modules/manager/helm-values/types.ts index 50dbe42b439ccd..9f73fb382b22b4 100644 --- a/lib/modules/manager/helm-values/types.ts +++ b/lib/modules/manager/helm-values/types.ts @@ -18,3 +18,9 @@ export interface HelmDockerImageDependencyVersion export type HelmDockerImageDependency = | HelmDockerImageDependencyTag | HelmDockerImageDependencyVersion; + +export interface ChartDefinition { + apiVersion: string; + name: string; + version: string; +} diff --git a/lib/modules/manager/helm-values/update.spec.ts b/lib/modules/manager/helm-values/update.spec.ts index 205d9e6c7c8e53..9601627974bd20 100644 --- a/lib/modules/manager/helm-values/update.spec.ts +++ b/lib/modules/manager/helm-values/update.spec.ts @@ -2,6 +2,8 @@ import yaml from 'js-yaml'; import { fs } from '../../../../test/util'; import * as helmValuesUpdater from './update'; +jest.mock('../../../util/fs'); + describe('modules/manager/helm-values/update', () => { describe('.bumpPackageVersion()', () => { const chartContent = yaml.dump({ @@ -19,8 +21,8 @@ describe('modules/manager/helm-values/update', () => { beforeEach(() => { jest.resetAllMocks(); - fs.readLocalFile = jest.fn(); fs.readLocalFile.mockResolvedValueOnce(chartContent); + fs.getSiblingFileName.mockReturnValueOnce('test/Chart.yaml'); }); it('increments', async () => { @@ -29,13 +31,15 @@ describe('modules/manager/helm-values/update', () => { helmValuesContent, '0.0.2', 'patch', - 'values.yaml', + 'test/values.yaml', ); expect(bumpedContent).toEqual(helmValuesContent); expect(bumpedFiles).toHaveLength(1); const bumpedFile = bumpedFiles![0]; - expect(bumpedFile.fileName).toBe('Chart.yaml'); - expect(bumpedFile.newContent).toMatchSnapshot(); + expect(bumpedFile.fileName).toBe('test/Chart.yaml'); + expect(bumpedFile.newContent).toBe( + 'apiVersion: v2\nname: test\nversion: 0.0.3\n', + ); }); it('no ops', async () => { @@ -58,13 +62,15 @@ describe('modules/manager/helm-values/update', () => { helmValuesContent, '0.0.1', 'minor', - 'values.yaml', + 'test/values.yaml', ); expect(bumpedContent).toEqual(helmValuesContent); expect(bumpedFiles).toHaveLength(1); const bumpedFile = bumpedFiles![0]; - expect(bumpedFile.fileName).toBe('Chart.yaml'); - expect(bumpedFile.newContent).toMatchSnapshot(); + expect(bumpedFile.fileName).toBe('test/Chart.yaml'); + expect(bumpedFile.newContent).toBe( + 'apiVersion: v2\nname: test\nversion: 0.1.0\n', + ); }); it('returns content if bumping errors', async () => { @@ -81,7 +87,6 @@ describe('modules/manager/helm-values/update', () => { it('returns content if retrieving Chart.yaml fails', async () => { jest.resetAllMocks(); - fs.readLocalFile = jest.fn(); fs.readLocalFile.mockRejectedValueOnce(null); const { bumpedContent, bumpedFiles } = await helmValuesUpdater.bumpPackageVersion( diff --git a/lib/modules/manager/helm-values/util.ts b/lib/modules/manager/helm-values/util.ts index c5c253b783288e..1f567fba9db374 100644 --- a/lib/modules/manager/helm-values/util.ts +++ b/lib/modules/manager/helm-values/util.ts @@ -1,9 +1,9 @@ -import yaml from 'js-yaml'; import { logger } from '../../../logger'; import { getSiblingFileName, readLocalFile } from '../../../util/fs'; import { hasKey } from '../../../util/object'; import { regEx } from '../../../util/regex'; -import type { HelmDockerImageDependency } from './types'; +import { parseSingleYaml } from '../../../util/yaml'; +import type { ChartDefinition, HelmDockerImageDependency } from './types'; const parentKeyRe = regEx(/image$/i); @@ -71,14 +71,14 @@ export async function getSiblingChartYamlContent( */ export async function getParsedSiblingChartYaml( fileName: string, -): Promise { +): Promise { try { const chartContents = await getSiblingChartYamlContent(fileName); if (!chartContents) { logger.debug({ fileName }, 'Failed to find helm Chart.yaml'); return null; } - const chart = yaml.load(chartContents, { json: true }) as any; + const chart = parseSingleYaml(chartContents) as ChartDefinition; if (!(chart?.apiVersion && chart.name && chart.version)) { logger.debug( { fileName }, From c3c95ca0efb63d04c06d28003553d01c5e1c04ac Mon Sep 17 00:00:00 2001 From: kvanzuijlen <8818390+kvanzuijlen@users.noreply.github.com> Date: Mon, 1 Jan 2024 23:15:29 +0100 Subject: [PATCH 07/13] chore: Cleanup and code improvements Signed-off-by: kvanzuijlen <8818390+kvanzuijlen@users.noreply.github.com> --- lib/modules/manager/helm-values/types.ts | 21 +++- .../manager/helm-values/update.spec.ts | 83 ++++++--------- lib/modules/manager/helm-values/update.ts | 42 +++----- lib/modules/manager/helm-values/util.ts | 17 ++- lib/modules/manager/types.ts | 6 -- .../__snapshots__/get-updated.spec.ts.snap | 84 +++------------ .../update/branch/get-updated.spec.ts | 100 ++++-------------- .../repository/update/branch/get-updated.ts | 19 +--- 8 files changed, 103 insertions(+), 269 deletions(-) diff --git a/lib/modules/manager/helm-values/types.ts b/lib/modules/manager/helm-values/types.ts index 9f73fb382b22b4..845e2f3465ccf4 100644 --- a/lib/modules/manager/helm-values/types.ts +++ b/lib/modules/manager/helm-values/types.ts @@ -1,3 +1,6 @@ +import { z } from 'zod'; +import { Yaml } from '../../../util/schema-utils'; + export interface HelmDockerImageDependencyBasic { registry?: string; repository: string; @@ -19,8 +22,16 @@ export type HelmDockerImageDependency = | HelmDockerImageDependencyTag | HelmDockerImageDependencyVersion; -export interface ChartDefinition { - apiVersion: string; - name: string; - version: string; -} +export const ChartDefinition = z + .object({ + apiVersion: z.string().regex(/v([12])/), + name: z.string().min(1), + version: z.string().regex( + // Copied from https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string + /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/, + ), + }) + .partial(); +export type ChartDefinition = z.infer; + +export const ChartDefinitionYaml = Yaml.pipe(ChartDefinition); diff --git a/lib/modules/manager/helm-values/update.spec.ts b/lib/modules/manager/helm-values/update.spec.ts index 9601627974bd20..93acf46f1c1381 100644 --- a/lib/modules/manager/helm-values/update.spec.ts +++ b/lib/modules/manager/helm-values/update.spec.ts @@ -22,81 +22,58 @@ describe('modules/manager/helm-values/update', () => { beforeEach(() => { jest.resetAllMocks(); fs.readLocalFile.mockResolvedValueOnce(chartContent); - fs.getSiblingFileName.mockReturnValueOnce('test/Chart.yaml'); }); it('increments', async () => { - const { bumpedContent, bumpedFiles } = - await helmValuesUpdater.bumpPackageVersion( - helmValuesContent, - '0.0.2', - 'patch', - 'test/values.yaml', - ); - expect(bumpedContent).toEqual(helmValuesContent); - expect(bumpedFiles).toHaveLength(1); - const bumpedFile = bumpedFiles![0]; - expect(bumpedFile.fileName).toBe('test/Chart.yaml'); - expect(bumpedFile.newContent).toBe( - 'apiVersion: v2\nname: test\nversion: 0.0.3\n', + const { bumpedContent } = await helmValuesUpdater.bumpPackageVersion( + helmValuesContent, + '0.0.2', + 'patch', + 'test/values.yaml', ); + expect(bumpedContent).toEqual(helmValuesContent); }); it('no ops', async () => { - const { bumpedContent, bumpedFiles } = - await helmValuesUpdater.bumpPackageVersion( - helmValuesContent, - '0.0.1', - 'patch', - 'values.yaml', - ); + const { bumpedContent } = await helmValuesUpdater.bumpPackageVersion( + helmValuesContent, + '0.0.1', + 'patch', + 'values.yaml', + ); expect(bumpedContent).toEqual(helmValuesContent); - expect(bumpedFiles).toHaveLength(1); - const bumpedFile = bumpedFiles![0]; - expect(bumpedFile.newContent).toEqual(chartContent); }); it('updates', async () => { - const { bumpedContent, bumpedFiles } = - await helmValuesUpdater.bumpPackageVersion( - helmValuesContent, - '0.0.1', - 'minor', - 'test/values.yaml', - ); - expect(bumpedContent).toEqual(helmValuesContent); - expect(bumpedFiles).toHaveLength(1); - const bumpedFile = bumpedFiles![0]; - expect(bumpedFile.fileName).toBe('test/Chart.yaml'); - expect(bumpedFile.newContent).toBe( - 'apiVersion: v2\nname: test\nversion: 0.1.0\n', + const { bumpedContent } = await helmValuesUpdater.bumpPackageVersion( + helmValuesContent, + '0.0.1', + 'minor', + 'test/values.yaml', ); + expect(bumpedContent).toEqual(helmValuesContent); }); it('returns content if bumping errors', async () => { - const { bumpedContent, bumpedFiles } = - await helmValuesUpdater.bumpPackageVersion( - helmValuesContent, - '0.0.2', - true as any, - 'values.yaml', - ); + const { bumpedContent } = await helmValuesUpdater.bumpPackageVersion( + helmValuesContent, + '0.0.2', + true as any, + 'values.yaml', + ); expect(bumpedContent).toEqual(helmValuesContent); - expect(bumpedFiles).toBeUndefined(); }); it('returns content if retrieving Chart.yaml fails', async () => { jest.resetAllMocks(); fs.readLocalFile.mockRejectedValueOnce(null); - const { bumpedContent, bumpedFiles } = - await helmValuesUpdater.bumpPackageVersion( - helmValuesContent, - '0.0.2', - 'minor', - 'values.yaml', - ); + const { bumpedContent } = await helmValuesUpdater.bumpPackageVersion( + helmValuesContent, + '0.0.2', + 'minor', + 'values.yaml', + ); expect(bumpedContent).toEqual(helmValuesContent); - expect(bumpedFiles).toBeUndefined(); }); }); }); diff --git a/lib/modules/manager/helm-values/update.ts b/lib/modules/manager/helm-values/update.ts index 493abda86e10f0..1fb9e9a9fec3cf 100644 --- a/lib/modules/manager/helm-values/update.ts +++ b/lib/modules/manager/helm-values/update.ts @@ -1,6 +1,5 @@ import { ReleaseType, inc } from 'semver'; import { logger } from '../../../logger'; -import { getSiblingFileName } from '../../../util/fs'; import type { BumpPackageVersionResult } from '../types'; import { getSiblingChartYamlContent } from './util'; @@ -14,33 +13,9 @@ export async function bumpPackageVersion( { bumpVersion, currentValue }, 'Checking if we should bump Chart.yaml version', ); - const chartFileName = getSiblingFileName(packageFile, 'Chart.yaml'); const chartYamlContent = await getSiblingChartYamlContent(packageFile); - try { - const newChartVersion = inc(currentValue, bumpVersion); - if (!newChartVersion) { - throw new Error('semver inc failed'); - } - if (chartYamlContent === null) { - throw new Error( - 'Cannot bump chart version because Chart.yaml could not be read.', - ); - } - logger.debug({ newChartVersion }); - const bumpedContent = chartYamlContent?.replace( - /^(version:\s*).*$/m, - `$1${newChartVersion}`, - ); - if (bumpedContent === chartYamlContent) { - logger.debug('Version was already bumped'); - } else { - logger.debug('Bumped Chart.yaml version'); - } - return { - bumpedContent: content, - bumpedFiles: [{ fileName: chartFileName, newContent: bumpedContent }], - }; - } catch (err) { + const newChartVersion = inc(currentValue, bumpVersion); + if (!newChartVersion || chartYamlContent === null) { logger.warn( { chartYamlContent, @@ -53,4 +28,17 @@ export async function bumpPackageVersion( bumpedContent: content, }; } + logger.debug({ newChartVersion }); + const bumpedContent = chartYamlContent?.replace( + /^(version:\s*).*$/m, + `$1${newChartVersion}`, + ); + if (bumpedContent === chartYamlContent) { + logger.debug('Version was already bumped'); + } else { + logger.debug('Bumped Chart.yaml version'); + } + return { + bumpedContent: content, + }; } diff --git a/lib/modules/manager/helm-values/util.ts b/lib/modules/manager/helm-values/util.ts index 1f567fba9db374..980ba7bd773701 100644 --- a/lib/modules/manager/helm-values/util.ts +++ b/lib/modules/manager/helm-values/util.ts @@ -2,8 +2,11 @@ import { logger } from '../../../logger'; import { getSiblingFileName, readLocalFile } from '../../../util/fs'; import { hasKey } from '../../../util/object'; import { regEx } from '../../../util/regex'; -import { parseSingleYaml } from '../../../util/yaml'; -import type { ChartDefinition, HelmDockerImageDependency } from './types'; +import { + type ChartDefinition, + ChartDefinitionYaml, + type HelmDockerImageDependency, +} from './types'; const parentKeyRe = regEx(/image$/i); @@ -78,15 +81,7 @@ export async function getParsedSiblingChartYaml( logger.debug({ fileName }, 'Failed to find helm Chart.yaml'); return null; } - const chart = parseSingleYaml(chartContents) as ChartDefinition; - if (!(chart?.apiVersion && chart.name && chart.version)) { - logger.debug( - { fileName }, - 'Failed to find required fields in Chart.yaml', - ); - return null; - } - return chart; + return ChartDefinitionYaml.parse(chartContents); } catch (err) { logger.debug({ fileName }, 'Failed to parse helm Chart.yaml'); return null; diff --git a/lib/modules/manager/types.ts b/lib/modules/manager/types.ts index ee6cccebe25522..8e39836dac274c 100644 --- a/lib/modules/manager/types.ts +++ b/lib/modules/manager/types.ts @@ -199,12 +199,6 @@ export interface UpdateDependencyConfig> { 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 { diff --git a/lib/workers/repository/update/branch/__snapshots__/get-updated.spec.ts.snap b/lib/workers/repository/update/branch/__snapshots__/get-updated.spec.ts.snap index f13f9b6fa06eda..55675aa4f8d44a 100644 --- a/lib/workers/repository/update/branch/__snapshots__/get-updated.spec.ts.snap +++ b/lib/workers/repository/update/branch/__snapshots__/get-updated.spec.ts.snap @@ -1,5 +1,20 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() bumps versions in autoReplace managers 1`] = ` +{ + "artifactErrors": [], + "reuseExistingBranch": undefined, + "updatedArtifacts": [], + "updatedPackageFiles": [ + { + "contents": "version: 0.0.2", + "path": "Chart.yaml", + "type": "addition", + }, + ], +} +`; + exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() bumps versions in updateDependency managers 1`] = ` { "artifactErrors": [], @@ -175,75 +190,6 @@ exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() h } `; -exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() in autoReplace managers bumps versions 1`] = ` -{ - "artifactErrors": [], - "reuseExistingBranch": undefined, - "updatedArtifacts": [], - "updatedPackageFiles": [ - { - "contents": "version: 0.0.2", - "path": "Chart.yaml", - "type": "addition", - }, - ], -} -`; - -exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() in autoReplace managers bumps versions in all files if multiple files were bumped 1`] = ` -{ - "artifactErrors": [], - "reuseExistingBranch": undefined, - "updatedArtifacts": [], - "updatedPackageFiles": [ - { - "contents": "new content", - "path": "values.yaml", - "type": "addition", - }, - { - "contents": "version: 0.0.2", - "path": "/test/Chart.yaml", - "type": "addition", - }, - { - "contents": "# Version 0.0.2", - "path": "/test/README.md", - "type": "addition", - }, - ], -} -`; - -exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() in autoReplace managers bumps versions with a bumpPackageFile different from the packageFile 1`] = ` -{ - "artifactErrors": [], - "reuseExistingBranch": undefined, - "updatedArtifacts": [], - "updatedPackageFiles": [ - { - "contents": "new content", - "path": "values.yaml", - "type": "addition", - }, - { - "contents": "version: 0.0.2", - "path": "/test/Chart.yaml", - "type": "addition", - }, - ], -} -`; - -exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() in autoReplace managers doesn't bump versions if content wasn't changed 1`] = ` -{ - "artifactErrors": [], - "reuseExistingBranch": undefined, - "updatedArtifacts": [], - "updatedPackageFiles": [], -} -`; - exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() update artifacts on update-lockfile strategy 1`] = ` { "artifactErrors": [], diff --git a/lib/workers/repository/update/branch/get-updated.spec.ts b/lib/workers/repository/update/branch/get-updated.spec.ts index 2a4cf0342d0d9a..4a6590790e6734 100644 --- a/lib/workers/repository/update/branch/get-updated.spec.ts +++ b/lib/workers/repository/update/branch/get-updated.spec.ts @@ -4,7 +4,6 @@ import * as _batectWrapper from '../../../../modules/manager/batect-wrapper'; import * as _bundler from '../../../../modules/manager/bundler'; import * as _composer from '../../../../modules/manager/composer'; import * as _gitSubmodules from '../../../../modules/manager/git-submodules'; -import * as _helmValues from '../../../../modules/manager/helm-values'; import * as _helmv3 from '../../../../modules/manager/helmv3'; import * as _npm from '../../../../modules/manager/npm'; import type { BranchConfig, BranchUpgradeConfig } from '../../../types'; @@ -14,7 +13,6 @@ import { getUpdatedPackageFiles } from './get-updated'; const bundler = mocked(_bundler); const composer = mocked(_composer); const gitSubmodules = mocked(_gitSubmodules); -const helmValues = mocked(_helmValues); const helmv3 = mocked(_helmv3); const npm = mocked(_npm); const batectWrapper = mocked(_batectWrapper); @@ -22,7 +20,6 @@ const autoReplace = mocked(_autoReplace); jest.mock('../../../../modules/manager/bundler'); jest.mock('../../../../modules/manager/composer'); -jest.mock('../../../../modules/manager/helm-values'); jest.mock('../../../../modules/manager/helmv3'); jest.mock('../../../../modules/manager/npm'); jest.mock('../../../../modules/manager/git-submodules'); @@ -495,86 +492,27 @@ describe('workers/repository/update/branch/get-updated', () => { }); }); - describe('in autoReplace managers', () => { - it('bumps versions', async () => { - config.upgrades.push({ - packageFile: 'Chart.yaml', - branchName: '', - bumpVersion: 'patch', - manager: 'helmv3', - packageFileVersion: '0.0.1', - }); - autoReplace.doAutoReplace.mockResolvedValueOnce('version: 0.0.1'); - helmv3.bumpPackageVersion.mockReturnValue({ - bumpedContent: 'version: 0.0.2', - }); - const res = await getUpdatedPackageFiles(config); - expect(res).toMatchSnapshot(); - }); - - it('bumps versions with a bumpPackageFile different from the packageFile', async () => { - config.upgrades.push({ - packageFile: 'values.yaml', - branchName: '', - bumpVersion: 'patch', - manager: 'helm-values', - packageFileVersion: '0.0.1', - }); - autoReplace.doAutoReplace.mockResolvedValueOnce('new content'); - helmValues.bumpPackageVersion.mockResolvedValue({ - bumpedContent: 'new content', - bumpedFiles: [ - { - fileName: '/test/Chart.yaml', - newContent: 'version: 0.0.2', - }, - ], - }); - const res = await getUpdatedPackageFiles(config); - expect(res).toMatchSnapshot(); + it('bumps versions in autoReplace managers', async () => { + config.upgrades.push({ + packageFile: 'Chart.yaml', + branchName: '', + bumpVersion: 'patch', + manager: 'helmv3', + packageFileVersion: '0.0.1', }); - - it('bumps versions in all files if multiple files were bumped', async () => { - config.upgrades.push({ - packageFile: 'values.yaml', - branchName: '', - bumpVersion: 'patch', - manager: 'helm-values', - packageFileVersion: '0.0.1', - }); - autoReplace.doAutoReplace.mockResolvedValueOnce('new content'); - helmValues.bumpPackageVersion.mockResolvedValue({ - bumpedContent: 'new content', - bumpedFiles: [ - { - fileName: '/test/Chart.yaml', - newContent: 'version: 0.0.2', - }, - { - fileName: '/test/README.md', - newContent: '# Version 0.0.2', - }, - ], - }); - const res = await getUpdatedPackageFiles(config); - expect(res).toMatchSnapshot(); + autoReplace.doAutoReplace.mockResolvedValueOnce('version: 0.0.1'); + helmv3.bumpPackageVersion.mockReturnValue({ + bumpedContent: 'version: 0.0.2', }); - - it("doesn't bump versions if content wasn't changed", async () => { - config.upgrades.push({ - packageFile: 'values.yaml', - branchName: '', - bumpVersion: 'patch', - manager: 'helm-values', - packageFileVersion: '0.0.1', - }); - autoReplace.doAutoReplace.mockResolvedValueOnce('existing content'); - helmValues.bumpPackageVersion.mockResolvedValue({ - bumpedContent: 'existing content', - bumpedFiles: [], - }); - const res = await getUpdatedPackageFiles(config); - expect(res).toMatchSnapshot(); + const res = await getUpdatedPackageFiles(config); + expect(res).toMatchSnapshot({ + updatedPackageFiles: [ + { + type: 'addition', + path: 'Chart.yaml', + contents: 'version: 0.0.2', + }, + ], }); }); diff --git a/lib/workers/repository/update/branch/get-updated.ts b/lib/workers/repository/update/branch/get-updated.ts index 4c974be418c592..1adfb25bd34637 100644 --- a/lib/workers/repository/update/branch/get-updated.ts +++ b/lib/workers/repository/update/branch/get-updated.ts @@ -5,7 +5,6 @@ import { logger } from '../../../../logger'; import { get } from '../../../../modules/manager'; import type { ArtifactError, - BumpedPackageFile, PackageDependency, } from '../../../../modules/manager/types'; import { getFile } from '../../../../util/git'; @@ -186,20 +185,18 @@ export async function getUpdatedPackageFiles( ); firstUpdate = false; if (res) { - let bumpedPackageFiles: BumpedPackageFile[] = []; if ( bumpPackageVersion && upgrade.bumpVersion && upgrade.packageFileVersion ) { - const bumpResult = await bumpPackageVersion( + const { bumpedContent } = await bumpPackageVersion( res, upgrade.packageFileVersion, upgrade.bumpVersion, packageFile, ); - res = bumpResult.bumpedContent; - bumpedPackageFiles = bumpResult.bumpedFiles ?? []; + res = bumpedContent; } if (res === packageFileContent) { logger.debug({ packageFile, depName }, 'No content changed'); @@ -207,18 +204,6 @@ export async function getUpdatedPackageFiles( logger.debug({ packageFile, depName }, 'Contents updated'); updatedFileContents[packageFile] = res!; delete nonUpdatedFileContents[packageFile]; - // indicates that the version was bumped in one or more files in - // addition to or instead of the packageFile - if (bumpedPackageFiles) { - for (const bumpedPackageFile of bumpedPackageFiles) { - logger.debug( - { bumpedPackageFile, depName }, - 'Updating bumpedPackageFile content', - ); - updatedFileContents[bumpedPackageFile.fileName] = - bumpedPackageFile.newContent; - } - } } continue; } else if (reuseExistingBranch) { From c0cd271d52e181d88b09e511dc38ec8d07b2d076 Mon Sep 17 00:00:00 2001 From: kvanzuijlen <8818390+kvanzuijlen@users.noreply.github.com> Date: Wed, 3 Jan 2024 21:07:47 +0100 Subject: [PATCH 08/13] chore: PR feedback --- lib/modules/manager/helm-values/schema.ts | 13 +++++++++++++ lib/modules/manager/helm-values/types.ts | 17 ----------------- lib/modules/manager/helm-values/update.spec.ts | 1 - lib/modules/manager/helm-values/util.ts | 7 ++----- 4 files changed, 15 insertions(+), 23 deletions(-) create mode 100644 lib/modules/manager/helm-values/schema.ts diff --git a/lib/modules/manager/helm-values/schema.ts b/lib/modules/manager/helm-values/schema.ts new file mode 100644 index 00000000000000..c7f77fe7756323 --- /dev/null +++ b/lib/modules/manager/helm-values/schema.ts @@ -0,0 +1,13 @@ +import { z } from 'zod'; +import { Yaml } from '../../../util/schema-utils'; + +export const ChartDefinition = z + .object({ + apiVersion: z.string().regex(/v([12])/), + name: z.string().min(1), + version: z.string().min(1), + }) + .partial(); +export type ChartDefinition = z.infer; + +export const ChartDefinitionYaml = Yaml.pipe(ChartDefinition); diff --git a/lib/modules/manager/helm-values/types.ts b/lib/modules/manager/helm-values/types.ts index 845e2f3465ccf4..50dbe42b439ccd 100644 --- a/lib/modules/manager/helm-values/types.ts +++ b/lib/modules/manager/helm-values/types.ts @@ -1,6 +1,3 @@ -import { z } from 'zod'; -import { Yaml } from '../../../util/schema-utils'; - export interface HelmDockerImageDependencyBasic { registry?: string; repository: string; @@ -21,17 +18,3 @@ export interface HelmDockerImageDependencyVersion export type HelmDockerImageDependency = | HelmDockerImageDependencyTag | HelmDockerImageDependencyVersion; - -export const ChartDefinition = z - .object({ - apiVersion: z.string().regex(/v([12])/), - name: z.string().min(1), - version: z.string().regex( - // Copied from https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string - /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/, - ), - }) - .partial(); -export type ChartDefinition = z.infer; - -export const ChartDefinitionYaml = Yaml.pipe(ChartDefinition); diff --git a/lib/modules/manager/helm-values/update.spec.ts b/lib/modules/manager/helm-values/update.spec.ts index 93acf46f1c1381..e9d42da11272ba 100644 --- a/lib/modules/manager/helm-values/update.spec.ts +++ b/lib/modules/manager/helm-values/update.spec.ts @@ -20,7 +20,6 @@ describe('modules/manager/helm-values/update', () => { }); beforeEach(() => { - jest.resetAllMocks(); fs.readLocalFile.mockResolvedValueOnce(chartContent); }); diff --git a/lib/modules/manager/helm-values/util.ts b/lib/modules/manager/helm-values/util.ts index 980ba7bd773701..26814c6f46e794 100644 --- a/lib/modules/manager/helm-values/util.ts +++ b/lib/modules/manager/helm-values/util.ts @@ -2,11 +2,8 @@ import { logger } from '../../../logger'; import { getSiblingFileName, readLocalFile } from '../../../util/fs'; import { hasKey } from '../../../util/object'; import { regEx } from '../../../util/regex'; -import { - type ChartDefinition, - ChartDefinitionYaml, - type HelmDockerImageDependency, -} from './types'; +import { type ChartDefinition, ChartDefinitionYaml } from './schema'; +import type { HelmDockerImageDependency } from './types'; const parentKeyRe = regEx(/image$/i); From feba5fe6f47090c886614d2276403f97aa5c19e4 Mon Sep 17 00:00:00 2001 From: kvanzuijlen <8818390+kvanzuijlen@users.noreply.github.com> Date: Wed, 3 Jan 2024 21:08:06 +0100 Subject: [PATCH 09/13] chore: Reverted unrelated changes --- .../repository/update/branch/get-updated.ts | 39 +++++++------------ 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/lib/workers/repository/update/branch/get-updated.ts b/lib/workers/repository/update/branch/get-updated.ts index 1adfb25bd34637..1c17afadf4bda6 100644 --- a/lib/workers/repository/update/branch/get-updated.ts +++ b/lib/workers/repository/update/branch/get-updated.ts @@ -20,21 +20,6 @@ export interface PackageFilesResult { updatedArtifacts: FileChange[]; } -async function getFileContent( - updatedFileContents: Record, - filePath: string, - config: BranchConfig, -): Promise { - let fileContent: string | null = updatedFileContents[filePath]; - if (!fileContent) { - fileContent = await getFile( - filePath, - config.reuseExistingBranch ? config.branchName : config.baseBranch, - ); - } - return fileContent; -} - export async function getUpdatedPackageFiles( config: BranchConfig, ): Promise { @@ -61,19 +46,23 @@ export async function getUpdatedPackageFiles( packageFileUpdatedDeps[packageFile] = packageFileUpdatedDeps[packageFile] || []; packageFileUpdatedDeps[packageFile].push({ ...upgrade }); - const packageFileContent = await getFileContent( - updatedFileContents, - packageFile, - config, - ); + let packageFileContent: string | null = updatedFileContents[packageFile]; + if (!packageFileContent) { + packageFileContent = await getFile( + packageFile, + reuseExistingBranch ? config.branchName : config.baseBranch, + ); + } let lockFileContent: string | null = null; const lockFile = upgrade.lockFile ?? upgrade.lockFiles?.[0] ?? ''; if (lockFile) { - lockFileContent = await getFileContent( - updatedFileContents, - lockFile, - config, - ); + lockFileContent = updatedFileContents[lockFile]; + if (!lockFileContent) { + lockFileContent = await getFile( + lockFile, + reuseExistingBranch ? config.branchName : config.baseBranch, + ); + } } // istanbul ignore if if ( From bb7aa7c6b9b9c2b7a9ba6f17e3ce49c7329552c4 Mon Sep 17 00:00:00 2001 From: kvanzuijlen <8818390+kvanzuijlen@users.noreply.github.com> Date: Sun, 7 Jan 2024 21:21:47 +0100 Subject: [PATCH 10/13] chore: Reverted changes that should be in separate PR --- lib/workers/repository/update/branch/get-updated.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/workers/repository/update/branch/get-updated.ts b/lib/workers/repository/update/branch/get-updated.ts index 1c17afadf4bda6..648f107c25b213 100644 --- a/lib/workers/repository/update/branch/get-updated.ts +++ b/lib/workers/repository/update/branch/get-updated.ts @@ -183,7 +183,6 @@ export async function getUpdatedPackageFiles( res, upgrade.packageFileVersion, upgrade.bumpVersion, - packageFile, ); res = bumpedContent; } @@ -218,7 +217,6 @@ export async function getUpdatedPackageFiles( newContent, upgrade.packageFileVersion, upgrade.bumpVersion, - packageFile, ); newContent = bumpedContent; } From 7581208e10877d7c6c4a40befa234c27e577dede Mon Sep 17 00:00:00 2001 From: kvanzuijlen <8818390+kvanzuijlen@users.noreply.github.com> Date: Sun, 7 Jan 2024 21:33:39 +0100 Subject: [PATCH 11/13] fix: removed argument to bumpPackageVersion --- lib/modules/manager/types.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/modules/manager/types.ts b/lib/modules/manager/types.ts index 8e39836dac274c..8435b4e9b9d467 100644 --- a/lib/modules/manager/types.ts +++ b/lib/modules/manager/types.ts @@ -235,7 +235,6 @@ export interface ManagerApi extends ModuleApi { content: string, currentValue: string, bumpVersion: ReleaseType, - packageFile?: string, ): Result; detectGlobalConfig?(): Result; From 8858138b88559dbf9e205cf21efd04b8e6b7e611 Mon Sep 17 00:00:00 2001 From: kvanzuijlen <8818390+kvanzuijlen@users.noreply.github.com> Date: Sun, 7 Jan 2024 21:37:20 +0100 Subject: [PATCH 12/13] chore: Removed unnecessary resetAllMocks statement --- lib/modules/manager/helm-values/update.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/modules/manager/helm-values/update.spec.ts b/lib/modules/manager/helm-values/update.spec.ts index e9d42da11272ba..bd0fd0715d028c 100644 --- a/lib/modules/manager/helm-values/update.spec.ts +++ b/lib/modules/manager/helm-values/update.spec.ts @@ -64,7 +64,6 @@ describe('modules/manager/helm-values/update', () => { }); it('returns content if retrieving Chart.yaml fails', async () => { - jest.resetAllMocks(); fs.readLocalFile.mockRejectedValueOnce(null); const { bumpedContent } = await helmValuesUpdater.bumpPackageVersion( helmValuesContent, From a58bc1ac18efcb845c107af395ea77abd52c11c5 Mon Sep 17 00:00:00 2001 From: kvanzuijlen <8818390+kvanzuijlen@users.noreply.github.com> Date: Thu, 11 Jan 2024 03:17:43 +0100 Subject: [PATCH 13/13] fix(tests): Fixed test (+ coverage) --- lib/modules/manager/helm-values/update.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/modules/manager/helm-values/update.spec.ts b/lib/modules/manager/helm-values/update.spec.ts index bd0fd0715d028c..10290fb3766070 100644 --- a/lib/modules/manager/helm-values/update.spec.ts +++ b/lib/modules/manager/helm-values/update.spec.ts @@ -64,6 +64,7 @@ describe('modules/manager/helm-values/update', () => { }); it('returns content if retrieving Chart.yaml fails', async () => { + fs.readLocalFile.mockReset(); fs.readLocalFile.mockRejectedValueOnce(null); const { bumpedContent } = await helmValuesUpdater.bumpPackageVersion( helmValuesContent,