Skip to content

Commit

Permalink
fix(manifest): node-workspace plugin respects release-as (#901)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldodge79 committed May 11, 2021
1 parent 1af2623 commit 2d4ee9e
Show file tree
Hide file tree
Showing 14 changed files with 299 additions and 45 deletions.
154 changes: 154 additions & 0 deletions __snapshots__/node-workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,160 @@ exports['NodeWorkspaceDependencyUpdates run handles unusual changelog formats lo
]
]

exports['NodeWorkspaceDependencyUpdates run prefers release-as configuration over default patch-bump changes'] = `
====================
{
"config": {
"releaseType": "node",
"packageName": "@here/pkgA",
"path": "packages/pkgA"
},
"prData": {
"version": "1.1.2",
"changes": {}
}
}
filename: packages/pkgA/package.json
{
"name": "@here/pkgA",
"version": "1.1.2",
"dependencies": {
"@there/foo": "^4.1.7"
}
}
filename: packages/pkgA/CHANGELOG.md
# Changelog
All notable changes to this project will be documented in this file.### [1.1.2](https://www.github.com/fake/repo/compare/pkgA-v1.1.1...pkgA-v1.1.2) (1983-10-10)
### Bug Fixes
* We fixed a bug!
====================
{
"config": {
"path": "packages/pkgB",
"releaseType": "node",
"releaseAs": "2.3.0",
"packageName": "@here/pkgB"
},
"prData": {
"version": "2.3.0",
"changes": {}
}
}
filename: packages/pkgB/package.json
{
"name": "@here/pkgB",
"version": "2.3.0",
"dependencies": {
"@here/pkgA": "^1.1.2",
"someExternal": "^9.2.3"
}
}
filename: packages/pkgB/CHANGELOG.md
# Changelog
All notable changes to this project will be documented in this file.
## [2.3.0](https://www.github.com/fake/repo/compare/pkgB-v2.2.2...pkgB-v2.3.0) (1983-10-10)
### Dependencies
* The following workspace dependencies were updated
* dependencies
* @here/pkgA bumped from ^1.1.1 to ^1.1.2
### [2.2.2](https://www.github.com/fake/repo/compare/pkgB-v2.2.1...pkgB-v2.2.2) (1983-10-10)
### Bug Fixes
* We fixed a bug
====================
{
"config": {
"path": "packages/pkgC",
"releaseType": "node",
"packageName": "@here/pkgC"
},
"prData": {
"version": "3.3.4",
"changes": {}
}
}
filename: packages/pkgC/package.json
{
"name": "@here/pkgC",
"version": "3.3.4",
"dependencies": {
"@here/pkgB": "^2.3.0",
"anotherExternal": "^4.3.1"
}
}
filename: packages/pkgC/CHANGELOG.md
# Changelog
### [3.3.4](https://www.github.com/fake/repo/compare/pkgC-v3.3.3...pkgC-v3.3.4) (1983-10-10)
### Dependencies
* The following workspace dependencies were updated
* dependencies
* @here/pkgB bumped from ^2.2.2 to ^2.3.0
`

exports['NodeWorkspaceDependencyUpdates run prefers release-as configuration over default patch-bump logs'] = [
[
"node-workspace: found packages/pkgA/package.json in changes",
"success"
],
[
"node-workspace: loaded packages/pkgA/package.json from existing changes",
"success"
],
[
"node-workspace: loaded packages/pkgB/package.json from github",
"success"
],
[
"node-workspace: loaded packages/pkgC/package.json from github",
"success"
],
[
"node-workspace: setting packages/pkgA/package.json to 1.1.2 from release-please",
"success"
],
[
"node-workspace: setting packages/pkgB/package.json to 2.3.0 from release-as configuration",
"success"
],
[
"node-workspace: setting packages/pkgC/package.json to 3.3.4 from dependency bump",
"success"
],
[
"node-workspace: @here/pkgB.@here/pkgA updated to ^1.1.2",
"success"
],
[
"node-workspace: @here/pkgC.@here/pkgB updated to ^2.3.0",
"success"
]
]

