From 69fa567092a86ee8dd4db026ef2c720d28e635d6 Mon Sep 17 00:00:00 2001 From: secustor Date: Mon, 10 Jan 2022 13:00:41 +0100 Subject: [PATCH 1/4] fix: only update lock files if necessary when using `update-lockfile` and missing `updateLockDependency` --- .../__snapshots__/get-updated.spec.ts.snap | 9 +++++++ lib/workers/branch/get-updated.spec.ts | 24 +++++++++++++++++++ lib/workers/branch/get-updated.ts | 14 +++++++++-- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/lib/workers/branch/__snapshots__/get-updated.spec.ts.snap b/lib/workers/branch/__snapshots__/get-updated.spec.ts.snap index a54eaec9b806b8..a4301b5cba0230 100644 --- a/lib/workers/branch/__snapshots__/get-updated.spec.ts.snap +++ b/lib/workers/branch/__snapshots__/get-updated.spec.ts.snap @@ -178,6 +178,15 @@ Object { } `; +exports[`workers/branch/get-updated getUpdatedPackageFiles() reuse branch when update artifacts on update-lockfile strategy with no updateLockedDependency 1`] = ` +Object { + "artifactErrors": Array [], + "reuseExistingBranch": undefined, + "updatedArtifacts": Array [], + "updatedPackageFiles": Array [], +} +`; + exports[`workers/branch/get-updated getUpdatedPackageFiles() update artifacts on update-lockfile strategy 1`] = ` Object { "artifactErrors": Array [], diff --git a/lib/workers/branch/get-updated.spec.ts b/lib/workers/branch/get-updated.spec.ts index 0eb8c312e85f18..116571525a4ffc 100644 --- a/lib/workers/branch/get-updated.spec.ts +++ b/lib/workers/branch/get-updated.spec.ts @@ -295,6 +295,30 @@ describe('workers/branch/get-updated', () => { ], }); }); + + it('reuse branch when update artifacts on update-lockfile strategy with no updateLockedDependency', async () => { + config.upgrades.push({ + packageFile: 'pyproject.toml', + manager: 'poetry', + branchName: undefined, + isLockfileUpdate: true, + }); + poetry.updateArtifacts.mockResolvedValueOnce([ + { + file: { + name: 'poetry.lock', + contents: 'some contents', + }, + }, + ]); + git.getFile.mockResolvedValueOnce('some contents'); + const res = await getUpdatedPackageFiles(config); + expect(res).toMatchSnapshot({ + updatedArtifacts: [], + updatedPackageFiles: [], + }); + }); + it('attempts updateLockedDependency and handles unsupported', async () => { config.upgrades.push({ packageFile: 'package.json', diff --git a/lib/workers/branch/get-updated.ts b/lib/workers/branch/get-updated.ts index f5855407afc7ac..28e5e3339481c2 100644 --- a/lib/workers/branch/get-updated.ts +++ b/lib/workers/branch/get-updated.ts @@ -260,16 +260,26 @@ export async function getUpdatedPackageFiles( config, }); if (is.nonEmptyArray(results)) { - updatedPackageFiles.push(packageFile); + let updated = false; for (const res of results) { const { file, artifactError } = res; // istanbul ignore else - if (file) { + if ( + file && + (await getFile( + file.name, + reuseExistingBranch ? config.branchName : config.baseBranch + )) !== file.contents + ) { updatedArtifacts.push(file); + updated = true; } else if (artifactError) { artifactErrors.push(artifactError); } } + if (updated) { + updatedPackageFiles.push(packageFile); + } } } } From 9a697c9768c6462f18d2780159d4b92721cd3ca2 Mon Sep 17 00:00:00 2001 From: secustor Date: Mon, 10 Jan 2022 18:58:51 +0100 Subject: [PATCH 2/4] use toEqual instead of snapshot --- .../branch/__snapshots__/get-updated.spec.ts.snap | 9 --------- lib/workers/branch/get-updated.spec.ts | 4 +++- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/workers/branch/__snapshots__/get-updated.spec.ts.snap b/lib/workers/branch/__snapshots__/get-updated.spec.ts.snap index a4301b5cba0230..a54eaec9b806b8 100644 --- a/lib/workers/branch/__snapshots__/get-updated.spec.ts.snap +++ b/lib/workers/branch/__snapshots__/get-updated.spec.ts.snap @@ -178,15 +178,6 @@ Object { } `; -exports[`workers/branch/get-updated getUpdatedPackageFiles() reuse branch when update artifacts on update-lockfile strategy with no updateLockedDependency 1`] = ` -Object { - "artifactErrors": Array [], - "reuseExistingBranch": undefined, - "updatedArtifacts": Array [], - "updatedPackageFiles": Array [], -} -`; - exports[`workers/branch/get-updated getUpdatedPackageFiles() update artifacts on update-lockfile strategy 1`] = ` Object { "artifactErrors": Array [], diff --git a/lib/workers/branch/get-updated.spec.ts b/lib/workers/branch/get-updated.spec.ts index 116571525a4ffc..9b44f34891bf30 100644 --- a/lib/workers/branch/get-updated.spec.ts +++ b/lib/workers/branch/get-updated.spec.ts @@ -313,7 +313,9 @@ describe('workers/branch/get-updated', () => { ]); git.getFile.mockResolvedValueOnce('some contents'); const res = await getUpdatedPackageFiles(config); - expect(res).toMatchSnapshot({ + expect(res).toEqual({ + artifactErrors: [], + reuseExistingBranch: undefined, updatedArtifacts: [], updatedPackageFiles: [], }); From 4851cac59e7fb2e45e61e50ff1f7271255605a54 Mon Sep 17 00:00:00 2001 From: secustor Date: Sat, 22 Jan 2022 16:06:26 +0100 Subject: [PATCH 3/4] handle buffer and empty content --- lib/workers/branch/get-updated.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/workers/branch/get-updated.ts b/lib/workers/branch/get-updated.ts index 28e5e3339481c2..170b959543af71 100644 --- a/lib/workers/branch/get-updated.ts +++ b/lib/workers/branch/get-updated.ts @@ -266,10 +266,11 @@ export async function getUpdatedPackageFiles( // istanbul ignore else if ( file && + file.contents !== '' && // only check if artifact is non-empty --> ignore git-submodule artifacts (await getFile( file.name, reuseExistingBranch ? config.branchName : config.baseBranch - )) !== file.contents + )) !== file.contents.toString() // convert to string if defined as buffer ) { updatedArtifacts.push(file); updated = true; From b4a9c2e0eec5f8b58640e148087585f9709f17b2 Mon Sep 17 00:00:00 2001 From: secustor Date: Fri, 28 Jan 2022 15:55:49 +0100 Subject: [PATCH 4/4] refactor: integrate external changes --- lib/workers/branch/get-updated.spec.ts | 3 ++- lib/workers/branch/get-updated.ts | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/workers/branch/get-updated.spec.ts b/lib/workers/branch/get-updated.spec.ts index 1d25f13e2f938e..3a1ff59bb3fc6c 100644 --- a/lib/workers/branch/get-updated.spec.ts +++ b/lib/workers/branch/get-updated.spec.ts @@ -356,7 +356,8 @@ describe('workers/branch/get-updated', () => { poetry.updateArtifacts.mockResolvedValueOnce([ { file: { - name: 'poetry.lock', + type: 'addition', + path: 'poetry.lock', contents: 'some contents', }, }, diff --git a/lib/workers/branch/get-updated.ts b/lib/workers/branch/get-updated.ts index ba242588a69ba5..42efe6dbe2259f 100644 --- a/lib/workers/branch/get-updated.ts +++ b/lib/workers/branch/get-updated.ts @@ -269,10 +269,10 @@ export async function getUpdatedPackageFiles( const { file, artifactError } = res; // istanbul ignore else if ( - file && + file?.type === 'addition' && file.contents !== '' && // only check if artifact is non-empty --> ignore git-submodule artifacts (await getFile( - file.name, + file.path, reuseExistingBranch ? config.branchName : config.baseBranch )) !== file.contents.toString() // convert to string if defined as buffer ) {