From 0cc622a863ae006c1a0008c5361133aef4a72b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Rodr=C3=ADguez=20Mor=C3=A9?= Date: Thu, 1 Feb 2024 09:41:15 +0100 Subject: [PATCH] fix: making compatible linked-versions + includeComponentInTag=false \n\n Continues this: https://github.com/googleapis/release-please/pull/1749 --- __snapshots__/manifest.js | 4 +- src/manifest.ts | 12 ++++- src/strategies/base.ts | 3 -- test/fixtures/release-notes/grouped.txt | 2 +- .../mixed-componentless-manifest.txt | 2 +- test/manifest.ts | 48 +++++++++---------- test/util/pull-request-body.ts | 4 +- 7 files changed, 41 insertions(+), 34 deletions(-) diff --git a/__snapshots__/manifest.js b/__snapshots__/manifest.js index 2e175987c..ee0e36655 100644 --- a/__snapshots__/manifest.js +++ b/__snapshots__/manifest.js @@ -93,9 +93,9 @@ exports['Manifest buildPullRequests should handle mixing componentless configs 1 --- -
1.0.1 +
pkg1: 1.0.1 -## [1.0.1](https://github.com/fake-owner/fake-repo/compare/v1.0.0...v1.0.1) (1983-10-10) +## [1.0.1](https://github.com/fake-owner/fake-repo/compare/pkg1-v1.0.0...v1.0.1) (1983-10-10) ### Bug Fixes diff --git a/src/manifest.ts b/src/manifest.ts index e41847a2b..773cf8081 100644 --- a/src/manifest.ts +++ b/src/manifest.ts @@ -501,7 +501,8 @@ export class Manifest { */ async buildPullRequests(): Promise { this.logger.info('Building pull requests'); - const pathsByComponent = await this.getPathsByComponent(); + const pathsByComponent = + (await this.getPathsByComponent()) || this.getComponentlessPackage(); const strategiesByPath = await this.getStrategiesByPath(); // Collect all the SHAs of the latest release packages @@ -797,6 +798,15 @@ export class Manifest { ); } + private getComponentlessPackage(): string { + for (const path in this.repositoryConfig) { + if (!this.repositoryConfig[path].includeComponentInTag) { + return path; + } + } + return ''; + } + private async backfillReleasesFromTags( missingPaths: string[], strategiesByPath: Record diff --git a/src/strategies/base.ts b/src/strategies/base.ts index d0e766ed0..02de0ce41 100644 --- a/src/strategies/base.ts +++ b/src/strategies/base.ts @@ -160,9 +160,6 @@ export abstract class BaseStrategy implements Strategy { * @returns {string} */ async getComponent(): Promise { - if (!this.includeComponentInTag) { - return ''; - } return this.component || (await this.getDefaultComponent()); } diff --git a/test/fixtures/release-notes/grouped.txt b/test/fixtures/release-notes/grouped.txt index 2b1aa21a0..0d8a5ade4 100644 --- a/test/fixtures/release-notes/grouped.txt +++ b/test/fixtures/release-notes/grouped.txt @@ -2,7 +2,7 @@ --- -
1.0.1 +
base: 1.0.1 ## [1.0.1](https://github.com/testOwner/testRepo/compare/v1.0.0...v1.0.1) (2022-07-16) diff --git a/test/fixtures/release-notes/mixed-componentless-manifest.txt b/test/fixtures/release-notes/mixed-componentless-manifest.txt index d47aed238..fa42e2486 100644 --- a/test/fixtures/release-notes/mixed-componentless-manifest.txt +++ b/test/fixtures/release-notes/mixed-componentless-manifest.txt @@ -1,6 +1,6 @@ :robot: I have created a release \*beep\* \*boop\* --- -
3.2.0 +
@google-automation/bot-config-utils: 3.2.0 ### Features diff --git a/test/manifest.ts b/test/manifest.ts index 31beb2880..b2872b23c 100644 --- a/test/manifest.ts +++ b/test/manifest.ts @@ -3152,6 +3152,12 @@ describe('Manifest', () => { }, }, ]); + mockTags(sandbox, github, [ + { + name: 'pkg1-v1.0.0', + sha: 'abc123', + }, + ]); const manifest = new Manifest( github, 'main', @@ -5228,47 +5234,39 @@ describe('Manifest', () => { } ); const releases = await manifest.buildReleases(); - expect(releases).lengthOf(5); - // 3.3.0 - expect(releases[0].tag.toString()).to.eql('v3.3.0'); + expect(releases).lengthOf(4); + // @google-automations/bot-config-utils: 3.2.0 + expect(releases[0].tag.toString()).to.eql('bot-config-utils-v3.2.0'); expect(releases[0].sha).to.eql('abc123'); expect(releases[0].notes) .to.be.a('string') .and.satisfy((msg: string) => msg.startsWith('### Features')); - expect(releases[0].path).to.eql('.'); - expect(releases[0].name).to.eql('v3.3.0'); - // @google-automations/bot-config-utils: 3.2.0 - expect(releases[1].tag.toString()).to.eql('bot-config-utils-v3.2.0'); + expect(releases[0].path).to.eql('packages/bot-config-utils'); + expect(releases[0].name).to.eql('bot-config-utils: v3.2.0'); + // @google-automations/label-utils: 1.1.0 + expect(releases[1].tag.toString()).to.eql('label-utils-v1.1.0'); expect(releases[1].sha).to.eql('abc123'); expect(releases[1].notes) .to.be.a('string') .and.satisfy((msg: string) => msg.startsWith('### Features')); - expect(releases[1].path).to.eql('packages/bot-config-utils'); - expect(releases[1].name).to.eql('bot-config-utils: v3.2.0'); - // @google-automations/label-utils: 1.1.0 - expect(releases[2].tag.toString()).to.eql('label-utils-v1.1.0'); + expect(releases[1].path).to.eql('packages/label-utils'); + expect(releases[1].name).to.eql('label-utils: v1.1.0'); + // @google-automations/object-selector: 1.1.0 + expect(releases[2].tag.toString()).to.eql('object-selector-v1.1.0'); expect(releases[2].sha).to.eql('abc123'); expect(releases[2].notes) .to.be.a('string') .and.satisfy((msg: string) => msg.startsWith('### Features')); - expect(releases[2].path).to.eql('packages/label-utils'); - expect(releases[2].name).to.eql('label-utils: v1.1.0'); - // @google-automations/object-selector: 1.1.0 - expect(releases[3].tag.toString()).to.eql('object-selector-v1.1.0'); + expect(releases[2].path).to.eql('packages/object-selector'); + expect(releases[2].name).to.eql('object-selector: v1.1.0'); + // @google-automations/datastore-lock: 2.1.0 + expect(releases[3].tag.toString()).to.eql('datastore-lock-v2.1.0'); expect(releases[3].sha).to.eql('abc123'); expect(releases[3].notes) .to.be.a('string') .and.satisfy((msg: string) => msg.startsWith('### Features')); - expect(releases[3].path).to.eql('packages/object-selector'); - expect(releases[3].name).to.eql('object-selector: v1.1.0'); - // @google-automations/datastore-lock: 2.1.0 - expect(releases[4].tag.toString()).to.eql('datastore-lock-v2.1.0'); - expect(releases[4].sha).to.eql('abc123'); - expect(releases[4].notes) - .to.be.a('string') - .and.satisfy((msg: string) => msg.startsWith('### Features')); - expect(releases[4].path).to.eql('packages/datastore-lock'); - expect(releases[4].name).to.eql('datastore-lock: v2.1.0'); + expect(releases[3].path).to.eql('packages/datastore-lock'); + expect(releases[3].name).to.eql('datastore-lock: v2.1.0'); }); it('should skip component releases for non-component configs', async () => { diff --git a/test/util/pull-request-body.ts b/test/util/pull-request-body.ts index 1f1e92309..c7702a384 100644 --- a/test/util/pull-request-body.ts +++ b/test/util/pull-request-body.ts @@ -63,7 +63,9 @@ describe('PullRequestBody', () => { expect(pullRequestBody).to.not.be.undefined; const releaseData = pullRequestBody!.releaseData; expect(releaseData).lengthOf(2); - expect(releaseData[0].component).to.be.undefined; + expect(releaseData[0].component).to.eq( + '@google-automation/bot-config-utils' + ); expect(releaseData[0].version?.toString()).to.eql('3.2.0'); expect(releaseData[0].notes).matches(/^### Features/); expect(releaseData[1].component).to.eql(