diff --git a/lib/manager/batect-wrapper/artifacts.spec.ts b/lib/manager/batect-wrapper/artifacts.spec.ts index 7ab182b0583c919f25aae979008afe5d4bf2a176..1513ba2e539630e9f3ce65235971a6e4f8b77ff0 100644 --- a/lib/manager/batect-wrapper/artifacts.spec.ts +++ b/lib/manager/batect-wrapper/artifacts.spec.ts @@ -58,13 +58,15 @@ describe('manager/batect-wrapper/artifacts', () => { expect(result).toEqual([ { file: { - name: 'batect', + type: 'addition', + path: 'batect', contents: newUnixWrapperContent, }, }, { file: { - name: 'batect.cmd', + type: 'addition', + path: 'batect.cmd', contents: newWindowsWrapperContent, }, }, @@ -78,13 +80,15 @@ describe('manager/batect-wrapper/artifacts', () => { expect(result).toEqual([ { file: { - name: 'some/sub/dir/batect', + type: 'addition', + path: 'some/sub/dir/batect', contents: newUnixWrapperContent, }, }, { file: { - name: 'some/sub/dir/batect.cmd', + type: 'addition', + path: 'some/sub/dir/batect.cmd', contents: newWindowsWrapperContent, }, }, diff --git a/lib/manager/batect-wrapper/artifacts.ts b/lib/manager/batect-wrapper/artifacts.ts index 5a1198f7b83936b47d5ee0772e46b23536d56c21..1d28c0fd1a70e795f1f79cb389ed7026af0153a3 100644 --- a/lib/manager/batect-wrapper/artifacts.ts +++ b/lib/manager/batect-wrapper/artifacts.ts @@ -16,10 +16,7 @@ async function updateArtifact( const contents = response.body; return { - file: { - name: path, - contents, - }, + file: { type: 'addition', path, contents }, }; } catch (err) { const errorDescription: string = err.toString(); diff --git a/lib/manager/bundler/artifacts.spec.ts b/lib/manager/bundler/artifacts.spec.ts index d0ce943b323a93d806e816bf2c68058ad4b44c82..eb865ba3e952629040577cbee90b61575e249638 100644 --- a/lib/manager/bundler/artifacts.spec.ts +++ b/lib/manager/bundler/artifacts.spec.ts @@ -36,8 +36,9 @@ const config: UpdateArtifactsConfig = {}; const updatedGemfileLock = { file: { + type: 'addition', + path: 'Gemfile.lock', contents: 'Updated Gemfile.lock', - name: 'Gemfile.lock', }, }; diff --git a/lib/manager/bundler/artifacts.ts b/lib/manager/bundler/artifacts.ts index a69d7389e9b8ba40c2f2a7f26ae8d9bb3591775d..d0adfc7cc9c073506e37c31e4ecd1f999c9bcbf0 100644 --- a/lib/manager/bundler/artifacts.ts +++ b/lib/manager/bundler/artifacts.ts @@ -198,7 +198,8 @@ export async function updateArtifacts( return [ { file: { - name: lockFileName, + type: 'addition', + path: lockFileName, contents: lockFileContent, }, }, diff --git a/lib/manager/cargo/artifacts.ts b/lib/manager/cargo/artifacts.ts index 0627b9a15c4ea9b537d30cfd71a2deedc9e61af9..5aaf6905ddd09dc26605b8db815d65bac77fc9c2 100644 --- a/lib/manager/cargo/artifacts.ts +++ b/lib/manager/cargo/artifacts.ts @@ -74,7 +74,8 @@ export async function updateArtifacts({ return [ { file: { - name: lockFileName, + type: 'addition', + path: lockFileName, contents: newCargoLockContent, }, }, diff --git a/lib/manager/cocoapods/__snapshots__/artifacts.spec.ts.snap b/lib/manager/cocoapods/__snapshots__/artifacts.spec.ts.snap index af05dec48c498b644566dc1c4c0616f23af0c157..047cbe24cae6abc3f48b2b3f64dc89a1190697bf 100644 --- a/lib/manager/cocoapods/__snapshots__/artifacts.spec.ts.snap +++ b/lib/manager/cocoapods/__snapshots__/artifacts.spec.ts.snap @@ -129,7 +129,8 @@ Array [ Object { "file": Object { "contents": "New Podfile", - "name": "Podfile.lock", + "path": "Podfile.lock", + "type": "addition", }, }, ] @@ -175,25 +176,28 @@ Array [ Object { "file": Object { "contents": "New Podfile", - "name": "Podfile.lock", + "path": "Podfile.lock", + "type": "addition", }, }, Object { "file": Object { "contents": undefined, - "name": "Pods/Manifest.lock", + "path": "Pods/Manifest.lock", + "type": "addition", }, }, Object { "file": Object { "contents": undefined, - "name": "Pods/New", + "path": "Pods/New", + "type": "addition", }, }, Object { "file": Object { - "contents": "Pods/Deleted", - "name": "|delete|", + "path": "Pods/Deleted", + "type": "deletion", }, }, ] diff --git a/lib/manager/cocoapods/artifacts.spec.ts b/lib/manager/cocoapods/artifacts.spec.ts index 21d1fa9c5936c7f393eb44d786f4dd4deb163c58..8cf8c099e5c79872f0cd1c48cc990a12b3a717e7 100644 --- a/lib/manager/cocoapods/artifacts.spec.ts +++ b/lib/manager/cocoapods/artifacts.spec.ts @@ -169,10 +169,10 @@ describe('manager/cocoapods/artifacts', () => { config, }) ).toMatchSnapshot([ - { file: { name: 'Podfile.lock' } }, - { file: { name: 'Pods/Manifest.lock' } }, - { file: { name: 'Pods/New' } }, - { file: { name: '|delete|' } }, + { file: { type: 'addition', path: 'Podfile.lock' } }, + { file: { type: 'addition', path: 'Pods/Manifest.lock' } }, + { file: { type: 'addition', path: 'Pods/New' } }, + { file: { type: 'deletion', path: 'Pods/Deleted' } }, ]); expect(execSnapshots).toMatchSnapshot(); }); diff --git a/lib/manager/cocoapods/artifacts.ts b/lib/manager/cocoapods/artifacts.ts index 91d84de32ca8f87352bfc4b3e4427a33c6b1514d..4c30ad6be5a9fc11dfbc01b6848499e19670f568 100644 --- a/lib/manager/cocoapods/artifacts.ts +++ b/lib/manager/cocoapods/artifacts.ts @@ -108,7 +108,8 @@ export async function updateArtifacts({ const res: UpdateArtifactsResult[] = [ { file: { - name: lockFileName, + type: 'addition', + path: lockFileName, contents: lockFileContent, }, }, @@ -121,7 +122,8 @@ export async function updateArtifacts({ if (f.startsWith(podsDir)) { res.push({ file: { - name: f, + type: 'addition', + path: f, contents: await readLocalFile(f), }, }); @@ -130,8 +132,8 @@ export async function updateArtifacts({ for (const f of status.deleted || []) { res.push({ file: { - name: '|delete|', - contents: f, + type: 'deletion', + path: f, }, }); } diff --git a/lib/manager/composer/artifacts.spec.ts b/lib/manager/composer/artifacts.spec.ts index 7ebeaa8f2a42813e607ca8592f054edcab34a357..15b24d72c460aed934d924fd1a6ef8e17b475b9d 100644 --- a/lib/manager/composer/artifacts.spec.ts +++ b/lib/manager/composer/artifacts.spec.ts @@ -193,10 +193,10 @@ describe('manager/composer/artifacts', () => { }); expect(res).not.toBeNull(); expect(res?.map(({ file }) => file)).toEqual([ - { contents: '{ }', name: 'composer.lock' }, - { contents: 'Foo', name: foo }, - { contents: 'Bar', name: bar }, - { contents: baz, name: '|delete|' }, + { type: 'addition', path: 'composer.lock', contents: '{ }' }, + { type: 'addition', path: foo, contents: 'Foo' }, + { type: 'addition', path: bar, contents: 'Bar' }, + { type: 'deletion', path: baz }, ]); expect(execSnapshots).toMatchSnapshot(); }); diff --git a/lib/manager/composer/artifacts.ts b/lib/manager/composer/artifacts.ts index 4e6c0c648906ab05599d44253099f159982609a6..1ab1152a5090dbaddb100008bddf880968a68ba8 100644 --- a/lib/manager/composer/artifacts.ts +++ b/lib/manager/composer/artifacts.ts @@ -154,7 +154,8 @@ export async function updateArtifacts({ const res: UpdateArtifactsResult[] = [ { file: { - name: lockFileName, + type: 'addition', + path: lockFileName, contents: await readLocalFile(lockFileName), }, }, @@ -169,7 +170,8 @@ export async function updateArtifacts({ if (f.startsWith(vendorDir)) { res.push({ file: { - name: f, + type: 'addition', + path: f, contents: await readLocalFile(f), }, }); @@ -178,8 +180,8 @@ export async function updateArtifacts({ for (const f of status.deleted) { res.push({ file: { - name: '|delete|', - contents: f, + type: 'deletion', + path: f, }, }); } diff --git a/lib/manager/git-submodules/__snapshots__/artifact.spec.ts.snap b/lib/manager/git-submodules/__snapshots__/artifact.spec.ts.snap index 37c94fe5b6f8dcb145b1de59b22a618c0e3fb29a..b3383be2c0f0240a23e19b9521fb60ce084ded5d 100644 --- a/lib/manager/git-submodules/__snapshots__/artifact.spec.ts.snap +++ b/lib/manager/git-submodules/__snapshots__/artifact.spec.ts.snap @@ -5,7 +5,8 @@ Array [ Object { "file": Object { "contents": "", - "name": "", + "path": "", + "type": "addition", }, }, ] @@ -16,13 +17,15 @@ Array [ Object { "file": Object { "contents": "", - "name": "renovate", + "path": "renovate", + "type": "addition", }, }, Object { "file": Object { "contents": "", - "name": "renovate-pro", + "path": "renovate-pro", + "type": "addition", }, }, ] diff --git a/lib/manager/git-submodules/artifact.spec.ts b/lib/manager/git-submodules/artifact.spec.ts index f81dd26bc14c035fdf000425d82e48d610445a82..4f686f4c20c0077fdc758800039de30cd6c5d993 100644 --- a/lib/manager/git-submodules/artifact.spec.ts +++ b/lib/manager/git-submodules/artifact.spec.ts @@ -10,7 +10,9 @@ describe('manager/git-submodules/artifact', () => { newPackageFileContent: '', config: {}, }) - ).toMatchSnapshot([{ file: { contents: '', name: '' } }]); + ).toMatchSnapshot([ + { file: { type: 'addition', path: '', contents: '' } }, + ]); }); it('returns two modules', () => { expect( @@ -21,8 +23,8 @@ describe('manager/git-submodules/artifact', () => { config: {}, }) ).toMatchSnapshot([ - { file: { name: 'renovate' } }, - { file: { name: 'renovate-pro' } }, + { file: { type: 'addition', path: 'renovate', contents: '' } }, + { file: { type: 'addition', path: 'renovate-pro', contents: '' } }, ]); }); }); diff --git a/lib/manager/git-submodules/artifacts.ts b/lib/manager/git-submodules/artifacts.ts index d3f75f2c376d81a668c51f93f2ba85063491a292..b3d73ce7b1c107750defa9f64a44cc2d49a39c9d 100644 --- a/lib/manager/git-submodules/artifacts.ts +++ b/lib/manager/git-submodules/artifacts.ts @@ -8,10 +8,7 @@ export default function updateArtifacts({ updatedDeps.forEach((dep) => { logger.info('Updating submodule ' + dep.depName); res.push({ - file: { - name: dep.depName, - contents: '', - }, + file: { type: 'addition', path: dep.depName, contents: '' }, }); }); return res; diff --git a/lib/manager/gomod/__snapshots__/artifacts.spec.ts.snap b/lib/manager/gomod/__snapshots__/artifacts.spec.ts.snap index f623052a8cdb650a50506fb28419dfdb2bc3535b..48732f2a7e299b6375f92e42f58b0f186fe51ebd 100644 --- a/lib/manager/gomod/__snapshots__/artifacts.spec.ts.snap +++ b/lib/manager/gomod/__snapshots__/artifacts.spec.ts.snap @@ -7,13 +7,15 @@ Array [ Object { "file": Object { "contents": "New go.sum", - "name": "go.sum", + "path": "go.sum", + "type": "addition", }, }, Object { "file": Object { "contents": "New main.go", - "name": "go.mod", + "path": "go.mod", + "type": "addition", }, }, ] @@ -113,13 +115,15 @@ Array [ Object { "file": Object { "contents": "New go.sum", - "name": "go.sum", + "path": "go.sum", + "type": "addition", }, }, Object { "file": Object { "contents": "New main.go", - "name": "go.mod", + "path": "go.mod", + "type": "addition", }, }, ] diff --git a/lib/manager/gomod/artifacts.spec.ts b/lib/manager/gomod/artifacts.spec.ts index 133f738e39af5855b09cf52f2fffb3a3228fe010..b405e00895383c4aa5210e55613fe7229c67d1d8 100644 --- a/lib/manager/gomod/artifacts.spec.ts +++ b/lib/manager/gomod/artifacts.spec.ts @@ -142,11 +142,11 @@ describe('manager/gomod/artifacts', () => { }); expect(res).not.toBeNull(); expect(res?.map(({ file }) => file)).toEqual([ - { contents: 'New go.sum', name: 'go.sum' }, - { contents: 'Foo go.sum', name: foo }, - { contents: 'Bar go.sum', name: bar }, - { contents: baz, name: '|delete|' }, - { contents: 'New go.mod', name: 'go.mod' }, + { type: 'addition', path: 'go.sum', contents: 'New go.sum' }, + { type: 'addition', path: foo, contents: 'Foo go.sum' }, + { type: 'addition', path: bar, contents: 'Bar go.sum' }, + { type: 'deletion', path: baz }, + { type: 'addition', path: 'go.mod', contents: 'New go.mod' }, ]); expect(execSnapshots).toMatchSnapshot(); }); @@ -598,9 +598,9 @@ describe('manager/gomod/artifacts', () => { }, }) ).toEqual([ - { file: { contents: 'New go.sum', name: 'go.sum' } }, - { file: { contents: 'New main.go', name: 'main.go' } }, - { file: { contents: 'New go.mod', name: 'go.mod' } }, + { file: { type: 'addition', path: 'go.sum', contents: 'New go.sum' } }, + { file: { type: 'addition', path: 'main.go', contents: 'New main.go' } }, + { file: { type: 'addition', path: 'go.mod', contents: 'New go.mod' } }, ]); expect(execSnapshots).toMatchSnapshot(); }); @@ -628,8 +628,8 @@ describe('manager/gomod/artifacts', () => { }, }) ).toEqual([ - { file: { contents: 'New go.sum', name: 'go.sum' } }, - { file: { contents: 'New go.mod', name: 'go.mod' } }, + { file: { type: 'addition', path: 'go.sum', contents: 'New go.sum' } }, + { file: { type: 'addition', path: 'go.mod', contents: 'New go.mod' } }, ]); expect(execSnapshots).toMatchSnapshot(); }); @@ -714,9 +714,9 @@ describe('manager/gomod/artifacts', () => { }, }) ).toEqual([ - { file: { contents: 'New go.sum', name: 'go.sum' } }, - { file: { contents: 'New main.go', name: 'main.go' } }, - { file: { contents: 'New go.mod', name: 'go.mod' } }, + { file: { type: 'addition', path: 'go.sum', contents: 'New go.sum' } }, + { file: { type: 'addition', path: 'main.go', contents: 'New main.go' } }, + { file: { type: 'addition', path: 'go.mod', contents: 'New go.mod' } }, ]); expect(execSnapshots).toMatchSnapshot(); }); @@ -748,9 +748,9 @@ describe('manager/gomod/artifacts', () => { }, }) ).toEqual([ - { file: { contents: 'New go.sum', name: 'go.sum' } }, - { file: { contents: 'New main.go', name: 'main.go' } }, - { file: { contents: 'New go.mod', name: 'go.mod' } }, + { file: { type: 'addition', path: 'go.sum', contents: 'New go.sum' } }, + { file: { type: 'addition', path: 'main.go', contents: 'New main.go' } }, + { file: { type: 'addition', path: 'go.mod', contents: 'New go.mod' } }, ]); expect(execSnapshots).toMatchSnapshot(); }); @@ -778,8 +778,8 @@ describe('manager/gomod/artifacts', () => { }, }) ).toEqual([ - { file: { contents: 'New go.sum', name: 'go.sum' } }, - { file: { contents: 'New go.mod', name: 'go.mod' } }, + { file: { type: 'addition', path: 'go.sum', contents: 'New go.sum' } }, + { file: { type: 'addition', path: 'go.mod', contents: 'New go.mod' } }, ]); expect(execSnapshots).toMatchSnapshot(); }); diff --git a/lib/manager/gomod/artifacts.ts b/lib/manager/gomod/artifacts.ts index d0e6260f5d2b21be33984fce875082d89cd10e7c..b03de4239c0f5142cb2c0dc225357723b92bdf62 100644 --- a/lib/manager/gomod/artifacts.ts +++ b/lib/manager/gomod/artifacts.ts @@ -252,7 +252,8 @@ export async function updateArtifacts({ const res: UpdateArtifactsResult[] = [ { file: { - name: sumFileName, + type: 'addition', + path: sumFileName, contents: await readLocalFile(sumFileName), }, }, @@ -265,7 +266,8 @@ export async function updateArtifacts({ if (f.endsWith('.go')) { res.push({ file: { - name: f, + type: 'addition', + path: f, contents: await readLocalFile(f), }, }); @@ -278,7 +280,8 @@ export async function updateArtifacts({ if (f.startsWith(vendorDir)) { res.push({ file: { - name: f, + type: 'addition', + path: f, contents: await readLocalFile(f), }, }); @@ -287,8 +290,8 @@ export async function updateArtifacts({ for (const f of status.deleted || []) { res.push({ file: { - name: '|delete|', - contents: f, + type: 'deletion', + path: f, }, }); } @@ -301,7 +304,8 @@ export async function updateArtifacts({ logger.debug('Found updated go.mod after go.sum update'); res.push({ file: { - name: goModFileName, + type: 'addition', + path: goModFileName, contents: finalGoModContent, }, }); diff --git a/lib/manager/gradle-wrapper/artifacts.spec.ts b/lib/manager/gradle-wrapper/artifacts.spec.ts index 4d042f021fdfbd362ae5231dbcb8aa25283d46a9..c4b5aa83d488df69364c23f7356d8e88d3e88656 100644 --- a/lib/manager/gradle-wrapper/artifacts.spec.ts +++ b/lib/manager/gradle-wrapper/artifacts.spec.ts @@ -88,7 +88,8 @@ describe('manager/gradle-wrapper/artifacts', () => { 'gradlew.bat', ].map((fileProjectPath) => ({ file: { - name: fileProjectPath, + type: 'addition', + path: fileProjectPath, contents: 'test', }, })) diff --git a/lib/manager/gradle-wrapper/artifacts.ts b/lib/manager/gradle-wrapper/artifacts.ts index 461ae067e4ebe530227226771540f080f6c44737..10d0500c00b6816b17088441ff044cd7bc2eaf82 100644 --- a/lib/manager/gradle-wrapper/artifacts.ts +++ b/lib/manager/gradle-wrapper/artifacts.ts @@ -27,7 +27,8 @@ async function addIfUpdated( if (status.modified.includes(fileProjectPath)) { return { file: { - name: fileProjectPath, + type: 'addition', + path: fileProjectPath, contents: await readLocalFile(fileProjectPath), }, }; @@ -130,7 +131,7 @@ export async function updateArtifacts({ ) ).filter(Boolean); logger.debug( - { files: updateArtifactsResult.map((r) => r.file.name) }, + { files: updateArtifactsResult.map((r) => r.file.path) }, `Returning updated gradle-wrapper files` ); return updateArtifactsResult; diff --git a/lib/manager/helmv3/__snapshots__/artifacts.spec.ts.snap b/lib/manager/helmv3/__snapshots__/artifacts.spec.ts.snap index b29ab6b050a5575892f85c0527e88fb3156dc95e..727719750f81d1f22d583f386a26bdb25acd59aa 100644 --- a/lib/manager/helmv3/__snapshots__/artifacts.spec.ts.snap +++ b/lib/manager/helmv3/__snapshots__/artifacts.spec.ts.snap @@ -40,7 +40,8 @@ Array [ Object { "file": Object { "contents": "New Chart.lock", - "name": "Chart.lock", + "path": "Chart.lock", + "type": "addition", }, }, ] @@ -75,7 +76,8 @@ Array [ Object { "file": Object { "contents": "New Chart.lock", - "name": "Chart.lock", + "path": "Chart.lock", + "type": "addition", }, }, ] @@ -110,7 +112,8 @@ Array [ Object { "file": Object { "contents": "New Chart.lock", - "name": "Chart.lock", + "path": "Chart.lock", + "type": "addition", }, }, ] @@ -157,7 +160,8 @@ Array [ Object { "file": Object { "contents": "New Chart.lock", - "name": "Chart.lock", + "path": "Chart.lock", + "type": "addition", }, }, ] @@ -230,7 +234,8 @@ Array [ Object { "file": Object { "contents": "New Chart.lock", - "name": "Chart.lock", + "path": "Chart.lock", + "type": "addition", }, }, ] diff --git a/lib/manager/helmv3/artifacts.spec.ts b/lib/manager/helmv3/artifacts.spec.ts index 54238b5cfafba73f442343b9e7e4e14488a20569..1e3fc906495b7dabe306688b68ee01696d8da214 100644 --- a/lib/manager/helmv3/artifacts.spec.ts +++ b/lib/manager/helmv3/artifacts.spec.ts @@ -86,7 +86,13 @@ describe('manager/helmv3/artifacts', () => { config, }) ).toMatchSnapshot([ - { file: { contents: 'New Chart.lock', name: 'Chart.lock' } }, + { + file: { + type: 'addition', + path: 'Chart.lock', + contents: 'New Chart.lock', + }, + }, ]); expect(execSnapshots).toMatchSnapshot(); }); @@ -103,7 +109,13 @@ describe('manager/helmv3/artifacts', () => { config: { ...config, updateType: 'lockFileMaintenance' }, }) ).toMatchSnapshot([ - { file: { contents: 'New Chart.lock', name: 'Chart.lock' } }, + { + file: { + type: 'addition', + path: 'Chart.lock', + contents: 'New Chart.lock', + }, + }, ]); expect(execSnapshots).toMatchSnapshot(); }); @@ -122,7 +134,13 @@ describe('manager/helmv3/artifacts', () => { config, }) ).toMatchSnapshot([ - { file: { contents: 'New Chart.lock', name: 'Chart.lock' } }, + { + file: { + type: 'addition', + path: 'Chart.lock', + contents: 'New Chart.lock', + }, + }, ]); expect(execSnapshots).toMatchSnapshot(); }); @@ -165,7 +183,13 @@ describe('manager/helmv3/artifacts', () => { }, }) ).toMatchSnapshot([ - { file: { contents: 'New Chart.lock', name: 'Chart.lock' } }, + { + file: { + type: 'addition', + path: 'Chart.lock', + contents: 'New Chart.lock', + }, + }, ]); expect(execSnapshots).toMatchSnapshot(); }); @@ -187,7 +211,13 @@ describe('manager/helmv3/artifacts', () => { }, }) ).toMatchSnapshot([ - { file: { contents: 'New Chart.lock', name: 'Chart.lock' } }, + { + file: { + type: 'addition', + path: 'Chart.lock', + contents: 'New Chart.lock', + }, + }, ]); expect(execSnapshots).toMatchSnapshot(); }); diff --git a/lib/manager/helmv3/artifacts.ts b/lib/manager/helmv3/artifacts.ts index a2c47cb335786faf3d453d7625d5b5ac615e9838..0bb830c5d7a7b231f3fa0d38cfc781c7d19b9dea 100644 --- a/lib/manager/helmv3/artifacts.ts +++ b/lib/manager/helmv3/artifacts.ts @@ -72,7 +72,8 @@ export async function updateArtifacts({ return [ { file: { - name: lockFileName, + type: 'addition', + path: lockFileName, contents: newHelmLockContent, }, }, diff --git a/lib/manager/jsonnet-bundler/__snapshots__/artifacts.spec.ts.snap b/lib/manager/jsonnet-bundler/__snapshots__/artifacts.spec.ts.snap index 79d70146d35e51b4ab2a7ebaf31c1869db816398..8e85ddc0ff0261049782220e418a716cba0a8f50 100644 --- a/lib/manager/jsonnet-bundler/__snapshots__/artifacts.spec.ts.snap +++ b/lib/manager/jsonnet-bundler/__snapshots__/artifacts.spec.ts.snap @@ -5,7 +5,8 @@ Array [ Object { "file": Object { "contents": "Updated jsonnetfile.lock.json", - "name": "jsonnetfile.lock.json", + "path": "jsonnetfile.lock.json", + "type": "addition", }, }, ] @@ -75,31 +76,35 @@ Array [ Object { "file": Object { "contents": "Updated jsonnetfile.json", - "name": "jsonnetfile.json", + "path": "jsonnetfile.json", + "type": "addition", }, }, Object { "file": Object { "contents": "Updated jsonnetfile.lock.json", - "name": "jsonnetfile.lock.json", + "path": "jsonnetfile.lock.json", + "type": "addition", }, }, Object { "file": Object { "contents": "New foo/main.jsonnet", - "name": "vendor/foo/main.jsonnet", + "path": "vendor/foo/main.jsonnet", + "type": "addition", }, }, Object { "file": Object { "contents": "New bar/main.jsonnet", - "name": "vendor/bar/main.jsonnet", + "path": "vendor/bar/main.jsonnet", + "type": "addition", }, }, Object { "file": Object { - "contents": "vendor/baz/deleted.jsonnet", - "name": "|delete|", + "path": "vendor/baz/deleted.jsonnet", + "type": "deletion", }, }, ] diff --git a/lib/manager/jsonnet-bundler/artifacts.spec.ts b/lib/manager/jsonnet-bundler/artifacts.spec.ts index 87c666493499b2b5edd87210ec6f00eb8b91000f..cfe76346df6e696c93221c6edbd56ea4e8277cc4 100644 --- a/lib/manager/jsonnet-bundler/artifacts.spec.ts +++ b/lib/manager/jsonnet-bundler/artifacts.spec.ts @@ -97,32 +97,36 @@ describe('manager/jsonnet-bundler/artifacts', () => { ).toMatchSnapshot([ { file: { - name: 'jsonnetfile.json', + type: 'addition', + path: 'jsonnetfile.json', contents: 'Updated jsonnetfile.json', }, }, { file: { - name: 'jsonnetfile.lock.json', + type: 'addition', + path: 'jsonnetfile.lock.json', contents: 'Updated jsonnetfile.lock.json', }, }, { file: { - name: 'vendor/foo/main.jsonnet', + type: 'addition', + path: 'vendor/foo/main.jsonnet', contents: 'New foo/main.jsonnet', }, }, { file: { - name: 'vendor/bar/main.jsonnet', + type: 'addition', + path: 'vendor/bar/main.jsonnet', contents: 'New bar/main.jsonnet', }, }, { file: { - name: '|delete|', - contents: 'vendor/baz/deleted.jsonnet', + type: 'deletion', + path: 'vendor/baz/deleted.jsonnet', }, }, ]); @@ -152,7 +156,8 @@ describe('manager/jsonnet-bundler/artifacts', () => { ).toMatchSnapshot([ { file: { - name: 'jsonnetfile.lock.json', + type: 'addition', + path: 'jsonnetfile.lock.json', contents: 'Updated jsonnetfile.lock.json', }, }, diff --git a/lib/manager/jsonnet-bundler/artifacts.ts b/lib/manager/jsonnet-bundler/artifacts.ts index 9e19bc5701683f06640baac1e0f486d861a47b31..258602b1c47a308c39367aef012344037f37b18c 100644 --- a/lib/manager/jsonnet-bundler/artifacts.ts +++ b/lib/manager/jsonnet-bundler/artifacts.ts @@ -70,25 +70,19 @@ export async function updateArtifacts( for (const f of status.modified ?? []) { res.push({ - file: { - name: f, - contents: await readLocalFile(f), - }, + file: { type: 'addition', path: f, contents: await readLocalFile(f) }, }); } for (const f of status.not_added ?? []) { res.push({ - file: { - name: f, - contents: await readLocalFile(f), - }, + file: { type: 'addition', path: f, contents: await readLocalFile(f) }, }); } for (const f of status.deleted ?? []) { res.push({ file: { - name: '|delete|', - contents: f, + type: 'deletion', + path: f, }, }); } diff --git a/lib/manager/mix/__snapshots__/artifacts.spec.ts.snap b/lib/manager/mix/__snapshots__/artifacts.spec.ts.snap index efffd623a01aa112c3c4d9875abbd3eb44487a9f..1c8806335fdb9542ca80f5878e3598b6577427f0 100644 --- a/lib/manager/mix/__snapshots__/artifacts.spec.ts.snap +++ b/lib/manager/mix/__snapshots__/artifacts.spec.ts.snap @@ -5,7 +5,8 @@ Array [ Object { "file": Object { "contents": "New mix.lock", - "name": "mix.lock", + "path": "mix.lock", + "type": "addition", }, }, ] diff --git a/lib/manager/mix/artifacts.spec.ts b/lib/manager/mix/artifacts.spec.ts index fb51593334454bf9f30104492bc222412e8384eb..85914ed9108c01fddfee2fb6570b2a3a0ee5a8b9 100644 --- a/lib/manager/mix/artifacts.spec.ts +++ b/lib/manager/mix/artifacts.spec.ts @@ -94,7 +94,11 @@ describe('manager/mix/artifacts', () => { newPackageFileContent: '{}', config, }) - ).toEqual([{ file: { contents: 'New mix.lock', name: 'mix.lock' } }]); + ).toEqual([ + { + file: { type: 'addition', path: 'mix.lock', contents: 'New mix.lock' }, + }, + ]); expect(execSnapshots).toMatchSnapshot(); }); @@ -129,7 +133,7 @@ describe('manager/mix/artifacts', () => { const [updateResult] = result; expect(updateResult).toEqual({ - file: { contents: 'New mix.lock', name: 'mix.lock' }, + file: { type: 'addition', path: 'mix.lock', contents: 'New mix.lock' }, }); const [, packageUpdateCommand] = execSnapshots; diff --git a/lib/manager/mix/artifacts.ts b/lib/manager/mix/artifacts.ts index b53d712d71091ea4c4d6c992b0242cbddc8ee473..9bae5bf5dcc36af5a431d06b2ddf95f55d13c043 100644 --- a/lib/manager/mix/artifacts.ts +++ b/lib/manager/mix/artifacts.ts @@ -117,7 +117,8 @@ export async function updateArtifacts({ return [ { file: { - name: lockFileName, + type: 'addition', + path: lockFileName, contents: newMixLockContent, }, }, diff --git a/lib/manager/npm/post-update/__snapshots__/index.spec.ts.snap b/lib/manager/npm/post-update/__snapshots__/index.spec.ts.snap index c6c77ac8146dbd8b936283cfa05a2c4bba0fb2cc..99b40d9dbc955c66f844c061b976ab3502b0b02f 100644 --- a/lib/manager/npm/post-update/__snapshots__/index.spec.ts.snap +++ b/lib/manager/npm/post-update/__snapshots__/index.spec.ts.snap @@ -12,17 +12,19 @@ Array [ "contents": "yarnPath: .yarn/releases/yarn-3.0.2.cjs a: b ", - "name": "path/to/lockfile/.yarnrc.yml", + "path": "path/to/lockfile/.yarnrc.yml", + "type": "addition", }, Object { - "contents": "path/to/lockfile/.yarn/releases/yarn-3.0.1.cjs", - "name": "|delete|", + "path": "path/to/lockfile/.yarn/releases/yarn-3.0.1.cjs", + "type": "deletion", }, Object { "contents": "new yarn ", - "executable": true, - "name": "path/to/lockfile/.yarn/releases/yarn-3.0.2.cjs", + "isExecutable": true, + "path": "path/to/lockfile/.yarn/releases/yarn-3.0.2.cjs", + "type": "addition", }, ] `; @@ -33,17 +35,19 @@ Array [ "contents": "yarnPath: .yarn/releases/yarn-3.0.2.cjs a: b ", - "name": "path/to/lockfile/.yarnrc.yml", + "path": "path/to/lockfile/.yarnrc.yml", + "type": "addition", }, Object { - "contents": "path/to/lockfile/.yarn/releases/yarn-3.0.1.cjs", - "name": "|delete|", + "path": "path/to/lockfile/.yarn/releases/yarn-3.0.1.cjs", + "type": "deletion", }, Object { "contents": "new yarn ", - "executable": true, - "name": "path/to/lockfile/.yarn/releases/yarn-3.0.2.cjs", + "isExecutable": true, + "path": "path/to/lockfile/.yarn/releases/yarn-3.0.2.cjs", + "type": "addition", }, ] `; diff --git a/lib/manager/npm/post-update/index.ts b/lib/manager/npm/post-update/index.ts index 260b0c19207431365a3a96e72459f978b7af46bc..bc284614e4192510dd579c950fc82f114985d367 100644 --- a/lib/manager/npm/post-update/index.ts +++ b/lib/manager/npm/post-update/index.ts @@ -23,6 +23,7 @@ import { writeLocalFile, } from '../../../util/fs'; import { branchExists, getFile, getRepoStatus } from '../../../util/git'; +import type { File } from '../../../util/git/types'; import * as hostRules from '../../../util/host-rules'; import { regEx } from '../../../util/regex'; import { ensureTrailingSlash } from '../../../util/url'; @@ -36,7 +37,6 @@ import type { AdditionalPackageFiles, ArtifactError, DetermineLockFileDirsResult, - UpdatedArtifacts, WriteExistingFilesResult, } from './types'; import * as yarn from './yarn'; @@ -101,8 +101,8 @@ export function determineLockFileDirs( } for (const p of config.updatedPackageFiles) { - logger.trace(`Checking ${String(p.name)} for lock files`); - const packageFile = getPackageFile(p.name); + logger.trace(`Checking ${String(p.path)} for lock files`); + const packageFile = getPackageFile(p.path); // lerna first if (packageFile.managerData?.lernaJsonFile && packageFile.npmLock) { logger.debug(`${packageFile.packageFile} has lerna lock file`); @@ -255,20 +255,23 @@ export async function writeUpdatedPackageFiles( const { localDir } = GlobalConfig.get(); const supportedLockFiles = ['package-lock.json']; for (const packageFile of config.updatedPackageFiles) { + if (packageFile.type !== 'addition') { + continue; + } if ( - supportedLockFiles.some((fileName) => packageFile.name.endsWith(fileName)) + supportedLockFiles.some((fileName) => packageFile.path.endsWith(fileName)) ) { - logger.debug(`Writing lock file: ${packageFile.name}`); + logger.debug(`Writing lock file: ${packageFile.path}`); await outputFile( - upath.join(localDir, packageFile.name), + upath.join(localDir, packageFile.path), packageFile.contents ); continue; } - if (!packageFile.name.endsWith('package.json')) { + if (!packageFile.path.endsWith('package.json')) { continue; } - logger.debug(`Writing ${String(packageFile.name)}`); + logger.debug(`Writing ${packageFile.path}`); const detectedIndent = detectIndent(packageFile.contents.toString()).indent || ' '; const massagedFile = JSON.parse(packageFile.contents.toString()); @@ -278,7 +281,7 @@ export async function writeUpdatedPackageFiles( url: 'https://api.github.com/', }); for (const upgrade of config.upgrades) { - if (upgrade.gitRef && upgrade.packageFile === packageFile.name) { + if (upgrade.gitRef && upgrade.packageFile === packageFile.path) { massagedFile[upgrade.depType][upgrade.depName] = massagedFile[ upgrade.depType ][upgrade.depName].replace( @@ -291,7 +294,7 @@ export async function writeUpdatedPackageFiles( logger.warn({ err }, 'Error adding token to package files'); } await outputFile( - upath.join(localDir, packageFile.name), + upath.join(localDir, packageFile.path), JSON.stringify(massagedFile, null, detectedIndent) ); } @@ -358,7 +361,7 @@ async function resetNpmrcContent( async function updateYarnOffline( lockFileDir: string, localDir: string, - updatedArtifacts: UpdatedArtifacts[] + updatedArtifacts: File[] ): Promise<void> { try { const resolvedPaths: string[] = []; @@ -391,17 +394,15 @@ async function updateYarnOffline( if (resolvedPaths.some((p) => f.startsWith(p))) { const localModified = upath.join(localDir, f); updatedArtifacts.push({ - name: f, + type: 'addition', + path: f, contents: await readFile(localModified), }); } } for (const f of status.deleted || []) { if (resolvedPaths.some((p) => f.startsWith(p))) { - updatedArtifacts.push({ - name: '|delete|', - contents: f, - }); + updatedArtifacts.push({ type: 'deletion', path: f }); } } } @@ -413,7 +414,7 @@ async function updateYarnOffline( // exported for testing export async function updateYarnBinary( lockFileDir: string, - updatedArtifacts: UpdatedArtifacts[], + updatedArtifacts: File[], existingYarnrcYmlContent: string | undefined ): Promise<string | undefined> { let yarnrcYml = existingYarnrcYmlContent; @@ -434,17 +435,19 @@ export async function updateYarnBinary( yarnrcYml = yarnrcYml.replace(oldYarnPath, newYarnPath); updatedArtifacts.push( { - name: yarnrcYmlFilename, + type: 'addition', + path: yarnrcYmlFilename, contents: yarnrcYml, }, { - name: '|delete|', - contents: oldYarnFullPath, + type: 'deletion', + path: oldYarnFullPath, }, { - name: newYarnFullPath, + type: 'addition', + path: newYarnFullPath, contents: await readLocalFile(newYarnFullPath, 'utf8'), - executable: true, + isExecutable: true, } ); } catch (err) /* istanbul ignore next */ { @@ -460,7 +463,7 @@ export async function getAdditionalFiles( ): Promise<WriteExistingFilesResult> { logger.trace({ config }, 'getAdditionalFiles'); const artifactErrors: ArtifactError[] = []; - const updatedArtifacts: UpdatedArtifacts[] = []; + const updatedArtifacts: File[] = []; if (!packageFiles.npm?.length) { return { artifactErrors, updatedArtifacts }; } @@ -578,7 +581,8 @@ export async function getAdditionalFiles( } else { logger.debug(`${npmLock} needs updating`); updatedArtifacts.push({ - name: npmLock, + type: 'addition', + path: npmLock, contents: res.lockFile.replace(tokenRe, ''), }); } @@ -666,7 +670,8 @@ export async function getAdditionalFiles( } else { logger.debug('yarn.lock needs updating'); updatedArtifacts.push({ - name: lockFileName, + type: 'addition', + path: lockFileName, contents: res.lockFile, }); await updateYarnOffline(lockFileDir, localDir, updatedArtifacts); @@ -741,7 +746,8 @@ export async function getAdditionalFiles( } else { logger.debug('pnpm-lock.yaml needs updating'); updatedArtifacts.push({ - name: pnpmShrinkwrap, + type: 'addition', + path: pnpmShrinkwrap, contents: res.lockFile, }); } @@ -859,7 +865,8 @@ export async function getAdditionalFiles( } else { logger.debug('File is updated: ' + lockFilePath); updatedArtifacts.push({ - name: filename, + type: 'addition', + path: filename, contents: newContent, }); } diff --git a/lib/manager/npm/post-update/types.ts b/lib/manager/npm/post-update/types.ts index 8b4605f2274cd4a463ed41c93d5ae791cff8093b..af1dd120b2a8d122a11cd7a54b8d0d3e95a45b45 100644 --- a/lib/manager/npm/post-update/types.ts +++ b/lib/manager/npm/post-update/types.ts @@ -1,3 +1,4 @@ +import type { File } from '../../../util/git/types'; import type { PackageFile } from '../../types'; export interface DetermineLockFileDirsResult { @@ -16,15 +17,9 @@ export interface ArtifactError { stderr: string; } -export interface UpdatedArtifacts { - name: string; - contents: string | Buffer; - executable?: boolean; -} - export interface WriteExistingFilesResult { artifactErrors: ArtifactError[]; - updatedArtifacts: UpdatedArtifacts[]; + updatedArtifacts: File[]; } export interface GenerateLockFileResult { diff --git a/lib/manager/nuget/artifacts.ts b/lib/manager/nuget/artifacts.ts index 3ff382af5367054b0700127ef22574d9769c63ab..f245301ea544699e32dea1790e58bcbd72fff30d 100644 --- a/lib/manager/nuget/artifacts.ts +++ b/lib/manager/nuget/artifacts.ts @@ -137,7 +137,8 @@ export async function updateArtifacts({ return [ { file: { - name: lockFileName, + type: 'addition', + path: lockFileName, contents: await readLocalFile(lockFileName), }, }, diff --git a/lib/manager/pip-compile/artifacts.ts b/lib/manager/pip-compile/artifacts.ts index be0762569bb69f1b7b5ded8c301fc6abc8c8234e..dd79a9acd2b47885881f7cf9efb1efbbd449038c 100644 --- a/lib/manager/pip-compile/artifacts.ts +++ b/lib/manager/pip-compile/artifacts.ts @@ -83,7 +83,8 @@ export async function updateArtifacts({ return [ { file: { - name: outputFileName, + type: 'addition', + path: outputFileName, contents: await readLocalFile(outputFileName, 'utf8'), }, }, diff --git a/lib/manager/pip_requirements/artifacts.ts b/lib/manager/pip_requirements/artifacts.ts index d3ca1878f036aef9eac392021bb0222277e09bd9..e7f59f507ea0651e867c3da89a7c7efff98abbbb 100644 --- a/lib/manager/pip_requirements/artifacts.ts +++ b/lib/manager/pip_requirements/artifacts.ts @@ -54,7 +54,8 @@ export async function updateArtifacts({ return [ { file: { - name: packageFileName, + type: 'addition', + path: packageFileName, contents: newContent, }, }, diff --git a/lib/manager/pipenv/artifacts.ts b/lib/manager/pipenv/artifacts.ts index 84ead7814ad26bcccd717485083b409cfa38e4fe..da1712dec9999f72a735d3a781c4c79394a0d4e1 100644 --- a/lib/manager/pipenv/artifacts.ts +++ b/lib/manager/pipenv/artifacts.ts @@ -117,7 +117,8 @@ export async function updateArtifacts({ return [ { file: { - name: lockFileName, + type: 'addition', + path: lockFileName, contents: await readLocalFile(lockFileName, 'utf8'), }, }, diff --git a/lib/manager/poetry/artifacts.ts b/lib/manager/poetry/artifacts.ts index c6817201f48263833bf05392f0952a9f6ad8d2e0..69da0cce0c4cadb5205e6d2a66fa235849776ddb 100644 --- a/lib/manager/poetry/artifacts.ts +++ b/lib/manager/poetry/artifacts.ts @@ -153,7 +153,8 @@ export async function updateArtifacts({ return [ { file: { - name: lockFileName, + type: 'addition', + path: lockFileName, contents: newPoetryLockContent, }, }, diff --git a/lib/manager/terraform/lockfile/__snapshots__/index.spec.ts.snap b/lib/manager/terraform/lockfile/__snapshots__/index.spec.ts.snap index ad42a7720253249453f32987be5c8ac21c1aacd2..d0fea209e84c4f7ffeb271fef21c7a3bcbb23855 100644 --- a/lib/manager/terraform/lockfile/__snapshots__/index.spec.ts.snap +++ b/lib/manager/terraform/lockfile/__snapshots__/index.spec.ts.snap @@ -41,7 +41,8 @@ provider \\"registry.terraform.io/hashicorp/random\\" { ] } ", - "name": ".terraform.lock.hcl", + "path": ".terraform.lock.hcl", + "type": "addition", } `; @@ -101,7 +102,8 @@ provider \\"registry.terraform.io/hashicorp/random\\" { ] } ", - "name": "subfolder/.terraform.lock.hcl", + "path": "subfolder/.terraform.lock.hcl", + "type": "addition", } `; @@ -178,7 +180,8 @@ provider \\"registry.terraform.io/telmate/proxmox\\" { ] } ", - "name": "test/.terraform.lock.hcl", + "path": "test/.terraform.lock.hcl", + "type": "addition", } `; @@ -258,7 +261,8 @@ provider \\"registry.terraform.io/hashicorp/random\\" { ] } ", - "name": "test/.terraform.lock.hcl", + "path": "test/.terraform.lock.hcl", + "type": "addition", } `; @@ -325,7 +329,8 @@ provider \\"registry.terraform.io/hashicorp/random\\" { ] } ", - "name": ".terraform.lock.hcl", + "path": ".terraform.lock.hcl", + "type": "addition", } `; @@ -392,7 +397,8 @@ provider \\"registry.terraform.io/hashicorp/random\\" { ] } ", - "name": ".terraform.lock.hcl", + "path": ".terraform.lock.hcl", + "type": "addition", } `; @@ -457,7 +463,8 @@ provider \\"registry.terraform.io/hashicorp/random\\" { ] } ", - "name": ".terraform.lock.hcl", + "path": ".terraform.lock.hcl", + "type": "addition", } `; @@ -523,7 +530,8 @@ provider \\"registry.terraform.io/hashicorp/random\\" { ] } ", - "name": ".terraform.lock.hcl", + "path": ".terraform.lock.hcl", + "type": "addition", } `; diff --git a/lib/manager/terraform/lockfile/util.ts b/lib/manager/terraform/lockfile/util.ts index 4e257557c32270697dabc6b6a10150f2d0c0a1b4..1121c38a36fb99e48e8deb24981963438b1b9890 100644 --- a/lib/manager/terraform/lockfile/util.ts +++ b/lib/manager/terraform/lockfile/util.ts @@ -211,7 +211,8 @@ export function writeLockUpdates( return { file: { - name: lockFilePath, + type: 'addition', + path: lockFilePath, contents: newContent, }, }; diff --git a/lib/util/git/index.spec.ts b/lib/util/git/index.spec.ts index 259148798dae8ae1fdbb4ed98c9c76fe9a0ffa94..225a00b3fa0dbfe3b63c36054be17143e9d93f79 100644 --- a/lib/util/git/index.spec.ts +++ b/lib/util/git/index.spec.ts @@ -4,6 +4,7 @@ import SimpleGit from 'simple-git/src/git'; import tmp from 'tmp-promise'; import { GlobalConfig } from '../../config/global'; import { CONFIG_VALIDATION } from '../../constants/error-messages'; +import type { File } from './types'; import * as git from '.'; import { setNoVerify } from '.'; @@ -205,8 +206,9 @@ describe('util/git/index', () => { }); describe('getBranchFiles(branchName)', () => { it('detects changed files compared to current base branch', async () => { - const file = { - name: 'some-new-file', + const file: File = { + type: 'addition', + path: 'some-new-file', contents: 'some new-contents', }; await git.commitFiles({ @@ -267,8 +269,9 @@ describe('util/git/index', () => { }); describe('commitFiles({branchName, files, message})', () => { it('creates file', async () => { - const file = { - name: 'some-new-file', + const file: File = { + type: 'addition', + path: 'some-new-file', contents: 'some new-contents', }; const commit = await git.commitFiles({ @@ -279,9 +282,9 @@ describe('util/git/index', () => { expect(commit).not.toBeNull(); }); it('deletes file', async () => { - const file = { - name: '|delete|', - contents: 'file_to_delete', + const file: File = { + type: 'deletion', + path: 'file_to_delete', }; const commit = await git.commitFiles({ branchName: 'renovate/something', @@ -291,13 +294,15 @@ describe('util/git/index', () => { expect(commit).not.toBeNull(); }); it('updates multiple files', async () => { - const files = [ + const files: File[] = [ { - name: 'some-existing-file', + type: 'addition', + path: 'some-existing-file', contents: 'updated content', }, { - name: 'some-other-existing-file', + type: 'addition', + path: 'some-other-existing-file', contents: 'other updated content', }, ]; @@ -309,9 +314,10 @@ describe('util/git/index', () => { expect(commit).not.toBeNull(); }); it('updates git submodules', async () => { - const files = [ + const files: File[] = [ { - name: '.', + type: 'addition', + path: '.', contents: 'some content', }, ]; @@ -323,9 +329,10 @@ describe('util/git/index', () => { expect(commit).toBeNull(); }); it('does not push when no diff', async () => { - const files = [ + const files: File[] = [ { - name: 'future_file', + type: 'addition', + path: 'future_file', contents: 'future', }, ]; @@ -341,9 +348,10 @@ describe('util/git/index', () => { const commitSpy = jest.spyOn(SimpleGit.prototype, 'commit'); const pushSpy = jest.spyOn(SimpleGit.prototype, 'push'); - const files = [ + const files: File[] = [ { - name: 'some-new-file', + type: 'addition', + path: 'some-new-file', contents: 'some new-contents', }, ]; @@ -370,9 +378,10 @@ describe('util/git/index', () => { const commitSpy = jest.spyOn(SimpleGit.prototype, 'commit'); const pushSpy = jest.spyOn(SimpleGit.prototype, 'push'); - const files = [ + const files: File[] = [ { - name: 'some-new-file', + type: 'addition', + path: 'some-new-file', contents: 'some new-contents', }, ]; @@ -400,9 +409,10 @@ describe('util/git/index', () => { const commitSpy = jest.spyOn(SimpleGit.prototype, 'commit'); const pushSpy = jest.spyOn(SimpleGit.prototype, 'push'); - const files = [ + const files: File[] = [ { - name: 'some-new-file', + type: 'addition', + path: 'some-new-file', contents: 'some new-contents', }, ]; @@ -427,10 +437,11 @@ describe('util/git/index', () => { }); it('creates file with the executable bit', async () => { - const file = { - name: 'some-executable', + const file: File = { + type: 'addition', + path: 'some-executable', contents: 'some new-contents', - executable: true, + isExecutable: true, }; const commit = await git.commitFiles({ branchName: 'renovate/past_branch', diff --git a/lib/util/git/index.ts b/lib/util/git/index.ts index 88ea693b8575717dc56b0a13c42cd5d5237340db..d32f98a67f61e3d619e32415d0b576f6cf160150 100644 --- a/lib/util/git/index.ts +++ b/lib/util/git/index.ts @@ -700,10 +700,8 @@ export async function commitFiles({ const addedModifiedFiles: string[] = []; const ignoredFiles: string[] = []; for (const file of files) { - let fileName = file.name; - // istanbul ignore if - if (fileName === '|delete|') { - fileName = file.contents as string; + const fileName = file.path; + if (file.type === 'deletion') { try { await git.rm([fileName]); deletedFiles.push(fileName); @@ -730,7 +728,7 @@ export async function commitFiles({ // some file systems including Windows don't support the mode // so the index should be manually updated after adding the file await fs.outputFile(upath.join(localDir, fileName), contents, { - mode: file.executable ? 0o777 : 0o666, + mode: file.isExecutable ? 0o777 : 0o666, }); } try { @@ -738,7 +736,7 @@ export async function commitFiles({ const addParams = fileName === configFileNames[0] ? ['-f', fileName] : fileName; await git.add(addParams); - if (file.executable) { + if (file.isExecutable) { await git.raw(['update-index', '--chmod=+x', fileName]); } addedModifiedFiles.push(fileName); @@ -751,7 +749,7 @@ export async function commitFiles({ throw err; } logger.debug({ fileName }, 'Cannot commit ignored file'); - ignoredFiles.push(file.name); + ignoredFiles.push(file.path); } } } @@ -830,7 +828,7 @@ export async function commitFiles({ if ( (err.message.includes('remote rejected') || err.message.includes('403')) && - files?.some((file) => file.name?.startsWith('.github/workflows/')) + files?.some((file) => file.path?.startsWith('.github/workflows/')) ) { logger.debug({ err }, 'commitFiles error'); logger.info('Workflows update rejection - aborting branch.'); diff --git a/lib/util/git/types.ts b/lib/util/git/types.ts index edf2902e214fdd0ff656b3e612e28a72779342d6..3c69b556ec270548d0e11e89fd3f3c3ae37d6211 100644 --- a/lib/util/git/types.ts +++ b/lib/util/git/types.ts @@ -30,26 +30,42 @@ export interface LocalConfig extends StorageConfig { gitAuthorEmail?: string; } -/** - * File to commit - */ -export interface File { +export interface FileAddition { + /** + * Addition creates new file or modifies existing one + */ + type: 'addition'; + /** * Relative file path */ - name: string; + path: string; /** - * file contents + * File contents */ contents: string | Buffer; /** - * the executable bit + * The executable bit + */ + isExecutable?: boolean; +} + +export interface FileDeletion { + /** + * Deletion removes the file + */ + type: 'deletion'; + + /** + * Relative file path */ - executable?: boolean; + path: string; } +export type File = FileAddition | FileDeletion; + export type CommitFilesConfig = { branchName: string; files: File[]; diff --git a/lib/workers/branch/__snapshots__/commit.spec.ts.snap b/lib/workers/branch/__snapshots__/commit.spec.ts.snap index a097ea37927e36e629263610ec734d2bc1365f8d..1713c62d56ea8f4f323593e5c96797be8054be48 100644 --- a/lib/workers/branch/__snapshots__/commit.spec.ts.snap +++ b/lib/workers/branch/__snapshots__/commit.spec.ts.snap @@ -8,7 +8,8 @@ Array [ "files": Array [ Object { "contents": "some contents", - "name": "package.json", + "path": "package.json", + "type": "addition", }, ], "force": false, diff --git a/lib/workers/branch/__snapshots__/get-updated.spec.ts.snap b/lib/workers/branch/__snapshots__/get-updated.spec.ts.snap index a54eaec9b806b875882ef3f27526cb3843a4671f..da1db7c719cc5fe35283181d70a8ee5d50d65049 100644 --- a/lib/workers/branch/__snapshots__/get-updated.spec.ts.snap +++ b/lib/workers/branch/__snapshots__/get-updated.spec.ts.snap @@ -8,7 +8,8 @@ Object { "updatedPackageFiles": Array [ Object { "contents": "version: 0.0.2", - "name": "Chart.yaml", + "path": "Chart.yaml", + "type": "addition", }, ], } @@ -22,7 +23,8 @@ Object { "updatedPackageFiles": Array [ Object { "contents": "new version", - "name": "package.json", + "path": "package.json", + "type": "addition", }, ], } @@ -36,7 +38,8 @@ Object { "updatedPackageFiles": Array [ Object { "contents": "updated-file", - "name": "index.html", + "path": "index.html", + "type": "addition", }, ], } @@ -50,7 +53,8 @@ Object { "updatedPackageFiles": Array [ Object { "contents": "updated-file", - "name": "index.html", + "path": "index.html", + "type": "addition", }, ], } @@ -64,7 +68,8 @@ Object { "updatedPackageFiles": Array [ Object { "contents": "some new content", - "name": "package.json", + "path": "package.json", + "type": "addition", }, ], } @@ -78,7 +83,8 @@ Object { "updatedPackageFiles": Array [ Object { "contents": "existing content", - "name": ".gitmodules", + "path": ".gitmodules", + "type": "addition", }, ], } @@ -92,7 +98,8 @@ Object { "updatedPackageFiles": Array [ Object { "contents": "new contents", - "name": "package-lock.json", + "path": "package-lock.json", + "type": "addition", }, ], } @@ -106,7 +113,8 @@ Object { "updatedPackageFiles": Array [ Object { "contents": "new contents", - "name": "package-lock.json", + "path": "package-lock.json", + "type": "addition", }, ], } @@ -125,7 +133,8 @@ Object { "updatedPackageFiles": Array [ Object { "contents": "some new content", - "name": "undefined", + "path": "undefined", + "type": "addition", }, ], } @@ -138,13 +147,15 @@ Object { "updatedArtifacts": Array [ Object { "contents": "some contents", - "name": "composer.json", + "path": "composer.json", + "type": "addition", }, ], "updatedPackageFiles": Array [ Object { "contents": "some new content", - "name": "composer.json", + "path": "composer.json", + "type": "addition", }, ], } @@ -157,7 +168,8 @@ Object { "updatedArtifacts": Array [ Object { "contents": "some contents", - "name": "composer.json", + "path": "composer.json", + "type": "addition", }, ], "updatedPackageFiles": Array [], @@ -185,13 +197,15 @@ Object { "updatedArtifacts": Array [ Object { "contents": "some contents", - "name": "composer.lock", + "path": "composer.lock", + "type": "addition", }, ], "updatedPackageFiles": Array [ Object { "contents": "existing content", - "name": "composer.json", + "path": "composer.json", + "type": "addition", }, ], } @@ -204,13 +218,15 @@ Object { "updatedArtifacts": Array [ Object { "contents": "some contents", - "name": "poetry.lock", + "path": "poetry.lock", + "type": "addition", }, ], "updatedPackageFiles": Array [ Object { "contents": "existing content", - "name": "pyproject.toml", + "path": "pyproject.toml", + "type": "addition", }, ], } diff --git a/lib/workers/branch/commit.spec.ts b/lib/workers/branch/commit.spec.ts index c501a90c29a3a9def973631524194cd9cfd41ae8..b326976ded539ae3db98e6edde55b2f95aea1be6 100644 --- a/lib/workers/branch/commit.spec.ts +++ b/lib/workers/branch/commit.spec.ts @@ -29,7 +29,8 @@ describe('workers/branch/commit', () => { }); it('commits files', async () => { config.updatedPackageFiles.push({ - name: 'package.json', + type: 'addition', + path: 'package.json', contents: 'some contents', }); await commitFilesToBranch(config); @@ -39,7 +40,8 @@ describe('workers/branch/commit', () => { it('dry runs', async () => { GlobalConfig.set({ dryRun: true }); config.updatedPackageFiles.push({ - name: 'package.json', + type: 'addition', + path: 'package.json', contents: 'some contents', }); await commitFilesToBranch(config); diff --git a/lib/workers/branch/commit.ts b/lib/workers/branch/commit.ts index bd201e7ea8ccdd20493308832b6f39d89fffe437..4734ec057ff50968614ac442fb531a1b199696a2 100644 --- a/lib/workers/branch/commit.ts +++ b/lib/workers/branch/commit.ts @@ -13,13 +13,12 @@ export function commitFilesToBranch( let updatedFiles = config.updatedPackageFiles.concat(config.updatedArtifacts); // istanbul ignore if if (is.nonEmptyArray(config.excludeCommitPaths)) { - updatedFiles = updatedFiles.filter((f) => { - const filename = f.name === '|delete|' ? f.contents.toString() : f.name; - const matchesExcludePaths = config.excludeCommitPaths.some((path) => - minimatch(filename, path, { dot: true }) + updatedFiles = updatedFiles.filter(({ path: filePath }) => { + const matchesExcludePaths = config.excludeCommitPaths.some( + (excludedPath) => minimatch(filePath, excludedPath, { dot: true }) ); if (matchesExcludePaths) { - logger.debug(`Excluding ${filename} from commit`); + logger.debug(`Excluding ${filePath} from commit`); return false; } return true; @@ -29,7 +28,7 @@ export function commitFilesToBranch( logger.debug(`No files to commit`); return null; } - const fileLength = [...new Set(updatedFiles.map((file) => file.name))].length; + const fileLength = [...new Set(updatedFiles.map((file) => file.path))].length; logger.debug(`${fileLength} file(s) to commit`); // istanbul ignore if if (GlobalConfig.get('dryRun')) { diff --git a/lib/workers/branch/execute-post-upgrade-commands.ts b/lib/workers/branch/execute-post-upgrade-commands.ts index 8a2fc6d0545e7f2aab8595a083f5d4faf467f298..1c60e4e60294019e0677d43fdf5ce880c3a25eca 100644 --- a/lib/workers/branch/execute-post-upgrade-commands.ts +++ b/lib/workers/branch/execute-post-upgrade-commands.ts @@ -41,14 +41,14 @@ export async function postUpgradeCommandsExecutor( if (is.nonEmptyArray(commands)) { // Persist updated files in file system so any executed commands can see them for (const file of config.updatedPackageFiles.concat(updatedArtifacts)) { - if (file.name !== '|delete|') { + if (file.type === 'addition') { let contents; if (typeof file.contents === 'string') { contents = Buffer.from(file.contents); } else { contents = file.contents; } - await writeLocalFile(file.name, contents); + await writeLocalFile(file.path, contents); } } @@ -106,19 +106,20 @@ export async function postUpgradeCommandsExecutor( ); const existingContent = await readLocalFile(relativePath); const existingUpdatedArtifacts = updatedArtifacts.find( - (ua) => ua.name === relativePath + (ua) => ua.path === relativePath ); - if (existingUpdatedArtifacts) { + if (existingUpdatedArtifacts?.type === 'addition') { existingUpdatedArtifacts.contents = existingContent; } else { updatedArtifacts.push({ - name: relativePath, + type: 'addition', + path: relativePath, contents: existingContent, }); } // If the file is deleted by a previous post-update command, remove the deletion from updatedArtifacts updatedArtifacts = updatedArtifacts.filter( - (ua) => ua.name !== '|delete|' || ua.contents !== relativePath + (ua) => !(ua.type === 'deletion' && ua.path === relativePath) ); } } @@ -132,12 +133,12 @@ export async function postUpgradeCommandsExecutor( 'Post-upgrade file removed' ); updatedArtifacts.push({ - name: '|delete|', - contents: relativePath, + type: 'deletion', + path: relativePath, }); // If the file is created or modified by a previous post-update command, remove the modification from updatedArtifacts updatedArtifacts = updatedArtifacts.filter( - (ua) => ua.name !== relativePath + (ua) => !(ua.type === 'addition' && ua.path === relativePath) ); } } diff --git a/lib/workers/branch/get-updated.spec.ts b/lib/workers/branch/get-updated.spec.ts index 0eb8c312e85f18678f6cc23d1ecf659dc5339808..4889a7ee64025193a6133138e2b715587d4c0fd7 100644 --- a/lib/workers/branch/get-updated.spec.ts +++ b/lib/workers/branch/get-updated.spec.ts @@ -44,7 +44,9 @@ describe('workers/branch/get-updated', () => { autoReplace.doAutoReplace.mockResolvedValueOnce('updated-file'); const res = await getUpdatedPackageFiles(config); expect(res).toMatchSnapshot({ - updatedPackageFiles: [{ name: 'index.html', contents: 'updated-file' }], + updatedPackageFiles: [ + { type: 'addition', path: 'index.html', contents: 'updated-file' }, + ], }); }); it('handles autoreplace branch no update', async () => { @@ -78,7 +80,9 @@ describe('workers/branch/get-updated', () => { autoReplace.doAutoReplace.mockResolvedValueOnce('updated-file'); const res = await getUpdatedPackageFiles(config); expect(res).toMatchSnapshot({ - updatedPackageFiles: [{ contents: 'updated-file', name: 'index.html' }], + updatedPackageFiles: [ + { type: 'addition', path: 'index.html', contents: 'updated-file' }, + ], }); }); it('handles empty', async () => { @@ -107,7 +111,11 @@ describe('workers/branch/get-updated', () => { const res = await getUpdatedPackageFiles(config); expect(res).toMatchSnapshot({ updatedPackageFiles: [ - { name: 'package.json', contents: 'some new content' }, + { + type: 'addition', + path: 'package.json', + contents: 'some new content', + }, ], }); }); @@ -122,7 +130,8 @@ describe('workers/branch/get-updated', () => { composer.updateArtifacts.mockResolvedValueOnce([ { file: { - name: 'composer.json', + type: 'addition', + path: 'composer.json', contents: 'some contents', }, }, @@ -130,10 +139,18 @@ describe('workers/branch/get-updated', () => { const res = await getUpdatedPackageFiles(config); expect(res).toMatchSnapshot({ updatedArtifacts: [ - { name: 'composer.json', contents: 'some contents' }, + { + type: 'addition', + path: 'composer.json', + contents: 'some contents', + }, ], updatedPackageFiles: [ - { name: 'composer.json', contents: 'some new content' }, + { + type: 'addition', + path: 'composer.json', + contents: 'some new content', + }, ], }); }); @@ -145,7 +162,8 @@ describe('workers/branch/get-updated', () => { composer.updateArtifacts.mockResolvedValueOnce([ { file: { - name: 'composer.json', + type: 'addition', + path: 'composer.json', contents: 'some contents', }, }, @@ -153,7 +171,11 @@ describe('workers/branch/get-updated', () => { const res = await getUpdatedPackageFiles(config); expect(res).toMatchSnapshot({ updatedArtifacts: [ - { name: 'composer.json', contents: 'some contents' }, + { + type: 'addition', + path: 'composer.json', + contents: 'some contents', + }, ], }); }); @@ -170,7 +192,11 @@ describe('workers/branch/get-updated', () => { const res = await getUpdatedPackageFiles(config); expect(res).toMatchSnapshot({ updatedPackageFiles: [ - { name: 'package-lock.json', contents: 'new contents' }, + { + type: 'addition', + path: 'package-lock.json', + contents: 'new contents', + }, ], }); }); @@ -188,7 +214,11 @@ describe('workers/branch/get-updated', () => { const res = await getUpdatedPackageFiles(config); expect(res).toMatchSnapshot({ updatedPackageFiles: [ - { name: 'package-lock.json', contents: 'new contents' }, + { + type: 'addition', + path: 'package-lock.json', + contents: 'new contents', + }, ], }); }); @@ -240,7 +270,11 @@ describe('workers/branch/get-updated', () => { const res = await getUpdatedPackageFiles(config); expect(res).toMatchSnapshot({ updatedPackageFiles: [ - { name: '.gitmodules', contents: 'existing content' }, + { + type: 'addition', + path: '.gitmodules', + contents: 'existing content', + }, ], }); }); @@ -257,7 +291,8 @@ describe('workers/branch/get-updated', () => { composer.updateArtifacts.mockResolvedValueOnce([ { file: { - name: 'composer.lock', + type: 'addition', + path: 'composer.lock', contents: 'some contents', }, }, @@ -265,10 +300,18 @@ describe('workers/branch/get-updated', () => { const res = await getUpdatedPackageFiles(config); expect(res).toMatchSnapshot({ updatedArtifacts: [ - { name: 'composer.lock', contents: 'some contents' }, + { + type: 'addition', + path: 'composer.lock', + contents: 'some contents', + }, ], updatedPackageFiles: [ - { name: 'composer.json', contents: 'existing content' }, + { + type: 'addition', + path: 'composer.json', + contents: 'existing content', + }, ], }); }); @@ -282,16 +325,23 @@ describe('workers/branch/get-updated', () => { poetry.updateArtifacts.mockResolvedValueOnce([ { file: { - name: 'poetry.lock', + type: 'addition', + path: 'poetry.lock', contents: 'some contents', }, }, ]); const res = await getUpdatedPackageFiles(config); expect(res).toMatchSnapshot({ - updatedArtifacts: [{ name: 'poetry.lock', contents: 'some contents' }], + updatedArtifacts: [ + { type: 'addition', path: 'poetry.lock', contents: 'some contents' }, + ], updatedPackageFiles: [ - { name: 'pyproject.toml', contents: 'existing content' }, + { + type: 'addition', + path: 'pyproject.toml', + contents: 'existing content', + }, ], }); }); @@ -375,7 +425,8 @@ describe('workers/branch/get-updated', () => { expect(res).toMatchSnapshot({ updatedPackageFiles: [ { - name: 'package.json', + type: 'addition', + path: 'package.json', contents: 'new version', }, ], @@ -396,8 +447,9 @@ describe('workers/branch/get-updated', () => { expect(res).toMatchSnapshot({ updatedPackageFiles: [ { + type: 'addition', + path: 'Chart.yaml', contents: 'version: 0.0.2', - name: 'Chart.yaml', }, ], }); diff --git a/lib/workers/branch/get-updated.ts b/lib/workers/branch/get-updated.ts index f5855407afc7ac58c80820da72aca43cadd1fd48..884aa542cebb1161eb54b4275839f651c2b5bcab 100644 --- a/lib/workers/branch/get-updated.ts +++ b/lib/workers/branch/get-updated.ts @@ -4,7 +4,7 @@ import { logger } from '../../logger'; import { get } from '../../manager'; import type { ArtifactError, PackageDependency } from '../../manager/types'; import { getFile } from '../../util/git'; -import { File } from '../../util/git/types'; +import type { File, FileAddition } from '../../util/git/types'; import type { BranchConfig } from '../types'; import { doAutoReplace } from './auto-replace'; @@ -213,21 +213,24 @@ export async function getUpdatedPackageFiles( } } } - const updatedPackageFiles = Object.keys(updatedFileContents).map((name) => ({ - name, + const updatedPackageFiles: FileAddition[] = Object.keys( + updatedFileContents + ).map((name) => ({ + type: 'addition', + path: name, contents: updatedFileContents[name], })); const updatedArtifacts: File[] = []; const artifactErrors: ArtifactError[] = []; for (const packageFile of updatedPackageFiles) { - const manager = packageFileManagers[packageFile.name]; - const updatedDeps = packageFileUpdatedDeps[packageFile.name]; + const manager = packageFileManagers[packageFile.path]; + const updatedDeps = packageFileUpdatedDeps[packageFile.path]; const updateArtifacts = get(manager, 'updateArtifacts'); if (updateArtifacts) { const results = await updateArtifacts({ - packageFileName: packageFile.name, + packageFileName: packageFile.path, updatedDeps, - newPackageFileContent: packageFile.contents, + newPackageFileContent: packageFile.contents.toString(), config, }); if (is.nonEmptyArray(results)) { @@ -242,21 +245,22 @@ export async function getUpdatedPackageFiles( } } } - const nonUpdatedPackageFiles = Object.keys(nonUpdatedFileContents).map( - (name) => ({ - name, - contents: nonUpdatedFileContents[name], - }) - ); + const nonUpdatedPackageFiles: FileAddition[] = Object.keys( + nonUpdatedFileContents + ).map((name) => ({ + type: 'addition', + path: name, + contents: nonUpdatedFileContents[name], + })); for (const packageFile of nonUpdatedPackageFiles) { - const manager = packageFileManagers[packageFile.name]; - const updatedDeps = packageFileUpdatedDeps[packageFile.name]; + const manager = packageFileManagers[packageFile.path]; + const updatedDeps = packageFileUpdatedDeps[packageFile.path]; const updateArtifacts = get(manager, 'updateArtifacts'); if (updateArtifacts) { const results = await updateArtifacts({ - packageFileName: packageFile.name, + packageFileName: packageFile.path, updatedDeps, - newPackageFileContent: packageFile.contents, + newPackageFileContent: packageFile.contents.toString(), config, }); if (is.nonEmptyArray(results)) { diff --git a/lib/workers/branch/index.spec.ts b/lib/workers/branch/index.spec.ts index 0f7878fe8b91222ab2f5a2530cb07c9f74573b37..c7615c389850d900c6ff03da101af57c01801ba4 100644 --- a/lib/workers/branch/index.spec.ts +++ b/lib/workers/branch/index.spec.ts @@ -62,6 +62,14 @@ const limits = mocked(_limits); const adminConfig: RepoGlobalConfig = { localDir: '', cacheDir: '' }; +function findFileContent(files: File[], path: string): string | null { + const f = files.find((file) => file.path === path); + if (f.type === 'addition') { + return f.contents.toString(); + } + return null; +} + describe('workers/branch/index', () => { describe('processBranch', () => { const updatedPackageFiles: PackageFilesResult = { @@ -856,7 +864,7 @@ describe('workers/branch/index', () => { ...config, updateType: 'lockFileMaintenance', reuseExistingBranch: false, - updatedArtifacts: [{ name: '|delete|', contents: 'dummy' }], + updatedArtifacts: [{ type: 'deletion', path: 'dummy' }], }) ).toEqual({ branchExists: true, @@ -922,7 +930,7 @@ describe('workers/branch/index', () => { ...config, updateType: 'lockFileMaintenance', reuseExistingBranch: false, - updatedArtifacts: [{ name: '|delete|', contents: 'dummy' }], + updatedArtifacts: [{ type: 'deletion', path: 'dummy' }], }) ).toEqual({ branchExists: true, @@ -933,7 +941,8 @@ describe('workers/branch/index', () => { it('executes post-upgrade tasks if trust is high', async () => { const updatedPackageFile: File = { - name: 'pom.xml', + type: 'addition', + path: 'pom.xml', contents: 'pom.xml file contents', }; getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({ @@ -944,7 +953,8 @@ describe('workers/branch/index', () => { artifactErrors: [], updatedArtifacts: [ { - name: 'yarn.lock', + type: 'addition', + path: 'yarn.lock', contents: Buffer.from([1, 2, 3]) /* Binary content */, }, ], @@ -1014,7 +1024,8 @@ describe('workers/branch/index', () => { it('handles post-upgrade task exec errors', async () => { const updatedPackageFile: File = { - name: 'pom.xml', + type: 'addition', + path: 'pom.xml', contents: 'pom.xml file contents', }; getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({ @@ -1084,7 +1095,8 @@ describe('workers/branch/index', () => { it('executes post-upgrade tasks with disabled post-upgrade command templating', async () => { const updatedPackageFile: File = { - name: 'pom.xml', + type: 'addition', + path: 'pom.xml', contents: 'pom.xml file contents', }; getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({ @@ -1095,7 +1107,8 @@ describe('workers/branch/index', () => { artifactErrors: [], updatedArtifacts: [ { - name: 'yarn.lock', + type: 'addition', + path: 'yarn.lock', contents: Buffer.from([1, 2, 3]) /* Binary content */, }, ], @@ -1157,7 +1170,8 @@ describe('workers/branch/index', () => { it('executes post-upgrade tasks with multiple dependecy in one branch', async () => { const updatedPackageFile: File = { - name: 'pom.xml', + type: 'addition', + path: 'pom.xml', contents: 'pom.xml file contents', }; getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({ @@ -1168,7 +1182,8 @@ describe('workers/branch/index', () => { artifactErrors: [], updatedArtifacts: [ { - name: 'yarn.lock', + type: 'addition', + path: 'yarn.lock', contents: Buffer.from([1, 2, 3]) /* Binary content */, }, ], @@ -1268,42 +1283,37 @@ describe('workers/branch/index', () => { cwd: '/localDir', }); expect(exec.exec).toHaveBeenCalledTimes(2); + const calledWithConfig = commit.commitFilesToBranch.mock.calls[0][0]; + const updatedArtifacts = calledWithConfig.updatedArtifacts; + expect(findFileContent(updatedArtifacts, 'modified_file')).toBe( + 'modified file content again' + ); expect( - ( - commit.commitFilesToBranch.mock.calls[0][0].updatedArtifacts.find( - (f) => f.name === 'modified_file' - ).contents as Buffer - ).toString() - ).toBe('modified file content again'); - expect( - ( - commit.commitFilesToBranch.mock.calls[0][0].updatedArtifacts.find( - (f) => f.name === 'deleted_then_created_file' - ).contents as Buffer - ).toString() + findFileContent(updatedArtifacts, 'deleted_then_created_file') ).toBe('this file was once deleted'); expect( - commit.commitFilesToBranch.mock.calls[0][0].updatedArtifacts.find( - (f) => - f.contents === 'deleted_then_created_file' && f.name === '|delete|' + updatedArtifacts.find( + (f) => f.type === 'deletion' && f.path === 'deleted_then_created_file' ) ).toBeUndefined(); expect( - commit.commitFilesToBranch.mock.calls[0][0].updatedArtifacts.find( - (f) => f.name === 'modified_then_deleted_file' + updatedArtifacts.find( + (f) => + f.type === 'addition' && f.path === 'modified_then_deleted_file' ) ).toBeUndefined(); expect( - commit.commitFilesToBranch.mock.calls[0][0].updatedArtifacts.find( + updatedArtifacts.find( (f) => - f.contents === 'modified_then_deleted_file' && f.name === '|delete|' + f.type === 'deletion' && f.path === 'modified_then_deleted_file' ) ).toBeDefined(); }); it('executes post-upgrade tasks once when set to branch mode', async () => { const updatedPackageFile: File = { - name: 'pom.xml', + type: 'addition', + path: 'pom.xml', contents: 'pom.xml file contents', }; getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({ @@ -1314,7 +1324,8 @@ describe('workers/branch/index', () => { artifactErrors: [], updatedArtifacts: [ { - name: 'yarn.lock', + type: 'addition', + path: 'yarn.lock', contents: Buffer.from([1, 2, 3]) /* Binary content */, }, ], @@ -1403,11 +1414,10 @@ describe('workers/branch/index', () => { }); expect(exec.exec).toHaveBeenCalledTimes(1); expect( - ( - commit.commitFilesToBranch.mock.calls[0][0].updatedArtifacts.find( - (f) => f.name === 'modified_file' - ).contents as Buffer - ).toString() + findFileContent( + commit.commitFilesToBranch.mock.calls[0][0].updatedArtifacts, + 'modified_file' + ) ).toBe('modified file content'); }); it('returns when rebaseWhen=never', async () => { diff --git a/lib/workers/branch/index.ts b/lib/workers/branch/index.ts index 46cc828e91d558c232e38c1fed70bea245eff731..11d79a3449b4dbc0872c2177ba0e12d519f31f72 100644 --- a/lib/workers/branch/index.ts +++ b/lib/workers/branch/index.ts @@ -384,7 +384,7 @@ export async function processBranch( logger.debug( { updatedArtifacts: config.updatedArtifacts.map((f) => - f.name === '|delete|' ? `${String(f.contents)} (delete)` : f.name + f.type === 'deletion' ? `${f.path} (delete)` : f.path ), }, `Updated ${config.updatedArtifacts.length} lock files` diff --git a/lib/workers/branch/lock-files/index.spec.ts b/lib/workers/branch/lock-files/index.spec.ts index 6adeb1205d2f0fff7d0091408d9e4687b16d1af5..38ff28b04575f5d7675683f919ef171f9dfcdacf 100644 --- a/lib/workers/branch/lock-files/index.spec.ts +++ b/lib/workers/branch/lock-files/index.spec.ts @@ -44,7 +44,8 @@ describe('workers/branch/lock-files/index', () => { it('returns if no updated packageFiles are package.json', async () => { config.updatedPackageFiles = [ { - name: 'Dockerfile', + type: 'addition', + path: 'Dockerfile', contents: 'some-contents', }, ]; @@ -54,14 +55,20 @@ describe('workers/branch/lock-files/index', () => { it('writes updated packageFiles', async () => { config.updatedPackageFiles = [ { - name: 'package.json', + type: 'addition', + path: 'package.json', contents: '{ "name": "{{some-template}}" }', }, { - name: 'backend/package.json', + type: 'addition', + path: 'backend/package.json', contents: '{ "name": "some-other-name", "engines": { "node": "^6.0.0" }}', }, + { + type: 'deletion', + path: 'frontent/package.json', + }, ]; config.upgrades = []; await writeUpdatedPackageFiles(config); diff --git a/lib/workers/repository/onboarding/branch/create.spec.ts b/lib/workers/repository/onboarding/branch/create.spec.ts index 342ed1a987b98859251a65858ca13cd9ea378863..05869658ab515dc55c8cc7259e43e41b368b4a66 100644 --- a/lib/workers/repository/onboarding/branch/create.spec.ts +++ b/lib/workers/repository/onboarding/branch/create.spec.ts @@ -18,7 +18,8 @@ const buildExpectedCommitFilesArgument = ( branchName: 'renovate/configure', files: [ { - name: filename, + type: 'addition', + path: filename, contents: '{"foo":"bar"}', }, ], diff --git a/lib/workers/repository/onboarding/branch/create.ts b/lib/workers/repository/onboarding/branch/create.ts index 5b9bf89d242e2318ae825d412e63338476c26a3c..73526db1e89fb0f0261bb17502dd255221db2e43 100644 --- a/lib/workers/repository/onboarding/branch/create.ts +++ b/lib/workers/repository/onboarding/branch/create.ts @@ -34,7 +34,8 @@ export async function createOnboardingBranch( branchName: config.onboardingBranch, files: [ { - name: configFile, + type: 'addition', + path: configFile, contents, }, ], diff --git a/lib/workers/repository/onboarding/branch/index.spec.ts b/lib/workers/repository/onboarding/branch/index.spec.ts index 233f9f69848662cb7d53734843cc04d5458542b0..8fa2d0be65aa1ca25db985b2fe0f43b5586f6e51 100644 --- a/lib/workers/repository/onboarding/branch/index.spec.ts +++ b/lib/workers/repository/onboarding/branch/index.spec.ts @@ -15,6 +15,7 @@ import { import { Pr } from '../../../../platform'; import { PrState } from '../../../../types'; import * as _cache from '../../../../util/cache/repository'; +import type { FileAddition } from '../../../../util/git/types'; import * as _config from './config'; import * as _rebase from './rebase'; import { checkOnboardingBranch } from '.'; @@ -71,8 +72,8 @@ describe('workers/repository/onboarding/branch/index', () => { git.getFileList.mockResolvedValue(['package.json']); fs.readLocalFile.mockResolvedValue('{}'); await checkOnboardingBranch(config); - const contents = - git.commitFiles.mock.calls[0][0].files[0].contents?.toString(); + const file = git.commitFiles.mock.calls[0][0].files[0] as FileAddition; + const contents = file.contents.toString(); expect(contents).toBeJsonString(); expect(JSON.parse(contents)).toEqual({ $schema: 'https://docs.renovatebot.com/renovate-schema.json', @@ -100,8 +101,8 @@ describe('workers/repository/onboarding/branch/index', () => { }, configFileNames[0] ); - const contents = - git.commitFiles.mock.calls[0][0].files[0].contents?.toString(); + const file = git.commitFiles.mock.calls[0][0].files[0] as FileAddition; + const contents = file.contents.toString(); expect(contents).toBeJsonString(); expect(JSON.parse(contents)).toEqual({ $schema: 'https://docs.renovatebot.com/renovate-schema.json', diff --git a/lib/workers/repository/onboarding/branch/rebase.spec.ts b/lib/workers/repository/onboarding/branch/rebase.spec.ts index 23857990739529ee353bd849481990cc2710c9c4..fb31bdbe915e7b6962c6ae25e4cb7011f625812a 100644 --- a/lib/workers/repository/onboarding/branch/rebase.spec.ts +++ b/lib/workers/repository/onboarding/branch/rebase.spec.ts @@ -49,7 +49,7 @@ describe('workers/repository/onboarding/branch/rebase', () => { expect(git.commitFiles.mock.calls[0][0].message).toContain( '.github/renovate.json' ); - expect(git.commitFiles.mock.calls[0][0].files[0].name).toBe( + expect(git.commitFiles.mock.calls[0][0].files[0].path).toBe( '.github/renovate.json' ); }); @@ -63,7 +63,7 @@ describe('workers/repository/onboarding/branch/rebase', () => { expect(git.commitFiles.mock.calls[0][0].message).toContain( 'renovate.json' ); - expect(git.commitFiles.mock.calls[0][0].files[0].name).toBe( + expect(git.commitFiles.mock.calls[0][0].files[0].path).toBe( 'renovate.json' ); }); diff --git a/lib/workers/repository/onboarding/branch/rebase.ts b/lib/workers/repository/onboarding/branch/rebase.ts index a49c4eafd4446d0d3cfb61032d0f8b77633fab27..7a145e3f873a769b8d5fbad1c99919694e9896fd 100644 --- a/lib/workers/repository/onboarding/branch/rebase.ts +++ b/lib/workers/repository/onboarding/branch/rebase.ts @@ -51,7 +51,8 @@ export async function rebaseOnboardingBranch( branchName: config.onboardingBranch, files: [ { - name: configFile, + type: 'addition', + path: configFile, contents, }, ],