Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: releasable units should use version from pull-request body (fixes #2101) #2102

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/strategies/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,15 @@ export abstract class BaseStrategy implements Strategy {
if (notes === undefined) {
this.logger.warn('Failed to find release notes');
}
const version = pullRequestTitle.getVersion() || releaseData?.version;

let version: Version | undefined = pullRequestTitle.getVersion();
if (
!version ||
(pullRequestBody.releaseData.length > 1 && releaseData?.version)
) {
// prioritize pull-request body version for multi-component releases
version = releaseData?.version;
}
if (!version) {
this.logger.error('Pull request should have included version');
return;
Expand Down
44 changes: 44 additions & 0 deletions test/fixtures/release-notes/multiple-with-root.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
:robot: I have created a release \*beep\* \*boop\*
---
<details><summary>3.3.0</summary>


### Features

* upgrade to upgrade to gcf-utils@12 ([#2262](https://www.github.com/googleapis/repo-automation-bots/issues/2262)) ([bd04376](https://www.github.com/googleapis/repo-automation-bots/commit/bd043767ae59a4eed450f1d18741111dc4c3f8e8))
* **@google-automations/bot-config-utils:** upgrade to gcf-utils@12 ([#2262](https://www.github.com/googleapis/repo-automation-bots/issues/2262)) ([bd04376](https://www.github.com/googleapis/repo-automation-bots/commit/bd043767ae59a4eed450f1d18741111dc4c3f8e8))
* **@google-automations/label-utils:** upgrade to gcf-utils@12 ([#2262](https://www.github.com/googleapis/repo-automation-bots/issues/2262)) ([bd04376](https://www.github.com/googleapis/repo-automation-bots/commit/bd043767ae59a4eed450f1d18741111dc4c3f8e8))
* **@google-automations/object-selector:** upgrade to gcf-utils@12 ([#2262](https://www.github.com/googleapis/repo-automation-bots/issues/2262)) ([bd04376](https://www.github.com/googleapis/repo-automation-bots/commit/bd043767ae59a4eed450f1d18741111dc4c3f8e8))
* **@google-automations/datastore-lock:** upgrade to gcf-utils@12 ([#2262](https://www.github.com/googleapis/repo-automation-bots/issues/2262)) ([bd04376](https://www.github.com/googleapis/repo-automation-bots/commit/bd043767ae59a4eed450f1d18741111dc4c3f8e8))
</details>
<details><summary>@google-automations/bot-config-utils: 3.2.0</summary>


### Features

* upgrade to gcf-utils@12 ([#2262](https://www.github.com/googleapis/repo-automation-bots/issues/2262)) ([bd04376](https://www.github.com/googleapis/repo-automation-bots/commit/bd043767ae59a4eed450f1d18741111dc4c3f8e8))
</details>
<details><summary>@google-automations/label-utils: 1.1.0</summary>


### Features

* upgrade to gcf-utils@12 ([#2262](https://www.github.com/googleapis/repo-automation-bots/issues/2262)) ([bd04376](https://www.github.com/googleapis/repo-automation-bots/commit/bd043767ae59a4eed450f1d18741111dc4c3f8e8))
</details>
<details><summary>@google-automations/object-selector: 1.1.0</summary>


### Features

* upgrade to gcf-utils@12 ([#2262](https://www.github.com/googleapis/repo-automation-bots/issues/2262)) ([bd04376](https://www.github.com/googleapis/repo-automation-bots/commit/bd043767ae59a4eed450f1d18741111dc4c3f8e8))
</details>
<details><summary>@google-automations/datastore-lock: 2.1.0</summary>


### Features

* upgrade to gcf-utils@12 ([#2262](https://www.github.com/googleapis/repo-automation-bots/issues/2262)) ([bd04376](https://www.github.com/googleapis/repo-automation-bots/commit/bd043767ae59a4eed450f1d18741111dc4c3f8e8))
</details>


This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
133 changes: 133 additions & 0 deletions test/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5053,6 +5053,139 @@ describe('Manifest', () => {
expect(releases[0].path).to.eql('.');
});

it('should handle customized group pull request title', async () => {
mockPullRequests(
github,
[],
[
{
headBranchName: 'release-please/branches/main',
baseBranchName: 'main',
number: 1234,
title: 'chore: release v3.3.0',
body: pullRequestBody('release-notes/multiple-with-root.txt'),
labels: ['autorelease: pending'],
files: [
'package.json',
'packages/bot-config-utils/package.json',
'packages/label-utils/package.json',
'packages/object-selector/package.json',
'packages/datastore-lock/package.json',
],
sha: 'abc123',
},
]
);
const getFileContentsStub = sandbox.stub(
github,
'getFileContentsOnBranch'
);
getFileContentsStub
.withArgs('package.json', 'main')
.resolves(
buildGitHubFileRaw(JSON.stringify({name: '@google-automations/all'}))
)
.withArgs('packages/bot-config-utils/package.json', 'main')
.resolves(
buildGitHubFileRaw(
JSON.stringify({name: '@google-automations/bot-config-utils'})
)
)
.withArgs('packages/label-utils/package.json', 'main')
.resolves(
buildGitHubFileRaw(
JSON.stringify({name: '@google-automations/label-utils'})
)
)
.withArgs('packages/object-selector/package.json', 'main')
.resolves(
buildGitHubFileRaw(
JSON.stringify({name: '@google-automations/object-selector'})
)
)
.withArgs('packages/datastore-lock/package.json', 'main')
.resolves(
buildGitHubFileRaw(
JSON.stringify({name: '@google-automations/datastore-lock'})
)
);
const manifest = new Manifest(
github,
'main',
{
'.': {
releaseType: 'node',
component: '@google-automations/all',
includeComponentInTag: false,
},
'packages/bot-config-utils': {
releaseType: 'node',
},
'packages/label-utils': {
releaseType: 'node',
},
'packages/object-selector': {
releaseType: 'node',
},
'packages/datastore-lock': {
releaseType: 'node',
},
},
{
'.': Version.parse('3.2.0'),
'packages/bot-config-utils': Version.parse('3.1.4'),
'packages/label-utils': Version.parse('1.0.1'),
'packages/object-selector': Version.parse('1.0.2'),
'packages/datastore-lock': Version.parse('2.0.0'),
},
{
groupPullRequestTitlePattern: 'chore: release v${version}',
}
);
const releases = await manifest.buildReleases();
expect(releases).lengthOf(5);
// 3.3.0
expect(releases[0].tag.toString()).to.eql('v3.3.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[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[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[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');
});

it('should skip component releases for non-component configs', async () => {
mockPullRequests(
github,
Expand Down