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: support-node-workspace-plugin-prerelease #2249

Merged
merged 1 commit into from
Sep 11, 2024
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
55 changes: 55 additions & 0 deletions __snapshots__/node-workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,61 @@ Release notes for path: node1, releaseType: node
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
`

exports['NodeWorkspace plugin run walks dependency tree and updates previously untouched packages (prerelease) 1'] = `
:robot: I have created a release *beep* *boop*
---


<details><summary>@here/pkgA: 3.3.4-beta</summary>

Release notes for path: node1, releaseType: node
</details>

<details><summary>pkgB: 2.2.3-beta</summary>

## [2.2.3-beta](https://github.com/googleapis/node-test-repo/compare/pkgB-v2.2.2-beta...pkgB-v2.2.3-beta) (1983-10-10)


### Dependencies

* The following workspace dependencies were updated
* dependencies
* @here/pkgA bumped from 3.3.3 to 3.3.4-beta
</details>

<details><summary>pkgC: 1.1.2-beta</summary>

## 1.1.2-beta (1983-10-10)


### Dependencies

* The following workspace dependencies were updated
* dependencies
* @here/pkgB bumped from 2.2.2 to 2.2.3-beta
</details>

<details><summary>@here/pkgD: 4.4.5-beta</summary>

Release notes for path: node4, releaseType: node
</details>

<details><summary>pkgE: 1.0.1-beta</summary>

## 1.0.1-beta (1983-10-10)


### Dependencies

* The following workspace dependencies were updated
* dependencies
* @here/pkgA bumped to 3.3.4-beta
</details>

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
`

exports['NodeWorkspace plugin run walks dependency tree and updates previously untouched packages 1'] = `
:robot: I have created a release *beep* *boop*
---
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/node-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ import {
appendDependenciesSectionToChangelog,
addPath,
} from './workspace';
import {PatchVersionUpdate} from '../versioning-strategy';
import {Strategy} from '../strategy';
import {Commit} from '../commit';
import {Release} from '../release';
import {CompositeUpdater} from '../updaters/composite';
import {PackageJson, newVersionWithRange} from '../updaters/node/package-json';
import {Logger} from '../util/logger';
import {PatchVersionUpdate} from '../versioning-strategy';

interface ParsedPackageJson {
name: string;
Expand Down Expand Up @@ -170,6 +170,9 @@ export class NodeWorkspace extends WorkspacePlugin<Package> {

protected bumpVersion(pkg: Package): Version {
const version = Version.parse(pkg.version);
const strategy = this.strategiesByPath[pkg.path];

if (strategy) return strategy.versioningStrategy.bump(version, []);
return new PatchVersionUpdate().bump(version);
}

Expand Down
117 changes: 117 additions & 0 deletions test/plugins/node-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {ReleasePleaseManifest} from '../../src/updaters/release-please-manifest'
import {Node} from '../../src/strategies/node';
import {TagName} from '../../src/util/tag-name';
import {Generic} from '../../src/updaters/generic';
import {PrereleaseVersioningStrategy} from '../../src/versioning-strategies/prerelease';

const sandbox = sinon.createSandbox();
const fixturesPath = './test/fixtures/plugins/node-workspace';
Expand Down Expand Up @@ -314,6 +315,122 @@ describe('NodeWorkspace plugin', () => {
expect(updater.versionsMap?.get('node5')?.toString()).to.eql('1.0.1');
snapshot(dateSafe(nodeCandidate!.pullRequest.body.toString()));
});
it('walks dependency tree and updates previously untouched packages (prerelease)', async () => {
const candidates: CandidateReleasePullRequest[] = [
buildMockCandidatePullRequest('node1', 'node', '3.3.4-beta', {
component: '@here/pkgA',
updates: [
buildMockPackageUpdate('node1/package.json', 'node1/package.json'),
],
}),
buildMockCandidatePullRequest('node4', 'node', '4.4.5-beta', {
component: '@here/pkgD',
updates: [
buildMockPackageUpdate('node4/package.json', 'node4/package.json'),
],
}),
];
stubFilesFromFixtures({
sandbox,
github,
fixturePath: fixturesPath,
files: [
'node1/package.json',
'node2/package.json',
'node3/package.json',
'node4/package.json',
'node5/package.json',
],
flatten: false,
targetBranch: 'main',
});

await plugin.preconfigure(
{
node1: new Node({
github,
targetBranch: 'main',
path: 'node1',
packageName: '@here/pkgA',
versioningStrategy: new PrereleaseVersioningStrategy({
prereleaseType: 'beta',
}),
}),
node2: new Node({
github,
targetBranch: 'main',
path: 'node2',
packageName: '@here/pkgB',
versioningStrategy: new PrereleaseVersioningStrategy({
prereleaseType: 'beta',
}),
}),
node3: new Node({
github,
targetBranch: 'main',
path: 'node3',
packageName: '@here/pkgC',
versioningStrategy: new PrereleaseVersioningStrategy({
prereleaseType: 'beta',
}),
}),
node4: new Node({
github,
targetBranch: 'main',
path: 'node4',
packageName: '@here/pkgD',
versioningStrategy: new PrereleaseVersioningStrategy({
prereleaseType: 'beta',
}),
}),
node5: new Node({
github,
targetBranch: 'main',
path: 'node5',
packageName: '@here/pkgE',
versioningStrategy: new PrereleaseVersioningStrategy({
prereleaseType: 'beta',
}),
}),
},
{},
{
node2: {
tag: new TagName(new Version(2, 2, 2, 'beta'), 'pkgB'),
sha: '',
notes: '',
},
}
);

const newCandidates = await plugin.run(candidates);
expect(newCandidates).lengthOf(1);
const nodeCandidate = newCandidates.find(
candidate => candidate.config.releaseType === 'node'
);
expect(nodeCandidate).to.not.be.undefined;
const updates = nodeCandidate!.pullRequest.updates;
assertHasVersionUpdate(updates, 'node1/package.json', '3.3.4-beta');
assertHasVersionUpdate(updates, 'node2/package.json', '2.2.3-beta');
assertHasVersionUpdate(updates, 'node3/package.json', '1.1.2-beta');
assertHasVersionUpdate(updates, 'node4/package.json', '4.4.5-beta');
assertHasVersionUpdate(updates, 'node5/package.json', '1.0.1-beta');
const updater = assertHasUpdate(
updates,
'.release-please-manifest.json',
ReleasePleaseManifest
).updater as ReleasePleaseManifest;
expect(updater.versionsMap?.get('node2')?.toString()).to.eql(
'2.2.3-beta'
);
expect(updater.versionsMap?.get('node3')?.toString()).to.eql(
'1.1.2-beta'
);
expect(updater.versionsMap?.get('node5')?.toString()).to.eql(
'1.0.1-beta'
);
snapshot(dateSafe(nodeCandidate!.pullRequest.body.toString()));
});
it('appends dependency notes to an updated module', async () => {
const existingNotes =
'### Dependencies\n\n* update dependency foo/bar to 1.2.3';
Expand Down
Loading