Skip to content

Commit

Permalink
feat: add support for async deploys (#89)
Browse files Browse the repository at this point in the history
* feat: add support for async deploys

* feat: use async SDR in source plugin

* fix: fixes and refactors result output

Fixes result output for retrieve.  Combines common sorting and relative file path conversion.  Fixes
sorting.

* refactor: refactor for SDR changes

* chore: add rest to deploy options - needs SDR publish (#108)

* chore: deploy NUTs (#84)

* chore: deploy NUTs

* chore: disable other NUTs

* chore: make test:nuts test all nuts

* chore: reduce number of redundant tests

* chore: move from nutshell to source-teskit (#85)

* chore: move from nutshell to source-teskit

* chore: try deploy NUTs

* chore: undo try deploy NUTs

* chore: try new way to find package.xml

* chore: undo find package xml

* chore: bump testkit to 0.0.5

* chore: don't throw if cleanup fails

* chore: parallelize NUTs, add wildcard option to retrieve

* chore: add logging when cleanup fails

* chore: update convert, NUTs to use genUniqueDir: false (#88)

* chore: update convert, NUTs to use genUniqueDir: false

* chore: add large executor to windows

* chore: add findAndMove manifest back

* chore: fix convert NUT output dir

* chore: try new approach

* chore: remove .github/autointegrator.yml (#80)

Authored via Leif

* Update README.md

@W-9260305@

* chore(release): 0.0.17 [ci skip]

* chore(deps-dev): bump @typescript-eslint/parser from 4.24.0 to 4.26.0 (#90)

* chore(deps-dev): bump @typescript-eslint/parser from 4.24.0 to 4.26.0

Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 4.24.0 to 4.26.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v4.26.0/packages/parser)

Signed-off-by: dependabot[bot] <[email protected]>

* chore(deps-dev): bump sinon from 9.2.4 to 11.1.1

Bumps [sinon](https://github.com/sinonjs/sinon) from 9.2.4 to 11.1.1.
- [Release notes](https://github.com/sinonjs/sinon/releases)
- [Changelog](https://github.com/sinonjs/sinon/blob/master/CHANGELOG.md)
- [Commits](sinonjs/sinon@v9.2.4...v11.1.1)

Signed-off-by: dependabot[bot] <[email protected]>

* chore(deps-dev): bump @typescript-eslint/eslint-plugin

Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 4.24.0 to 4.26.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v4.26.0/packages/eslint-plugin)

Signed-off-by: dependabot[bot] <[email protected]>

* chore: update yarn.lock

* chore: pin sinon to v10.0.0

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Peter Hale <[email protected]>

* chore: dependabot combined changes (#105)

* chore: bump dep versions

# Conflicts:
#	package.json

* chore: bump dev-scripts

# Conflicts:
#	yarn.lock

* chore: update yarn lock

* chore(deps-dev): bump @oclif/plugin-command-snapshot from 2.0.0 to 2.1.2 (#106)

Bumps [@oclif/plugin-command-snapshot](https://github.com/oclif/plugin-command-snapshot) from 2.0.0 to 2.1.2.
- [Release notes](https://github.com/oclif/plugin-command-snapshot/releases)
- [Changelog](https://github.com/oclif/plugin-command-snapshot/blob/master/CHANGELOG.md)
- [Commits](oclif/plugin-command-snapshot@v2.0.0...v2.1.2)

---
updated-dependencies:
- dependency-name: "@oclif/plugin-command-snapshot"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore: add rest to deploy options - needs SDR publish

* chore: default to SOAP

Co-authored-by: Benjamin <[email protected]>
Co-authored-by: Steve Hetzel <[email protected]>
Co-authored-by: SF-CLI-BOT <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Peter Hale <[email protected]>
Co-authored-by: peternhale <[email protected]>

* fix: change the frequency to match deploy

* refactor: bump retrieve frequency to 1 second

* chore: enable async NUTs, logic for different deploy states when cancelling/reporting

Co-authored-by: Willie Ruemmele <[email protected]>
Co-authored-by: Benjamin <[email protected]>
Co-authored-by: SF-CLI-BOT <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Peter Hale <[email protected]>
Co-authored-by: peternhale <[email protected]>
  • Loading branch information
7 people authored Jun 12, 2021
1 parent 664a00a commit e7d7215
Show file tree
Hide file tree
Showing 22 changed files with 389 additions and 222 deletions.
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ sfdx plugins
# Usage

<!-- usage -->

```sh-session
$ npm install -g @salesforce/plugin-source
$ sfdx COMMAND
Expand All @@ -86,16 +87,18 @@ USAGE
$ sfdx COMMAND
...
```

<!-- usagestop -->

# Commands

<!-- commands -->
* [`sfdx force:source:convert [-r <directory>] [-d <directory>] [-n <string>] [-p <array> | -x <string> | -m <array>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-forcesourceconvert--r-directory--d-directory--n-string--p-array---x-string---m-array---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
* [`sfdx force:source:deploy [--soapdeploy] [-w <minutes>] [-q <id> | -x <filepath> | -m <array> | -p <array> | -c | -l NoTestRun|RunSpecifiedTests|RunLocalTests|RunAllTestsInOrg | -r <array> | -o | -g] [-u <string>] [--apiversion <string>] [--verbose] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-forcesourcedeploy---soapdeploy--w-minutes--q-id---x-filepath---m-array---p-array---c---l-notestrunrunspecifiedtestsrunlocaltestsrunalltestsinorg---r-array---o---g--u-string---apiversion-string---verbose---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
* [`sfdx force:source:deploy:cancel [-w <minutes>] [-i <id>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-forcesourcedeploycancel--w-minutes--i-id--u-string---apiversion-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
* [`sfdx force:source:deploy:report [-w <minutes>] [-i <id>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-forcesourcedeployreport--w-minutes--i-id--u-string---apiversion-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
* [`sfdx force:source:retrieve [-p <array> | -x <filepath> | -m <array>] [-w <minutes>] [-n <array>] [-u <string>] [-a <string>] [--verbose] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-forcesourceretrieve--p-array---x-filepath---m-array--w-minutes--n-array--u-string--a-string---verbose---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)

- [`sfdx force:source:convert [-r <directory>] [-d <directory>] [-n <string>] [-p <array> | -x <string> | -m <array>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-forcesourceconvert--r-directory--d-directory--n-string--p-array---x-string---m-array---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
- [`sfdx force:source:deploy [--soapdeploy] [-w <minutes>] [-q <id> | -x <filepath> | -m <array> | -p <array> | -c | -l NoTestRun|RunSpecifiedTests|RunLocalTests|RunAllTestsInOrg | -r <array> | -o | -g] [-u <string>] [--apiversion <string>] [--verbose] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-forcesourcedeploy---soapdeploy--w-minutes--q-id---x-filepath---m-array---p-array---c---l-notestrunrunspecifiedtestsrunlocaltestsrunalltestsinorg---r-array---o---g--u-string---apiversion-string---verbose---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
- [`sfdx force:source:deploy:cancel [-w <minutes>] [-i <id>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-forcesourcedeploycancel--w-minutes--i-id--u-string---apiversion-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
- [`sfdx force:source:deploy:report [-w <minutes>] [-i <id>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-forcesourcedeployreport--w-minutes--i-id--u-string---apiversion-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
- [`sfdx force:source:retrieve [-p <array> | -x <filepath> | -m <array>] [-w <minutes>] [-n <array>] [-u <string>] [-a <string>] [--verbose] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-forcesourceretrieve--p-array---x-filepath---m-array--w-minutes--n-array--u-string--a-string---verbose---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)

## `sfdx force:source:convert [-r <directory>] [-d <directory>] [-n <string>] [-p <array> | -x <string> | -m <array>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`

Expand All @@ -105,7 +108,7 @@ convert source into Metadata API format
convert source into Metadata API format
USAGE
$ sfdx force:source:convert [-r <directory>] [-d <directory>] [-n <string>] [-p <array> | -x <string> | -m <array>]
$ sfdx force:source:convert [-r <directory>] [-d <directory>] [-n <string>] [-p <array> | -x <string> | -m <array>]
[--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
OPTIONS
Expand Down Expand Up @@ -148,8 +151,8 @@ deploy source to an org
deploy source to an org
USAGE
$ sfdx force:source:deploy [--soapdeploy] [-w <minutes>] [-q <id> | -x <filepath> | -m <array> | -p <array> | -c | -l
NoTestRun|RunSpecifiedTests|RunLocalTests|RunAllTestsInOrg | -r <array> | -o | -g] [-u <string>] [--apiversion
$ sfdx force:source:deploy [--soapdeploy] [-w <minutes>] [-q <id> | -x <filepath> | -m <array> | -p <array> | -c | -l
NoTestRun|RunSpecifiedTests|RunLocalTests|RunAllTestsInOrg | -r <array> | -o | -g] [-u <string>] [--apiversion
<string>] [--verbose] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
OPTIONS
Expand Down Expand Up @@ -223,7 +226,7 @@ cancel a source deployment
cancel a source deployment
USAGE
$ sfdx force:source:deploy:cancel [-w <minutes>] [-i <id>] [-u <string>] [--apiversion <string>] [--json] [--loglevel
$ sfdx force:source:deploy:cancel [-w <minutes>] [-i <id>] [-u <string>] [--apiversion <string>] [--json] [--loglevel
trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
OPTIONS
Expand Down Expand Up @@ -261,7 +264,7 @@ check the status of a metadata deployment
check the status of a metadata deployment
USAGE
$ sfdx force:source:deploy:report [-w <minutes>] [-i <id>] [-u <string>] [--apiversion <string>] [--json] [--loglevel
$ sfdx force:source:deploy:report [-w <minutes>] [-i <id>] [-u <string>] [--apiversion <string>] [--json] [--loglevel
trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
OPTIONS
Expand Down Expand Up @@ -304,7 +307,7 @@ retrieve source from an org
retrieve source from an org
USAGE
$ sfdx force:source:retrieve [-p <array> | -x <filepath> | -m <array>] [-w <minutes>] [-n <array>] [-u <string>] [-a
$ sfdx force:source:retrieve [-p <array> | -x <filepath> | -m <array>] [-w <minutes>] [-n <array>] [-u <string>] [-a
<string>] [--verbose] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
OPTIONS
Expand Down Expand Up @@ -350,4 +353,5 @@ EXAMPLES
```

_See code: [src/commands/force/source/retrieve.ts](https://github.com/salesforcecli/plugin-source/blob/v0.0.18/src/commands/force/source/retrieve.ts)_

<!-- commandsstop -->
2 changes: 1 addition & 1 deletion command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{
"command": "force:source:deploy:report",
"plugin": "@salesforce/plugin-source",
"flags": ["apiversion", "jobid", "json", "loglevel", "targetusername", "wait"]
"flags": ["apiversion", "jobid", "json", "loglevel", "targetusername", "wait", "verbose"]
},
{
"command": "force:source:retrieve",
Expand Down
5 changes: 4 additions & 1 deletion messages/deploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@
"checkOnlySuccess": "Successfully validated the deployment. %s components deployed and %s tests run.\nUse the --verbose parameter to see detailed output.",
"MissingDeployId": "No deploy ID was provided or found in deploy history",
"deployCanceled": "The deployment has been canceled by %s",
"deployFailed": "Deploy failed."
"deployFailed": "Deploy failed.",
"asyncDeployQueued": "Deploy has been queued.",
"asyncDeployCancel": "Run sfdx force:source:deploy:cancel -i %s to cancel the deploy.",
"asyncDeployReport": "Run sfdx force:source:deploy:report -i %s to get the latest status."
}
3 changes: 2 additions & 1 deletion messages/report.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
],
"flags": {
"jobid": "job ID of the deployment you want to check; defaults to your most recent CLI deployment if not specified",
"wait": "wait time for command to finish in minutes"
"wait": "wait time for command to finish in minutes",
"verbose": "verbose output of deploy result"
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "@salesforce/plugin-source",
"description": "Commands to interact with source formatted metadata",
"version": "0.0.19",
"version": "0.1.19",
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/config": "^1",
"@salesforce/command": "^3.1.3",
"@salesforce/core": "^2.23.4",
"@salesforce/source-deploy-retrieve": "^2.1.5",
"@salesforce/source-deploy-retrieve": "^3.0.0",
"chalk": "^4.1.0",
"cli-ux": "^5.5.1",
"tslib": "^2"
Expand Down
4 changes: 2 additions & 2 deletions src/commands/force/source/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class Convert extends SourceCommand {
paths.push(this.project.getDefaultPackage().path);
}

const cs = await ComponentSetBuilder.build({
this.componentSet = await ComponentSetBuilder.build({
sourcepath: paths,
manifest: manifest && {
manifestPath: this.getFlag<string>('manifest'),
Expand All @@ -93,7 +93,7 @@ export class Convert extends SourceCommand {
});

const converter = new MetadataConverter();
this.convertResult = await converter.convert(cs.getSourceComponents().toArray(), 'metadata', {
this.convertResult = await converter.convert(this.componentSet.getSourceComponents().toArray(), 'metadata', {
type: 'directory',
outputDirectory: this.getFlag<string>('outputdir'),
packageName: this.getFlag<string>('packagename'),
Expand Down
117 changes: 60 additions & 57 deletions src/commands/force/source/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@
import * as os from 'os';
import { flags, FlagsConfig } from '@salesforce/command';
import { Messages } from '@salesforce/core';
import { DeployResult, MetadataApiDeploy } from '@salesforce/source-deploy-retrieve';
import { AsyncResult, DeployResult, MetadataApiDeploy } from '@salesforce/source-deploy-retrieve';
import { Duration } from '@salesforce/kit';
import { getString, isString } from '@salesforce/ts-types';
import { env } from '@salesforce/kit';
import { env, once } from '@salesforce/kit';
import { RequestStatus } from '@salesforce/source-deploy-retrieve/lib/src/client/types';
import { DeployCommand } from '../../../deployCommand';
import { ComponentSetBuilder } from '../../../componentSetBuilder';
import {
DeployResultFormatter,
DeployCommandResult,
DeployCommandAsyncResult,
} from '../../../formatters/deployResultFormatter';
import { DeployResultFormatter, DeployCommandResult } from '../../../formatters/deployResultFormatter';
import { DeployAsyncResultFormatter, DeployCommandAsyncResult } from '../../../formatters/deployAsyncResultFormatter';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-source', 'deploy');
Expand Down Expand Up @@ -102,6 +99,12 @@ export class Deploy extends DeployCommand {

private isAsync = false;
private isRest = false;
private asyncDeployResult: AsyncResult;

private updateDeployId = once((id) => {
this.displayDeployId(id);
this.setStash(id);
});

public async run(): Promise<DeployCommandResult | DeployCommandAsyncResult> {
await this.deploy();
Expand All @@ -114,15 +117,15 @@ export class Deploy extends DeployCommand {
// 2. asynchronous - deploy metadata and immediately return.
// 3. recent validation - deploy metadata that's already been validated by the org
protected async deploy(): Promise<void> {
this.isAsync = this.getFlag<Duration>('wait').quantity === 0;
const waitDuration = this.getFlag<Duration>('wait');
this.isAsync = waitDuration.quantity === 0;
this.isRest = await this.isRestDeploy();
this.ux.log(`*** Deploying with ${this.isRest ? 'REST' : 'SOAP'} API ***`);

if (this.flags.validateddeployrequestid) {
this.deployResult = await this.deployRecentValidation();
} else {
// the deployment involves a component set
const cs = await ComponentSetBuilder.build({
this.componentSet = await ComponentSetBuilder.build({
apiversion: this.getFlag<string>('apiversion'),
sourcepath: this.getFlag<string[]>('sourcepath'),
manifest: this.flags.manifest && {
Expand All @@ -135,57 +138,63 @@ export class Deploy extends DeployCommand {
},
});
// fire predeploy event for sync and async deploys
await this.lifecycle.emit('predeploy', cs.toArray());
if (this.isAsync) {
// This is an async deploy. We just kick off the request.
throw Error('ASYNC DEPLOYS NOT IMPLEMENTED YET');
} else {
const deploy = cs.deploy({
usernameOrConnection: this.org.getUsername(),
apiOptions: {
ignoreWarnings: this.getFlag<boolean>('ignorewarnings', false),
rollbackOnError: !this.getFlag<boolean>('ignoreerrors', false),
checkOnly: this.getFlag<boolean>('checkonly', false),
runTests: this.getFlag<string[]>('runtests'),
testLevel: this.getFlag<TestLevel>('testlevel', 'NoTestRun'),
},
});
await this.lifecycle.emit('predeploy', this.componentSet.toArray());

const deploy = await this.componentSet.deploy({
usernameOrConnection: this.org.getUsername(),
apiOptions: {
ignoreWarnings: this.getFlag<boolean>('ignorewarnings', false),
rollbackOnError: !this.getFlag<boolean>('ignoreerrors', false),
checkOnly: this.getFlag<boolean>('checkonly', false),
runTests: this.getFlag<string[]>('runtests'),
testLevel: this.getFlag<TestLevel>('testlevel'),
rest: this.isRest,
},
});
this.asyncDeployResult = { id: deploy.id };
this.updateDeployId(deploy.id);

if (!this.isAsync) {
// if SFDX_USE_PROGRESS_BAR is unset or true (default true) AND we're not print JSON output
if (env.getBoolean('SFDX_USE_PROGRESS_BAR', true) && !this.isJsonOutput()) {
this.initProgressBar();
this.progress(deploy);
}

this.deployResult = await deploy.start();
this.deployResult = await deploy.pollStatus(500, waitDuration.seconds);
}
}

await this.lifecycle.emit('postdeploy', this.deployResult);

const deployId = getString(this.deployResult, 'response.id');
if (deployId) {
this.displayDeployId(deployId);
const file = this.getStash();
// TODO: I think we should stash the ID as soon as we know it.
this.logger.debug(`Stashing deploy ID: ${deployId}`);
await file.write({ [DeployCommand.STASH_KEY]: { jobid: deployId } });
if (this.deployResult) {
// Only fire the postdeploy event when we have results. I.e., not async.
await this.lifecycle.emit('postdeploy', this.deployResult);
}
}

/**
* Checks the response status to determine whether the deploy was successful.
* Async deploys are successful unless an error is thrown, which resolves as
* unsuccessful in oclif.
*/
protected resolveSuccess(): void {
const status = getString(this.deployResult, 'response.status');
if (status !== RequestStatus.Succeeded) {
this.setExitCode(1);
if (!this.isAsync) {
const status = getString(this.deployResult, 'response.status');
if (status !== RequestStatus.Succeeded) {
this.setExitCode(1);
}
}
}

protected formatResult(): DeployCommandResult | DeployCommandAsyncResult {
const formatterOptions = {
verbose: this.getFlag<boolean>('verbose', false),
async: this.isAsync,
};
const formatter = new DeployResultFormatter(this.logger, this.ux, formatterOptions, this.deployResult);

let formatter: DeployAsyncResultFormatter | DeployResultFormatter;
if (this.isAsync) {
formatter = new DeployAsyncResultFormatter(this.logger, this.ux, formatterOptions, this.asyncDeployResult);
} else {
formatter = new DeployResultFormatter(this.logger, this.ux, formatterOptions, this.deployResult);
}

// Only display results to console when JSON flag is unset.
if (!this.isJsonOutput()) {
Expand All @@ -199,15 +208,8 @@ export class Deploy extends DeployCommand {
const conn = this.org.getConnection();
const id = this.getFlag<string>('validateddeployrequestid');

// TODO: This is an async call so we need to poll unless `--wait 0`
// See mdapiCheckStatusApi.ts for the toolbelt polling impl.
const response = await conn.deployRecentValidation({ id, rest: this.isRest });

if (!this.isAsync) {
// Remove this and add polling if we need to poll in the plugin.
throw Error('deployRecentValidation polling not yet implemented');
}

// This is the deploy ID of the deployRecentValidation response, not
// the already validated deploy ID (i.e., validateddeployrequestid).
let validatedDeployId: string;
Expand All @@ -218,26 +220,27 @@ export class Deploy extends DeployCommand {
// REST API
validatedDeployId = (response as { id: string }).id;
}
this.updateDeployId(validatedDeployId);

return this.report(validatedDeployId);
return this.isAsync ? this.report(validatedDeployId) : this.poll(validatedDeployId);
}

private progress(deploy: MetadataApiDeploy): void {
let started = false;
const startProgressBar = once((componentTotal: number) => {
this.progressBar.start(componentTotal);
});

deploy.onUpdate((data) => {
// the numCompTot. isn't computed right away, wait to start until we know how many we have
if (data.numberComponentsTotal && !started) {
this.displayDeployId(data.id);
this.progressBar.start(data.numberComponentsTotal + data.numberTestsTotal);
started = true;
if (data.numberComponentsTotal) {
startProgressBar(data.numberComponentsTotal + data.numberTestsTotal);
this.progressBar.update(data.numberComponentsDeployed + data.numberTestsCompleted);
}

// the numTestsTot. isn't computed until validated as tests by the server, update the PB once we know
if (data.numberTestsTotal) {
if (data.numberTestsTotal && data.numberComponentsTotal) {
this.progressBar.setTotal(data.numberComponentsTotal + data.numberTestsTotal);
}

this.progressBar.update(data.numberComponentsDeployed + data.numberTestsCompleted);
});

// any thing else should stop the progress bar
Expand Down
Loading

0 comments on commit e7d7215

Please sign in to comment.