Skip to content

Commit 013b78b

Browse files
authored
Merge branch 'main' into phale/W-8857752
2 parents 0c4afaa + ac7120c commit 013b78b

11 files changed

+253
-106
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [1.10.0](https://github.com/salesforcecli/plugin-release-management/compare/v1.9.4...v1.10.0) (2021-05-20)
6+
7+
8+
### Features
9+
10+
* add npm:release:validate command ([#122](https://github.com/salesforcecli/plugin-release-management/issues/122)) ([418ca2e](https://github.com/salesforcecli/plugin-release-management/commit/418ca2ec3b9f2e9749448d8f9938bd390b52998c))
11+
512
### [1.9.4](https://github.com/salesforcecli/plugin-release-management/compare/v1.9.3...v1.9.4) (2021-05-12)
613

714

README.md

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ sfdx plugins
9999
* [`sfdx npm:dependencies:pin [-d] [-t <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-npmdependenciespin--d--t-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
100100
* [`sfdx npm:lerna:release [-d] [-s <array>] [-t <string>] [-a <string>] [--install] [--githubrelease] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-npmlernarelease--d--s-array--t-string--a-string---install---githubrelease---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
101101
* [`sfdx npm:package:release [-d] [-s] [-t <string>] [-a <string>] [--install] [--prerelease <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-npmpackagerelease--d--s--t-string--a-string---install---prerelease-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
102+
* [`sfdx npm:release:validate [--verbose] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-npmreleasevalidate---verbose---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
102103
* [`sfdx `](#sfdx-)
103104
* [`sfdx trust:sign -s <string> -p <string> -k <string> [-t <string> | --tarpath <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-trustsign--s-string--p-string--k-string--t-string----tarpath-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
104105
* [`sfdx trust:upload -f <string> -b <string> [-k <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-trustupload--f-string--b-string--k-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
@@ -124,7 +125,7 @@ EXAMPLE
124125
sfdx circleci -t plugin
125126
```
126127

127-
_See code: [src/commands/circleci/index.ts](https://github.com/salesforcecli/plugin-release-management/blob/v1.9.3/src/commands/circleci/index.ts)_
128+
_See code: [src/commands/circleci/index.ts](https://github.com/salesforcecli/plugin-release-management/blob/v1.9.4/src/commands/circleci/index.ts)_
128129

129130
## `sfdx circleci:envvar:update -e <string> [-s <string>] [--dryrun] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`
130131

@@ -161,7 +162,7 @@ EXAMPLES
161162
sfdx circleci -t plugin | sfdx circleci:envvar:update -e 'MY_ENV_VAR' -e 'MY_OTHER_ENV_VAR'
162163
```
163164

164-
_See code: [src/commands/circleci/envvar/update.ts](https://github.com/salesforcecli/plugin-release-management/blob/v1.9.3/src/commands/circleci/envvar/update.ts)_
165+
_See code: [src/commands/circleci/envvar/update.ts](https://github.com/salesforcecli/plugin-release-management/blob/v1.9.4/src/commands/circleci/envvar/update.ts)_
165166

166167
## `sfdx cli:versions:inspect -c <string> -l <string> [-d <string>] [-s] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`
167168

@@ -206,7 +207,7 @@ EXAMPLES
206207
sfdx cli:versions:inspect -l npm -c latest -d chalk -s
207208
```
208209

209-
_See code: [src/commands/cli/versions/inspect.ts](https://github.com/salesforcecli/plugin-release-management/blob/v1.9.3/src/commands/cli/versions/inspect.ts)_
210+
_See code: [src/commands/cli/versions/inspect.ts](https://github.com/salesforcecli/plugin-release-management/blob/v1.9.4/src/commands/cli/versions/inspect.ts)_
210211

211212
## `sfdx npm:dependencies:pin [-d] [-t <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`
212213

@@ -231,7 +232,7 @@ OPTIONS
231232
this command invocation
232233
```
233234

234-
_See code: [src/commands/npm/dependencies/pin.ts](https://github.com/salesforcecli/plugin-release-management/blob/v1.9.3/src/commands/npm/dependencies/pin.ts)_
235+
_See code: [src/commands/npm/dependencies/pin.ts](https://github.com/salesforcecli/plugin-release-management/blob/v1.9.4/src/commands/npm/dependencies/pin.ts)_
235236

236237
## `sfdx npm:lerna:release [-d] [-s <array>] [-t <string>] [-a <string>] [--install] [--githubrelease] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`
237238

@@ -266,7 +267,7 @@ OPTIONS
266267
this command invocation
267268
```
268269

269-
_See code: [src/commands/npm/lerna/release.ts](https://github.com/salesforcecli/plugin-release-management/blob/v1.9.3/src/commands/npm/lerna/release.ts)_
270+
_See code: [src/commands/npm/lerna/release.ts](https://github.com/salesforcecli/plugin-release-management/blob/v1.9.4/src/commands/npm/lerna/release.ts)_
270271

271272
## `sfdx npm:package:release [-d] [-s] [-t <string>] [-a <string>] [--install] [--prerelease <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`
272273

@@ -304,7 +305,28 @@ OPTIONS
304305
is not manually set
305306
```
306307

307-
_See code: [src/commands/npm/package/release.ts](https://github.com/salesforcecli/plugin-release-management/blob/v1.9.3/src/commands/npm/package/release.ts)_
308+
_See code: [src/commands/npm/package/release.ts](https://github.com/salesforcecli/plugin-release-management/blob/v1.9.4/src/commands/npm/package/release.ts)_
309+
310+
## `sfdx npm:release:validate [--verbose] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`
311+
312+
inspects the git commits to see if there are any commits that will warrant a new release
313+
314+
```
315+
USAGE
316+
$ sfdx npm:release:validate [--verbose] [--json] [--loglevel
317+
trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
318+
319+
OPTIONS
320+
--json format output as json
321+
322+
--loglevel=(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL) [default: warn] logging level for
323+
this command invocation
324+
325+
--verbose show all commits for all packages
326+
(only works with --json flag)
327+
```
328+
329+
_See code: [src/commands/npm/release/validate.ts](https://github.com/salesforcecli/plugin-release-management/blob/v1.9.4/src/commands/npm/release/validate.ts)_
308330

309331
## `sfdx `
310332

@@ -349,7 +371,7 @@ EXAMPLES
349371
sfdx repositories --json | jq -r '.result[] | select(.name=="sfdx-core") | .packages[] | .url
350372
```
351373

352-
_See code: [src/commands/repositories/index.ts](https://github.com/salesforcecli/plugin-release-management/blob/v1.9.3/src/commands/repositories/index.ts)_
374+
_See code: [src/commands/repositories/index.ts](https://github.com/salesforcecli/plugin-release-management/blob/v1.9.4/src/commands/repositories/index.ts)_
353375

354376
## `sfdx trust:sign -s <string> -p <string> -k <string> [-t <string> | --tarpath <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`
355377

@@ -384,7 +406,7 @@ OPTIONS
384406
specify the package tgz path to sign instead of generating one from the target package
385407
```
386408

387-
_See code: [src/commands/trust/sign.ts](https://github.com/salesforcecli/plugin-release-management/blob/v1.9.3/src/commands/trust/sign.ts)_
409+
_See code: [src/commands/trust/sign.ts](https://github.com/salesforcecli/plugin-release-management/blob/v1.9.4/src/commands/trust/sign.ts)_
388410

389411
## `sfdx trust:upload -f <string> -b <string> [-k <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`
390412

@@ -409,7 +431,7 @@ OPTIONS
409431
this command invocation
410432
```
411433

412-
_See code: [src/commands/trust/upload.ts](https://github.com/salesforcecli/plugin-release-management/blob/v1.9.3/src/commands/trust/upload.ts)_
434+
_See code: [src/commands/trust/upload.ts](https://github.com/salesforcecli/plugin-release-management/blob/v1.9.4/src/commands/trust/upload.ts)_
413435

414436
## `sfdx typescript:update [-v <string>] [-t <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`
415437

@@ -436,5 +458,5 @@ OPTIONS
436458
this command invocation
437459
```
438460

439-
_See code: [src/commands/typescript/update.ts](https://github.com/salesforcecli/plugin-release-management/blob/v1.9.3/src/commands/typescript/update.ts)_
461+
_See code: [src/commands/typescript/update.ts](https://github.com/salesforcecli/plugin-release-management/blob/v1.9.4/src/commands/typescript/update.ts)_
440462
<!-- commandsstop -->

command-snapshot.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
"plugin": "@salesforce/plugin-release-management",
3030
"flags": ["dryrun", "install", "json", "loglevel", "npmaccess", "npmtag", "prerelease", "sign"]
3131
},
32+
{
33+
"command": "npm:release:validate",
34+
"plugin": "@salesforce/plugin-release-management",
35+
"flags": ["json", "loglevel", "verbose"]
36+
},
3237
{
3338
"command": "repositories",
3439
"plugin": "@salesforce/plugin-release-management",

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@salesforce/plugin-release-management",
33
"description": "A plugin for preparing and publishing npm packages",
4-
"version": "1.9.4",
4+
"version": "1.10.0",
55
"author": "Salesforce",
66
"bugs": "https://github.com/forcedotcom/cli/issues",
77
"bin": {
@@ -126,6 +126,9 @@
126126
},
127127
"package": {
128128
"description": "work with npm projects"
129+
},
130+
"release": {
131+
"description": "validate npm releases"
129132
}
130133
}
131134
},

src/commands/npm/release/validate.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2020, salesforce.com, inc.
3+
* All rights reserved.
4+
* Licensed under the BSD 3-Clause license.
5+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
9+
import { isMonoRepo, LernaRepo } from '../../../repository';
10+
import { Package } from '../../../package';
11+
import { CommitInspection, inspectCommits } from '../../../inspectCommits';
12+
13+
type PackageCommits = CommitInspection & {
14+
name: string;
15+
currentVersion: string;
16+
};
17+
18+
type Response = {
19+
shouldRelease: boolean;
20+
packages?: PackageCommits[];
21+
};
22+
23+
export default class Validate extends SfdxCommand {
24+
public static readonly description =
25+
'inspects the git commits to see if there are any commits that will warrant a new release';
26+
public static readonly flagsConfig: FlagsConfig = {
27+
verbose: flags.builtin({
28+
description: 'show all commits for all packages (only works with --json flag)',
29+
}),
30+
};
31+
32+
public async run(): Promise<Response> {
33+
const isLerna = await isMonoRepo();
34+
const packages = isLerna ? await LernaRepo.getPackages() : [await Package.create()];
35+
const responses: PackageCommits[] = [];
36+
for (const pkg of packages) {
37+
const commitInspection = await inspectCommits(pkg, isLerna);
38+
const response = Object.assign(commitInspection, {
39+
name: pkg.name,
40+
currentVersion: pkg.packageJson.version,
41+
});
42+
responses.push(response);
43+
}
44+
const shouldRelease = responses.some((resp) => !!resp.shouldRelease);
45+
this.ux.log(shouldRelease.toString());
46+
return this.flags.verbose ? { shouldRelease, packages: responses } : { shouldRelease };
47+
}
48+
}

src/commands/typescript/update.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default class Update extends SfdxCommand {
6363
}
6464

6565
private async getPackages(): Promise<Package[]> {
66-
return this.repo instanceof LernaRepo ? await this.repo.getPackages() : [this.repo.package];
66+
return this.repo instanceof LernaRepo ? await LernaRepo.getPackages() : [this.repo.package];
6767
}
6868

6969
private async updateEsTargetConfig(packagePath: string): Promise<void> {

src/inspectCommits.ts

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright (c) 2020, salesforce.com, inc.
3+
* All rights reserved.
4+
* Licensed under the BSD 3-Clause license.
5+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
import * as os from 'os';
9+
import { Readable } from 'stream';
10+
import { exec } from 'shelljs';
11+
import * as conventionalCommitsParser from 'conventional-commits-parser';
12+
import * as conventionalChangelogPresetLoader from 'conventional-changelog-preset-loader';
13+
import { Nullable } from '@salesforce/ts-types';
14+
import { Package } from './package';
15+
16+
export interface Commit {
17+
type: Nullable<string>;
18+
header: Nullable<string>;
19+
body: Nullable<string>;
20+
}
21+
22+
export interface CommitInspection {
23+
releasableCommits: Commit[];
24+
unreleasableCommits: Commit[];
25+
nextVersionIsHardcoded: boolean;
26+
shouldRelease: boolean;
27+
}
28+
29+
/**
30+
* If the commit type isn't fix (patch bump), feat (minor bump), or breaking (major bump),
31+
* then standard-version always defaults to a patch bump.
32+
* See https://github.com/conventional-changelog/standard-version/issues/577
33+
*
34+
* We, however, don't want to publish a new version for chore, docs, etc. So we analyze
35+
* the commits to see if any of them indicate that a new release should be published.
36+
*/
37+
export async function inspectCommits(pkg: Package, lerna = false): Promise<CommitInspection> {
38+
const skippableCommitTypes = ['chore', 'style', 'docs', 'ci', 'test'];
39+
40+
// find the latest git tag so that we can get all the commits that have happened since
41+
const tags = exec('git fetch --tags && git tag', { silent: true }).stdout.split(os.EOL);
42+
const latestTag = lerna
43+
? tags.find((tag) => tag.includes(`${pkg.name}@${pkg.npmPackage.version}`)) || ''
44+
: tags.find((tag) => tag.includes(pkg.npmPackage.version));
45+
// import the default commit parser configuration
46+
const defaultConfigPath = require.resolve('conventional-changelog-conventionalcommits');
47+
const configuration = await conventionalChangelogPresetLoader({ name: defaultConfigPath });
48+
49+
const commits: Commit[] = await new Promise((resolve) => {
50+
const DELIMITER = 'SPLIT';
51+
const gitLogCommand = lerna
52+
? `git log --format=%B%n-hash-%n%H%n${DELIMITER} ${latestTag}..HEAD --no-merges -- ${pkg.location}`
53+
: `git log --format=%B%n-hash-%n%H%n${DELIMITER} ${latestTag}..HEAD --no-merges`;
54+
const gitLog = exec(gitLogCommand, { silent: true })
55+
.stdout.split(`${DELIMITER}${os.EOL}`)
56+
.filter((c) => !!c);
57+
const readable = Readable.from(gitLog);
58+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
59+
// @ts-ignore because the type exported from conventionalCommitsParser is wrong
60+
const parser = readable.pipe(conventionalCommitsParser(configuration.parserOpts));
61+
const allCommits: Commit[] = [];
62+
parser.on('data', (commit: Commit) => allCommits.push(commit));
63+
parser.on('finish', () => resolve(allCommits));
64+
});
65+
66+
const nextVersionIsHardcoded = pkg.nextVersionIsHardcoded();
67+
// All commits are releasable if the version hardcoded in the package.json
68+
// In this scenario, we want to publish regardless of the commit types
69+
if (nextVersionIsHardcoded) {
70+
return {
71+
releasableCommits: commits,
72+
unreleasableCommits: [],
73+
nextVersionIsHardcoded,
74+
shouldRelease: true,
75+
};
76+
}
77+
78+
const releasableCommits: Commit[] = [];
79+
const unreleasableCommits: Commit[] = [];
80+
for (const commit of commits) {
81+
const headerIndicatesMajorChange = !!commit.header && commit.header.includes('!');
82+
const bodyIndicatesMajorChange = !!commit.body && commit.body.includes('BREAKING');
83+
const typeIsSkippable = skippableCommitTypes.includes(commit.type);
84+
const isReleasable = !typeIsSkippable || bodyIndicatesMajorChange || headerIndicatesMajorChange;
85+
if (isReleasable) {
86+
releasableCommits.push(commit);
87+
} else {
88+
unreleasableCommits.push(commit);
89+
}
90+
}
91+
92+
return {
93+
releasableCommits,
94+
unreleasableCommits,
95+
nextVersionIsHardcoded,
96+
shouldRelease: nextVersionIsHardcoded || releasableCommits.length > 0,
97+
};
98+
}

src/package.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77
import * as path from 'path';
8-
import { exec } from 'shelljs';
8+
import { exec, pwd } from 'shelljs';
99
import { fs, Logger, SfdxError } from '@salesforce/core';
1010
import { AsyncOptionalCreatable } from '@salesforce/kit';
1111
import { AnyJson, get } from '@salesforce/ts-types';
@@ -57,9 +57,9 @@ export class Package extends AsyncOptionalCreatable {
5757
private nextVersion: string;
5858
private registry: Registry;
5959

60-
public constructor(location?: string) {
60+
public constructor(location: string) {
6161
super();
62-
this.location = location;
62+
this.location = location || pwd().stdout;
6363
this.registry = new Registry();
6464
}
6565

0 commit comments

Comments
 (0)