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: allow deploy report on validated deploys #962

Merged
merged 2 commits into from
Apr 8, 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
8 changes: 6 additions & 2 deletions messages/deploy.metadata.report.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Check or poll for the status of a deploy operation.

Deploy operations include standard deploys, quick deploys, deploy validations, and deploy cancellations.

Run this command by either passing it a job ID or specifying the --use-most-recent flag to use the job ID of the most recent deploy operation. If you specify the --wait flag, the command polls for the status every second until the timeout of --wait minutes. If you don't specify the --wait flag, the command simply checks and displays the status of the deploy; the command doesn't poll for the status.
Run this command by either passing it a job ID or specifying the --use-most-recent flag to use the job ID of the most recent deploy operation. If you specify the --wait flag, the command polls for the status every second until the timeout of --wait minutes. If you don't specify the --wait flag, the command simply checks and displays the status of the deploy; the command doesn't poll for the status.

You typically don't specify the --target-org flag because the cached job already references the org to which you deployed. But if you run this command on a computer different than the one from which you deployed, then you must specify the --target-org and it must point to the same org.
You typically don't specify the --target-org flag because the cached job already references the org to which you deployed. But if you run this command on a computer different than the one from which you deployed, then you must specify the --target-org and it must point to the same org.

This command doesn't update source tracking information.

Expand Down Expand Up @@ -56,3 +56,7 @@ Output JUnit test results.
# flags.results-dir.summary

Output directory for code coverage and JUnit results; defaults to the deploy ID.

# noOrgError

No environment found. Use -o or --target-org to specify an environment
12 changes: 9 additions & 3 deletions src/commands/project/deploy/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { Messages, Org, SfProject } from '@salesforce/core';
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
import { ComponentSet, DeployResult, MetadataApiDeploy } from '@salesforce/source-deploy-retrieve';
import { ComponentSet, DeployResult, MetadataApiDeploy, RequestStatus } from '@salesforce/source-deploy-retrieve';
import { buildComponentSet } from '../../../utils/deploy.js';
import { DeployProgress } from '../../../utils/progressBar.js';
import { DeployCache } from '../../../utils/deployCache.js';
Expand Down Expand Up @@ -79,10 +79,15 @@ export default class DeployMetadataReport extends SfCommand<DeployResultJson> {
? await Org.create({ aliasOrUsername: deployOpts['target-org'] })
: flags['target-org'];

if (!org) {
// if we don't find an org from flags, config, or the cache, throw an error
throw messages.createError('noOrgError');
}

// if we're using mdapi we won't have a component set
let componentSet = new ComponentSet();
if (!deployOpts?.isMdapi) {
if (!cache.maybeGet(jobId)) {
if (!deployOpts) {
// If the cache file isn't there, use the project package directories for the CompSet
try {
this.project = await SfProject.resolve();
Expand All @@ -91,7 +96,8 @@ export default class DeployMetadataReport extends SfCommand<DeployResultJson> {
} catch (err) {
// ignore the error. this was just to get improved command output.
}
} else {
} else if (deployOpts.status !== RequestStatus.Succeeded) {
// if it's succeeded, the deployOpts can't be used to build a CS - nor do we need one
componentSet = await buildComponentSet({ ...deployOpts, wait });
}
}
Expand Down
58 changes: 58 additions & 0 deletions test/nuts/deploy/report.nut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import * as path from 'node:path';
import { assert, expect } from 'chai';
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { DeployResultJson } from '../../../src/utils/types.js';

describe('project deploy report', () => {
let testkit: TestSession;

before(async () => {
testkit = await TestSession.create({
project: { gitClone: 'https://github.com/trailheadapps/dreamhouse-lwc' },
scratchOrgs: [{ setDefault: true, config: path.join('config', 'project-scratch-def.json') }],
devhubAuthStrategy: 'AUTO',
});
execCmd<DeployResultJson>('project deploy start', {
ensureExitCode: 0,
});
});

after(async () => {
await testkit?.clean();
});

it('can validate / deploy quick / report', () => {
const validate = execCmd<DeployResultJson>('project deploy validate --metadata ApexClass --json', {
ensureExitCode: 0,
}).jsonOutput;
assert(validate);
expect(validate.result.checkOnly).to.be.true;
expect(validate.result.done).to.be.true;
expect(validate.result.success).to.be.true;
const validateId = validate.result.id;

const quick = execCmd<DeployResultJson>(`project deploy quick --job-id ${validateId} --json`, {
ensureExitCode: 0,
}).jsonOutput;
assert(quick);
expect(quick.result.checkOnly).to.be.false;
expect(quick.result.done).to.be.true;
expect(quick.result.success).to.be.true;
const quickId = quick.result.id;

const report = execCmd<DeployResultJson>(`project deploy report --job-id ${quickId} --json`, {
ensureExitCode: 0,
}).jsonOutput;
assert(report);
expect(report.result.checkOnly).to.be.false;
expect(report.result.done).to.be.true;
expect(report.result.success).to.be.true;
});
});
Loading