Skip to content

Commit

Permalink
feat(manifest): add support for releasing root module
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Mar 20, 2021
1 parent 535b5f9 commit 0a5df74
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 2 deletions.
131 changes: 131 additions & 0 deletions __snapshots__/manifest.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,134 @@
exports['Manifest pullRequest allows root module to be published, via special "." path: changes'] = `
filename: node/pkg1/CHANGELOG.md
# Changelog
## [4.0.0](https://github.com/fake/repo/compare/pkg1-v3.2.1...pkg1-v4.0.0) (1983-10-10)
### ⚠ BREAKING CHANGES
* **@node/pkg1:** major new feature
### Features
* **@node/pkg1:** major new feature ([e3ab0ab](https://github.com/fake/repo/commit/e3ab0abfd66e66324f685ceeececf35c))
filename: node/pkg1/package.json
{
"name": "@node/pkg1",
"version": "4.0.0"
}
filename: node/pkg2/CHANGELOG.md
# Changelog
## [2.0.0](https://github.com/fake/repo/compare/pkg2-v1.2.3...pkg2-v2.0.0) (1983-10-10)
### ⚠ BREAKING CHANGES
* **@node/pkg2:** major new feature
### Features
* **@node/pkg2:** major new feature ([72f962d](https://github.com/fake/repo/commit/72f962d44ba0bcee15594ea6bdc67d8b))
filename: node/pkg2/package.json
{
"name": "@node/pkg2",
"version": "2.0.0"
}
filename: CHANGELOG.md
# Changelog
## [3.0.0](https://github.com/fake/repo/compare/googleapis-v2.0.0...googleapis-v3.0.0) (1983-10-10)
### ⚠ BREAKING CHANGES
* **@node/pkg2:** major new feature
### Features
* **@node/pkg2:** major new feature ([72f962d](https://github.com/fake/repo/commit/72f962d44ba0bcee15594ea6bdc67d8b))
filename: package.json
{
"name": "googleapis",
"version": "3.0.0"
}
filename: .release-please-manifest.json
{
".": "3.0.0",
"node/pkg1": "4.0.0",
"node/pkg2": "2.0.0"
}
`

exports['Manifest pullRequest allows root module to be published, via special "." path: options'] = `
upstreamOwner: fake
upstreamRepo: repo
title: chore: release
branch: release-please/branches/main
description: :robot: I have created a release \\*beep\\* \\*boop\\*
---
@node/pkg1: 4.0.0
## [4.0.0](https://github.com/fake/repo/compare/pkg1-v3.2.1...pkg1-v4.0.0) (1983-10-10)
### ⚠ BREAKING CHANGES
* **@node/pkg1:** major new feature
### Features
* **@node/pkg1:** major new feature ([e3ab0ab](https://github.com/fake/repo/commit/e3ab0abfd66e66324f685ceeececf35c))
---
---
@node/pkg2: 2.0.0
## [2.0.0](https://github.com/fake/repo/compare/pkg2-v1.2.3...pkg2-v2.0.0) (1983-10-10)
### ⚠ BREAKING CHANGES
* **@node/pkg2:** major new feature
### Features
* **@node/pkg2:** major new feature ([72f962d](https://github.com/fake/repo/commit/72f962d44ba0bcee15594ea6bdc67d8b))
---
---
googleapis: 3.0.0
## [3.0.0](https://github.com/fake/repo/compare/googleapis-v2.0.0...googleapis-v3.0.0) (1983-10-10)
### ⚠ BREAKING CHANGES
* **@node/pkg2:** major new feature
### Features
* **@node/pkg2:** major new feature ([72f962d](https://github.com/fake/repo/commit/72f962d44ba0bcee15594ea6bdc67d8b))
---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
primary: main
force: true
fork: false
message: chore: release
`