exports['NodeWorkspaceDependencyUpdates run updates dependent from pre-release version changes'] = `
====================
{
Expand Down
10 changes: 4 additions & 6 deletions src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,15 @@ function getGitHubFactoryOpts(
}

function manifest(options: ManifestFactoryOptions): Manifest {
const [GHFactoryOptions, ManifestFactoryOptions] = getGitHubFactoryOpts(
options
);
const [GHFactoryOptions, ManifestFactoryOptions] =
getGitHubFactoryOpts(options);
const github = gitHubInstance(GHFactoryOptions);
return new Manifest({github, ...ManifestFactoryOptions});
}

function githubRelease(options: GitHubReleaseFactoryOptions): GitHubRelease {
const [GHFactoryOptions, GHRAndRPFactoryOptions] = getGitHubFactoryOpts(
options
);
const [GHFactoryOptions, GHRAndRPFactoryOptions] =
getGitHubFactoryOpts(options);
const github = gitHubInstance(GHFactoryOptions);
const {
releaseType,
Expand Down
14 changes: 9 additions & 5 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ type CreateIssueCommentResponse = PromiseValue<
// see: PromiseValue<
// ReturnType<InstanceType<typeof Octokit>['repos']['createRelease']>
// >['data'];
type CommitsListResponse = Endpoints['GET /repos/{owner}/{repo}/commits']['response'];
type CommitGetResponse = Endpoints['GET /repos/{owner}/{repo}/commits/{ref}']['response'];
type CommitsListResponse =
Endpoints['GET /repos/{owner}/{repo}/commits']['response'];
type CommitGetResponse =
Endpoints['GET /repos/{owner}/{repo}/commits/{ref}']['response'];
export type ReleaseCreateResponse = {
name: string;
tag_name: string;
Expand Down Expand Up @@ -1309,9 +1311,11 @@ export class GitHub {
Authorization: `token ${this.token}`,
},
});
this.repositoryDefaultBranch = (data as {
default_branch: string;
}).default_branch;
this.repositoryDefaultBranch = (
data as {
default_branch: string;
}
).default_branch;
return this.repositoryDefaultBranch as string;
}

Expand Down
11 changes: 5 additions & 6 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,11 @@ export class Manifest {
getFileMethod: 'getConfigJson' | 'getManifestJson',
fileName: string
): Promise<{valid: true; obj: object} | {valid: false; obj: undefined}> {
let response:
| {valid: true; obj: object}
| {valid: false; obj: undefined} = {
valid: false,
obj: undefined,
};
let response: {valid: true; obj: object} | {valid: false; obj: undefined} =
{
valid: false,
obj: undefined,
};
try {
const obj = await this[getFileMethod]();
if (obj.constructor.name === 'Object') {
Expand Down
33 changes: 21 additions & 12 deletions src/plugins/node-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,28 @@ export default class NodeWorkspaceDependencyUpdates extends ManifestPlugin {
version = node.version;
source = RELEASE_PLEASE;
} else {
// must be a dependent, assume a "patch" bump.
const patch = semver.inc(node.version, 'patch');
if (patch === null) {
this.log(
`Don't know how to patch ${node.name}'s version(${node.version})`,
CheckpointType.Failure
);
invalidVersions.add(node.name);
version = node.version;
source = 'failed to patch bump';
// must be a dependent, check for releaseAs config otherwise default
// to a patch bump.
const pkgConfig = this.config.parsedPackages.find(
p => `${p.path}/package.json` === node.location
);
if (pkgConfig?.releaseAs) {
version = pkgConfig.releaseAs;
source = 'release-as configuration';
} else {
version = patch;
source = 'dependency bump';
const patch = semver.inc(node.version, 'patch');
if (patch === null) {
this.log(
`Don't know how to patch ${node.name}'s version(${node.version})`,
CheckpointType.Failure
);
invalidVersions.add(node.name);
version = node.version;
source = 'failed to patch bump';
} else {
version = patch;
source = 'dependency bump';
}
}
}
this.log(
Expand Down
3 changes: 2 additions & 1 deletion src/release-pr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ export class ReleasePR {
latestTag: GitHubTag | undefined,
preRelease = false
): Promise<ReleaseCandidate> {
const releaseAsRe = /release-as:\s*v?([0-9]+\.[0-9]+\.[0-9a-z]+(-[0-9a-z.]+)?)\s*/i;
const releaseAsRe =
/release-as:\s*v?([0-9]+\.[0-9]+\.[0-9a-z]+(-[0-9a-z.]+)?)\s*/i;
const previousTag = latestTag ? latestTag.name : undefined;
let version = latestTag ? latestTag.version : this.defaultInitialVersion();

Expand Down
3 changes: 2 additions & 1 deletion src/releasers/java-bom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import {BumpType, maxBumpType, fromSemverReleaseType} from './java/bump_type';
import {Version} from './java/version';
import {JavaYoshi} from './java-yoshi';

const DEPENDENCY_UPDATE_REGEX = /^deps: update dependency (.*) to (v.*)(\s\(#\d+\))?$/m;
const DEPENDENCY_UPDATE_REGEX =
/^deps: update dependency (.*) to (v.*)(\s\(#\d+\))?$/m;
const DEPENDENCY_PATCH_VERSION_REGEX = /^v\d+\.\d+\.[1-9]\d*(-.*)?/;

export class JavaBom extends JavaYoshi {
Expand Down
3 changes: 1 addition & 2 deletions src/releasers/java-yoshi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,7 @@ export class JavaYoshi extends ReleasePR {
updates.push(
new GoogleUtils({
// TODO(@chingor): should this use search like pom.xml?
path:
'google-api-client/src/main/java/com/google/api/client/googleapis/GoogleUtils.java',
path: 'google-api-client/src/main/java/com/google/api/client/googleapis/GoogleUtils.java',
changelogEntry,
versions: candidateVersions,
version: candidate.version,
Expand Down
3 changes: 2 additions & 1 deletion src/updaters/java/java_update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {Update, VersionsMap, UpdateOptions} from '../update';
import {GitHubFileContents} from '../../github';

const INLINE_UPDATE_REGEX = /{x-version-update:([\w\-_]+):(current|released)}/;
const BLOCK_START_REGEX = /{x-version-update-start:([\w\-_]+):(current|released)}/;
const BLOCK_START_REGEX =
/{x-version-update-start:([\w\-_]+):(current|released)}/;
const BLOCK_END_REGEX = /{x-version-update-end}/;
const VERSION_REGEX = /\d+\.\d+\.\d+(-\w+(\.\d+)?)?(-SNAPSHOT)?/;

Expand Down
3 changes: 2 additions & 1 deletion src/util/branch-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ export class BranchName {
}
}

const AUTORELEASE_PATTERN = /^release-?(?<component>[\w-.]*)?-v(?<version>[0-9].*)$/;
const AUTORELEASE_PATTERN =
/^release-?(?<component>[\w-.]*)?-v(?<version>[0-9].*)$/;
class AutoreleaseBranchName extends BranchName {
static matches(branchName: string): boolean {
return !!branchName.match(AUTORELEASE_PATTERN);
Expand Down
4 changes: 2 additions & 2 deletions test/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ describe('CLI', () => {
stack,
};
const logs: string[] = [];
handleError.logger = ({
handleError.logger = {
error: (msg: string) => logs.push(msg),
} as unknown) as Console;
} as unknown as Console;
handleError.yargsArgs = {debug: true, _: ['foobar'], $0: 'mocha?'};
handleError(err);
expect(logs).to.eql([
Expand Down
7 changes: 2 additions & 5 deletions test/commit-split.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,8 @@ describe('CommitSplit', () => {
it(`partitions commits by ${
usePackagePaths ? 'specified' : 'top level'
} paths: includeEmpty(${includeEmpty})`, () => {
const [
expectedSplitCommitSplit,
packagePaths,
commits,
] = setupPackagePathCommits(includeEmpty, usePackagePaths);
const [expectedSplitCommitSplit, packagePaths, commits] =
setupPackagePathCommits(includeEmpty, usePackagePaths);
const commitSplitOpts: CommitSplitOptions = {};
if (usePackagePaths) {
commitSplitOpts.packagePaths = packagePaths;
Expand Down
6 changes: 3 additions & 3 deletions test/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('factory', () => {
.withArgs({
repo,
owner,
headers: (sinon.match.any as unknown) as RequestHeaders,
headers: sinon.match.any as unknown as RequestHeaders,
})
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.resolves({data: {default_branch: 'main'}} as any);
Expand Down Expand Up @@ -305,7 +305,7 @@ describe('factory', () => {
expect(() =>
factory.runCommand(
'foobar' as ReleasePRCommand,
({bar: 'baz'} as unknown) as ReleasePRFactoryOptions
{bar: 'baz'} as unknown as ReleasePRFactoryOptions
)
).to.throw('Invalid command(foobar) with options({"bar":"baz"})');
});
Expand Down Expand Up @@ -378,7 +378,7 @@ describe('factory', () => {
it('errors with bad method on unknown', async () => {
expect(() =>
factory.call(
({foo: () => 'in foo'} as unknown) as ReleasePR,
{foo: () => 'in foo'} as unknown as ReleasePR,
'foo' as ReleasePRMethod
)
).to.throw('Unknown instance.');
Expand Down

0 comments on commit 2d4ee9e

Please sign in to comment.