Skip to content

Commit 521138a

Browse files
Wr/deploy report (#67)
* fix: add deploy:report v1 * fix: move progress bar and deploy reporting * chore: fix stub * chore: review 1 * chore: fix pb stub * chore: fix pb final tick * chore: update validateddeployrequestid json Co-authored-by: Steve Hetzel <[email protected]>
1 parent 6aaf973 commit 521138a

File tree

13 files changed

+841
-199
lines changed

13 files changed

+841
-199
lines changed

CHANGELOG.md

+14-20
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,48 @@ All notable changes to this project will be documented in this file. See [standa
44

55
### [0.0.8](https://github.com/salesforcecli/plugin-source/compare/v0.0.7...v0.0.8) (2021-04-13)
66

7-
87
### Features
98

10-
* support split custom labels ([#62](https://github.com/salesforcecli/plugin-source/issues/62)) ([ab290a7](https://github.com/salesforcecli/plugin-source/commit/ab290a78fcdb5e4d8da2fbdcfc3e49e783e848ac))
9+
- support split custom labels ([#62](https://github.com/salesforcecli/plugin-source/issues/62)) ([ab290a7](https://github.com/salesforcecli/plugin-source/commit/ab290a78fcdb5e4d8da2fbdcfc3e49e783e848ac))
1110

1211
### [0.0.7](https://github.com/salesforcecli/plugin-source/compare/v0.0.6...v0.0.7) (2021-04-09)
1312

14-
1513
### Bug Fixes
1614

17-
* add deploy:cancel ([#66](https://github.com/salesforcecli/plugin-source/issues/66)) ([1e673a2](https://github.com/salesforcecli/plugin-source/commit/1e673a28943d306f85baa1728e9f438b570cc0e3))
15+
- add deploy:cancel ([#66](https://github.com/salesforcecli/plugin-source/issues/66)) ([1e673a2](https://github.com/salesforcecli/plugin-source/commit/1e673a28943d306f85baa1728e9f438b570cc0e3))
1816

1917
### [0.0.6](https://github.com/salesforcecli/plugin-source/compare/v0.0.5...v0.0.6) (2021-04-09)
2018

21-
2219
### Bug Fixes
2320

24-
* add progress bar to deploy ([#65](https://github.com/salesforcecli/plugin-source/issues/65)) ([df2f5e0](https://github.com/salesforcecli/plugin-source/commit/df2f5e0de2dea2d509d4b0a3c0ceae8cc75411b9))
21+
- add progress bar to deploy ([#65](https://github.com/salesforcecli/plugin-source/issues/65)) ([df2f5e0](https://github.com/salesforcecli/plugin-source/commit/df2f5e0de2dea2d509d4b0a3c0ceae8cc75411b9))
2522

2623
### [0.0.5](https://github.com/salesforcecli/plugin-source/compare/v0.0.4...v0.0.5) (2021-04-07)
2724

28-
2925
### Bug Fixes
3026

31-
* add convert command ([#64](https://github.com/salesforcecli/plugin-source/issues/64)) ([26e36b2](https://github.com/salesforcecli/plugin-source/commit/26e36b22f0402b9927834ecda63f24dc65f66d96))
27+
- add convert command ([#64](https://github.com/salesforcecli/plugin-source/issues/64)) ([26e36b2](https://github.com/salesforcecli/plugin-source/commit/26e36b22f0402b9927834ecda63f24dc65f66d96))
3228

3329
### [0.0.4](https://github.com/salesforcecli/plugin-source/compare/v0.0.3...v0.0.4) (2021-04-05)
3430

3531
### [0.0.3](https://github.com/salesforcecli/plugin-source/compare/v0.0.2...v0.0.3) (2021-04-02)
3632

3733
### [0.0.2](https://github.com/salesforcecli/plugin-source/compare/v0.0.1...v0.0.2) (2021-03-03)
3834

39-
4035
### Bug Fixes
4136

42-
* add initial NUTs, u-tests ([ca2076c](https://github.com/salesforcecli/plugin-source/commit/ca2076ca7ee1c9b0dcd23e096569006e33ecd149))
43-
* add retrieve via packageNames param ([2fb3217](https://github.com/salesforcecli/plugin-source/commit/2fb32170044d3d39295f2006ab6ab73a09260b43))
44-
* add wait to retrieve, move min wait and default wait to static members ([74a3cdd](https://github.com/salesforcecli/plugin-source/commit/74a3cddcb3d2688068f856d767e08b59d83d8adf))
45-
* deploy first pass ([c6665ab](https://github.com/salesforcecli/plugin-source/commit/c6665abc3fcbf381ccbdc87f40bc97b959a0d2f0))
46-
* fix sorting logic ([70876e3](https://github.com/salesforcecli/plugin-source/commit/70876e3edb2f2a5169a29e2ede011608fac81bc0))
47-
* fixed some of Steve's comments ([4596da6](https://github.com/salesforcecli/plugin-source/commit/4596da6863866236c890a993fd111ff58a092aa9))
48-
* match library changes for deploy ([abba216](https://github.com/salesforcecli/plugin-source/commit/abba216ffb323111837e1621a7e4ef92525eb404))
49-
* remove packagename, change some types ([b1d8b82](https://github.com/salesforcecli/plugin-source/commit/b1d8b82533e0df0b8b9d13306bbc1c0c7cbbfbd1))
50-
* source:retrieve working as a user, json and hook info wrong, missing tests ([7828c3f](https://github.com/salesforcecli/plugin-source/commit/7828c3fa64515b71c1ec6641efd79cdfe10b40da))
37+
- add initial NUTs, u-tests ([ca2076c](https://github.com/salesforcecli/plugin-source/commit/ca2076ca7ee1c9b0dcd23e096569006e33ecd149))
38+
- add retrieve via packageNames param ([2fb3217](https://github.com/salesforcecli/plugin-source/commit/2fb32170044d3d39295f2006ab6ab73a09260b43))
39+
- add wait to retrieve, move min wait and default wait to static members ([74a3cdd](https://github.com/salesforcecli/plugin-source/commit/74a3cddcb3d2688068f856d767e08b59d83d8adf))
40+
- deploy first pass ([c6665ab](https://github.com/salesforcecli/plugin-source/commit/c6665abc3fcbf381ccbdc87f40bc97b959a0d2f0))
41+
- fix sorting logic ([70876e3](https://github.com/salesforcecli/plugin-source/commit/70876e3edb2f2a5169a29e2ede011608fac81bc0))
42+
- fixed some of Steve's comments ([4596da6](https://github.com/salesforcecli/plugin-source/commit/4596da6863866236c890a993fd111ff58a092aa9))
43+
- match library changes for deploy ([abba216](https://github.com/salesforcecli/plugin-source/commit/abba216ffb323111837e1621a7e4ef92525eb404))
44+
- remove packagename, change some types ([b1d8b82](https://github.com/salesforcecli/plugin-source/commit/b1d8b82533e0df0b8b9d13306bbc1c0c7cbbfbd1))
45+
- source:retrieve working as a user, json and hook info wrong, missing tests ([7828c3f](https://github.com/salesforcecli/plugin-source/commit/7828c3fa64515b71c1ec6641efd79cdfe10b40da))
5146

5247
### 0.0.1 (2021-02-08)
5348

54-
5549
### Bug Fixes
5650

57-
* add command files, test files, message files, remove template ([598ff29](https://github.com/salesforcecli/plugin-source/commit/598ff29125185b1644fc5c009bcb4cf56115fb31))
51+
- add command files, test files, message files, remove template ([598ff29](https://github.com/salesforcecli/plugin-source/commit/598ff29125185b1644fc5c009bcb4cf56115fb31))

command-snapshot.json

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
"plugin": "@salesforce/plugin-source",
4343
"flags": ["apiversion", "jobid", "json", "loglevel", "targetusername", "wait"]
4444
},
45+
{
46+
"command": "force:source:deploy:report",
47+
"plugin": "@salesforce/plugin-source",
48+
"flags": ["apiversion", "jobid", "json", "loglevel", "targetusername", "wait"]
49+
},
4550
{
4651
"command": "force:source:retrieve",
4752
"plugin": "@salesforce/plugin-source",

messages/report.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"description": "check the status of a metadata deployment",
3+
"examples": [
4+
"Deploy a directory of files to the org",
5+
" $ sfdx force:source:deploy -d <directory>",
6+
"Now cancel this deployment and wait two minutes",
7+
" $ sfdx force:source:deploy:cancel -w 2",
8+
9+
"If you have multiple deployments in progress and want to cancel a specific one, specify the job ID",
10+
" $ sfdx force:source:deploy:cancel -i <jobid>",
11+
"Check the status of the cancel job",
12+
" $ sfdx force:source:deploy:report"
13+
],
14+
"flags": {
15+
"jobid": "job ID of the deployment you want to check; defaults to your most recent CLI deployment if not specified",
16+
"wait": "wait time for command to finish in minutes"
17+
}
18+
}

src/commands/force/source/deploy.ts

+19-27
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ import { flags, FlagsConfig } from '@salesforce/command';
1111
import { Lifecycle, Messages } from '@salesforce/core';
1212
import { DeployResult, MetadataApiDeploy } from '@salesforce/source-deploy-retrieve';
1313
import { Duration } from '@salesforce/kit';
14-
import { asString, asArray, getBoolean, JsonCollection } from '@salesforce/ts-types';
14+
import { asString, asArray, getBoolean } from '@salesforce/ts-types';
1515
import * as chalk from 'chalk';
16-
import cli from 'cli-ux';
1716
import { env } from '@salesforce/kit';
1817
import { SourceCommand } from '../../../sourceCommand';
1918

@@ -96,13 +95,16 @@ export class Deploy extends SourceCommand {
9695
};
9796
protected readonly lifecycleEventNames = ['predeploy', 'postdeploy'];
9897

99-
public async run(): Promise<DeployResult | JsonCollection> {
98+
public async run(): Promise<DeployResult> {
10099
if (this.flags.validateddeployrequestid) {
100+
const id = asString(this.flags.validateddeployrequestid);
101+
101102
const conn = this.org.getConnection();
102-
return conn.deployRecentValidation({
103-
id: this.flags.validateddeployrequestid as string,
103+
await conn.deployRecentValidation({
104+
id,
104105
rest: !this.flags.soapdeploy,
105106
});
107+
return this.deployReport(id);
106108
}
107109

108110
const hookEmitter = Lifecycle.getInstance();
@@ -126,8 +128,9 @@ export class Deploy extends SourceCommand {
126128
},
127129
});
128130

129-
// if SFDX_USE_PROGRESS_BAR is true and no --json flag use progress bar, if not, skip
131+
// if SFDX_USE_PROGRESS_BAR is unset or true (default true) AND we're not print JSON output
130132
if (env.getBoolean('SFDX_USE_PROGRESS_BAR', true) && !this.flags.json) {
133+
this.initProgressBar();
131134
this.progress(deploy);
132135
}
133136

@@ -147,47 +150,36 @@ export class Deploy extends SourceCommand {
147150
}
148151

149152
private progress(deploy: MetadataApiDeploy): void {
150-
// cli.progress doesn't have typings
151-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
152-
const progressBar = cli.progress({
153-
format: 'SOURCE PROGRESS | {bar} | {value}/{total} Components',
154-
barCompleteChar: '\u2588',
155-
barIncompleteChar: '\u2591',
156-
linewrap: true,
157-
});
158153
let printOnce = true;
159154
deploy.onUpdate((data) => {
160155
// the numCompTot. isn't computed right away, wait to start until we know how many we have
161156
if (data.numberComponentsTotal && printOnce) {
162157
this.ux.log(`Job ID | ${data.id}`);
163-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
164-
progressBar.start(data.numberComponentsTotal + data.numberTestsTotal);
158+
this.progressBar.start(data.numberComponentsTotal + data.numberTestsTotal);
165159
printOnce = false;
166160
}
167161

168162
// the numTestsTot. isn't computed until validated as tests by the server, update the PB once we know
169163
if (data.numberTestsTotal) {
170-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
171-
progressBar.setTotal(data.numberComponentsTotal + data.numberTestsTotal);
164+
this.progressBar.setTotal(data.numberComponentsTotal + data.numberTestsTotal);
172165
}
173166

174-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call
175-
progressBar.update(data.numberComponentsDeployed + data.numberTestsCompleted);
167+
this.progressBar.update(data.numberComponentsDeployed + data.numberTestsCompleted);
176168
});
177169

178-
deploy.onFinish(() => {
179-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
180-
progressBar.stop();
170+
// any thing else should stop the progress bar
171+
deploy.onFinish((data) => {
172+
// the final tick of `onUpdate` is actually fired with `onFinish`
173+
this.progressBar.update(data.response.numberComponentsDeployed + data.response.numberTestsCompleted);
174+
this.progressBar.stop();
181175
});
182176

183177
deploy.onCancel(() => {
184-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
185-
progressBar.stop();
178+
this.progressBar.stop();
186179
});
187180

188181
deploy.onError(() => {
189-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
190-
progressBar.stop();
182+
this.progressBar.stop();
191183
});
192184
}
193185

src/commands/force/source/deploy/cancel.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ export class Cancel extends SourceCommand {
4141
id = asString((stash.get(SourceCommand.STASH_KEY) as { jobid: string }).jobid);
4242
}
4343

44+
// first cancel the deploy
4445
// TODO: update to use SDRL we can just do this for now
4546
// this is the toolbelt implementation
4647
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment
47-
return (await this.org.getConnection().metadata['_invoke']('cancelDeploy', {
48+
await this.org.getConnection().metadata['_invoke']('cancelDeploy', {
4849
id,
49-
})) as DeployResult;
50+
});
51+
52+
// then print the status of the cancelled deploy
53+
return this.deployReport(id);
5054
}
5155
}
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
import * as os from 'os';
8+
import { Messages } from '@salesforce/core';
9+
import { flags, FlagsConfig } from '@salesforce/command';
10+
import { Duration } from '@salesforce/kit';
11+
import { DeployResult } from '@salesforce/source-deploy-retrieve';
12+
import { SourceCommand } from '../../../../sourceCommand';
13+
14+
Messages.importMessagesDirectory(__dirname);
15+
const messages = Messages.loadMessages('@salesforce/plugin-source', 'report');
16+
17+
export class Report extends SourceCommand {
18+
public static readonly description = messages.getMessage('description');
19+
public static readonly examples = messages.getMessage('examples').split(os.EOL);
20+
public static readonly requiresUsername = true;
21+
public static readonly flagsConfig: FlagsConfig = {
22+
wait: flags.minutes({
23+
char: 'w',
24+
default: Duration.minutes(SourceCommand.DEFAULT_SRC_WAIT_MINUTES),
25+
min: Duration.minutes(1),
26+
description: messages.getMessage('flags.wait'),
27+
}),
28+
jobid: flags.id({
29+
char: 'i',
30+
description: messages.getMessage('flags.jobid'),
31+
}),
32+
};
33+
34+
public async run(): Promise<DeployResult> {
35+
return this.deployReport(this.flags.jobid);
36+
}
37+
}

0 commit comments

Comments
 (0)