exports['Manifest pullRequest boostraps from HEAD manifest if first PR: changes'] = `
filename: node/pkg1/CHANGELOG.md
Expand Down
4 changes: 3 additions & 1 deletion src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,9 @@ export class Manifest {
const missingVersionPaths = [];
const defaultBranch = await this.gh.getDefaultBranch();
for (const pkg of packages) {
const commits = commitsPerPath[pkg.path];
// The special path of '.' indicates the root module is being released
// in this case, use the entire list of commits:
commits = pkg.path === '.' ? commits : commitsPerPath[pkg.path];
if (!commits || commits.length === 0) {
continue;
}
Expand Down
4 changes: 3 additions & 1 deletion src/release-pr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ export class ReleasePR {
constructor(options: ReleasePRConstructorOptions) {
this.bumpMinorPreMajor = options.bumpMinorPreMajor || false;
this.labels = options.labels ?? DEFAULT_LABELS;
this.path = options.path;
// undefined represents the root path of the library, if the special
// '.' path is provided, simply ignore it:
this.path = options.path !== '.' ? options.path : undefined;
this.packageName = options.packageName || '';
this.monorepoTags = options.monorepoTags || false;
this.releaseAs = options.releaseAs;
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/manifest/repo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "googleapis",
"version": "3.3.3"
}
74 changes: 74 additions & 0 deletions test/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ describe('Manifest', () => {
'node/pkg2/CHANGELOG.md',
'python/CHANGELOG.md',
'python/HISTORY.md',
'package-lock.json',
'samples/package.json',
'CHANGELOG.md',
];
for (const notFound of expectedNotFound) {
mock
Expand Down Expand Up @@ -283,6 +286,77 @@ describe('Manifest', () => {
]);
});

it('allows root module to be published, via special "." path', async function () {
const manifest = JSON.stringify({
'node/pkg1': '3.2.1',
'node/pkg2': '1.2.3',
'.': '2.0.0',
});
const config = JSON.stringify({
packages: {
'node/pkg1': {},
'node/pkg2': {},
'.': {},
},
});
const commits = [
buildMockCommit('feat(@node/pkg1)!: major new feature', [
'node/pkg1/src/foo.ts',
]),
buildMockCommit('feat(@node/pkg2)!: major new feature', [
'node/pkg2/src/bar.ts',
]),
];

const github = new GitHub({
owner: 'fake',
repo: 'repo',
defaultBranch,
});
const mock = mockGithub(github);
expectManifest(mock, {manifest, lastReleaseSha});
expectPR(mock, {lastReleaseSha});
expectCommitsSinceSha(mock, {commits, lastReleaseSha});
expectGetFiles(mock, {
fixtureFiles: [
'node/pkg1/package.json',
'node/pkg2/package.json',
'package.json',
],
inlineFiles: [
['release-please-config.json', config],
['.release-please-manifest.json', manifest],
],
});
expectLabelAndComment(mock, {addLabel});
stubSuggesterWithSnapshot(sandbox, this.test!.fullTitle());
const logs: [string, CheckpointType][] = [];
const checkpoint = (msg: string, type: CheckpointType) =>
logs.push([msg, type]);

const pr = await new Manifest({github, checkpoint}).pullRequest();

mock.verify();
expect(pr).to.equal(22);
expect(logs).to.eql([
[
'Found version 3.2.1 for node/pkg1 in .release-please-manifest.json at abc123 of main',
CheckpointType.Success,
],
[
'Found version 1.2.3 for node/pkg2 in .release-please-manifest.json at abc123 of main',
CheckpointType.Success,
],
[
'Found version 2.0.0 for . in .release-please-manifest.json at abc123 of main',
CheckpointType.Success,
],
['Processing package: Node(@node/pkg1)', CheckpointType.Success],
['Processing package: Node(@node/pkg2)', CheckpointType.Success],
['Processing package: Node(googleapis)', CheckpointType.Success],
]);
});

it('respects python releaser specific config over defaults', async function () {
// https://github.com/googleapis/release-please/pull/790#issuecomment-783792069
if (process.versions.node.split('.')[0] === '10') {
Expand Down

0 comments on commit 0a5df74

Please sign in to comment.