From e062dc1b73b336b021f62971c50917d6ca4c266b Mon Sep 17 00:00:00 2001 From: Joe Wang <106995533+JoeWang1127@users.noreply.github.com> Date: Tue, 8 Oct 2024 15:01:07 +0000 Subject: [PATCH] fix(java-yoshi): match full artifact id when updating versions (#2398) * fix: match full artifact id when updating versions * add unit tests * lint * fix unit test * lint * restore package * restore package * add unit test --- __snapshots__/version-manifest.js | 16 ++++++++++ src/updaters/java/versions-manifest.ts | 4 +-- .../versions-suffix-with-snapshot.txt | 5 +++ .../versions-suffix-without-snapshot.txt | 5 +++ test/updaters/version-manifest.ts | 32 +++++++++++++++++++ 5 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 test/updaters/fixtures/versions-suffix-with-snapshot.txt create mode 100644 test/updaters/fixtures/versions-suffix-without-snapshot.txt diff --git a/__snapshots__/version-manifest.js b/__snapshots__/version-manifest.js index 7e9d4a90d..a73465abd 100644 --- a/__snapshots__/version-manifest.js +++ b/__snapshots__/version-manifest.js @@ -1,3 +1,19 @@ +exports['VersionManifest updateContent updates versions.txt with an artifact id is another ones suffix with snapshot 1'] = ` +# Format: +# module:released-version:current-version + +google-cloud-admin:2.3.4:2.3.4 +admin:3.4.5:3.4.5 +` + +exports['VersionManifest updateContent updates versions.txt with an artifact id is another ones suffix without snapshot 1'] = ` +# Format: +# module:released-version:current-version + +google-cloud-admin:2.3.6:2.3.6 +admin:3.4.3:3.4.3 +` + exports['VersionManifest updateContent updates versions.txt with snapshot released version 1'] = ` # Format: # module:released-version:current-version diff --git a/src/updaters/java/versions-manifest.ts b/src/updaters/java/versions-manifest.ts index a38161a9b..d14c951d8 100644 --- a/src/updaters/java/versions-manifest.ts +++ b/src/updaters/java/versions-manifest.ts @@ -52,14 +52,14 @@ export class VersionsManifest extends JavaUpdate { if (version.includes('SNAPSHOT')) { newLines.push( line.replace( - new RegExp(`${packageName}:(.*):(.*)`, 'g'), + new RegExp(`^${packageName}:(.*):(.*)`, 'g'), `${packageName}:$1:${version}` ) ); } else { newLines.push( line.replace( - new RegExp(`${packageName}:(.*):(.*)`, 'g'), + new RegExp(`^${packageName}:(.*):(.*)`, 'g'), `${packageName}:${version}:${version}` ) ); diff --git a/test/updaters/fixtures/versions-suffix-with-snapshot.txt b/test/updaters/fixtures/versions-suffix-with-snapshot.txt new file mode 100644 index 000000000..fbf670fd5 --- /dev/null +++ b/test/updaters/fixtures/versions-suffix-with-snapshot.txt @@ -0,0 +1,5 @@ +# Format: +# module:released-version:current-version + +google-cloud-admin:2.3.5:2.3.5 +admin:3.4.2:3.4.2 \ No newline at end of file diff --git a/test/updaters/fixtures/versions-suffix-without-snapshot.txt b/test/updaters/fixtures/versions-suffix-without-snapshot.txt new file mode 100644 index 000000000..bff26116d --- /dev/null +++ b/test/updaters/fixtures/versions-suffix-without-snapshot.txt @@ -0,0 +1,5 @@ +# Format: +# module:released-version:current-version + +google-cloud-admin:2.3.0:2.3.1-SNAPSHOT +admin:3.4.0:3.4.1-SNAPSHOT \ No newline at end of file diff --git a/test/updaters/version-manifest.ts b/test/updaters/version-manifest.ts index 700c44852..7e170f46b 100644 --- a/test/updaters/version-manifest.ts +++ b/test/updaters/version-manifest.ts @@ -82,5 +82,37 @@ describe('VersionManifest', () => { const newContent = javaAuthVersions.updateContent(oldContent); snapshot(newContent); }); + + it('updates versions.txt with an artifact id is another ones suffix with snapshot', async () => { + const oldContent = readFileSync( + resolve(fixturesPath, './versions-suffix-with-snapshot.txt'), + 'utf8' + ).replace(/\r\n/g, '\n'); + const versions = new Map(); + versions.set('google-cloud-admin', Version.parse('2.3.4')); + versions.set('admin', Version.parse('3.4.5')); + const javaAuthVersions = new VersionsManifest({ + versionsMap: versions, + version: Version.parse('1.2.3'), + }); + const newContent = javaAuthVersions.updateContent(oldContent); + snapshot(newContent); + }); + + it('updates versions.txt with an artifact id is another ones suffix without snapshot', async () => { + const oldContent = readFileSync( + resolve(fixturesPath, './versions-suffix-without-snapshot.txt'), + 'utf8' + ).replace(/\r\n/g, '\n'); + const versions = new Map(); + versions.set('google-cloud-admin', Version.parse('2.3.6')); + versions.set('admin', Version.parse('3.4.3')); + const javaAuthVersions = new VersionsManifest({ + versionsMap: versions, + version: Version.parse('1.2.3'), + }); + const newContent = javaAuthVersions.updateContent(oldContent); + snapshot(newContent); + }); }); });