Skip to content

Commit

Permalink
fix: remove --use-most-recent requirement for deploy cancel/quick/rep…
Browse files Browse the repository at this point in the history
…ort/resume
  • Loading branch information
WillieRuemmele committed Jul 24, 2024
1 parent ed01875 commit cefaf0f
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 83 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^4.0.12",
"@oclif/core": "^4.0.14",
"@salesforce/apex-node": "^7.0.4",
"@salesforce/core": "^8.1.3",
"@salesforce/core": "^8.2.3",
"@salesforce/kit": "^3.1.6",
"@salesforce/plugin-info": "^3.3.19",
"@salesforce/sf-plugins-core": "^11.1.9",
"@salesforce/source-deploy-retrieve": "^12.1.6",
"@salesforce/source-tracking": "^7.0.9",
"@salesforce/plugin-info": "^3.3.21",
"@salesforce/sf-plugins-core": "^11.2.1",
"@salesforce/source-deploy-retrieve": "^12.1.8",
"@salesforce/source-tracking": "^7.1.0",
"@salesforce/ts-types": "^2.0.10",
"ansis": "^3.3.1"
},
Expand Down
9 changes: 6 additions & 3 deletions src/commands/project/deploy/cancel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ export default class DeployMetadataCancel extends SfCommand<DeployResultJson> {
length: 'both',
description: messages.getMessage('flags.job-id.description'),
summary: messages.getMessage('flags.job-id.summary'),
exactlyOne: ['use-most-recent', 'job-id'],
exclusive: ['use-most-recent'],
}),
'use-most-recent': Flags.boolean({
char: 'r',
description: messages.getMessage('flags.use-most-recent.description'),
summary: messages.getMessage('flags.use-most-recent.summary'),
exactlyOne: ['use-most-recent', 'job-id'],
exclusive: ['job-id'],
}),
// we want to allow undefined to use the value from the cache
// eslint-disable-next-line sf-plugin/flag-min-max-default
Expand All @@ -61,7 +61,10 @@ export default class DeployMetadataCancel extends SfCommand<DeployResultJson> {

public async run(): Promise<DeployResultJson> {
const [{ flags }, cache] = await Promise.all([this.parse(DeployMetadataCancel), DeployCache.create()]);
const jobId = cache.resolveLatest(flags['use-most-recent'], flags['job-id']);
const jobId = cache.resolveLatest(
(!flags['use-most-recent'] && !flags['job-id']) || flags['use-most-recent'],
flags['job-id']
);

// cancel don't care about your tracking conflicts
const deployOpts = {
Expand Down
6 changes: 3 additions & 3 deletions src/commands/project/deploy/quick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ export default class DeployMetadataQuick extends SfCommand<DeployResultJson> {
length: 'both',
description: messages.getMessage('flags.job-id.description'),
summary: messages.getMessage('flags.job-id.summary'),
exactlyOne: ['use-most-recent', 'job-id'],
exclusive: ['use-most-recent'],
}),
'target-org': Flags.optionalOrg(),
'use-most-recent': Flags.boolean({
char: 'r',
description: messages.getMessage('flags.use-most-recent.description'),
summary: messages.getMessage('flags.use-most-recent.summary'),
exactlyOne: ['use-most-recent', 'job-id'],
exclusive: ['job-id'],
}),
verbose: Flags.boolean({
summary: messages.getMessage('flags.verbose.summary'),
Expand Down Expand Up @@ -143,7 +143,7 @@ export default class DeployMetadataQuick extends SfCommand<DeployResultJson> {
/** Resolve a job ID for a validated deploy using cache, most recent, or a job ID flag. */
const resolveJobId = (cache: DeployCache, useMostRecentFlag: boolean, jobIdFlag?: string): string => {
try {
return cache.resolveLatest(useMostRecentFlag, jobIdFlag, true);
return cache.resolveLatest((!useMostRecentFlag && jobIdFlag !== undefined) || useMostRecentFlag, jobIdFlag);
} catch (e) {
if (e instanceof Error && e.name === 'NoMatchingJobIdError' && jobIdFlag) {
return jobIdFlag; // Use the specified 15 char job ID
Expand Down
9 changes: 6 additions & 3 deletions src/commands/project/deploy/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ export default class DeployMetadataReport extends SfCommand<DeployResultJson> {
length: 'both',
description: messages.getMessage('flags.job-id.description'),
summary: messages.getMessage('flags.job-id.summary'),
exactlyOne: ['use-most-recent', 'job-id'],
exclusive: ['use-most-recent'],
}),
'use-most-recent': Flags.boolean({
char: 'r',
description: messages.getMessage('flags.use-most-recent.description'),
summary: messages.getMessage('flags.use-most-recent.summary'),
exactlyOne: ['use-most-recent', 'job-id'],
exclusive: ['job-id'],
}),
'coverage-formatters': coverageFormattersFlag({ helpGroup: testFlags }),
junit: Flags.boolean({
Expand All @@ -67,7 +67,10 @@ export default class DeployMetadataReport extends SfCommand<DeployResultJson> {

public async run(): Promise<DeployResultJson> {
const [{ flags }, cache] = await Promise.all([this.parse(DeployMetadataReport), DeployCache.create()]);
const jobId = cache.resolveLatest(flags['use-most-recent'], flags['job-id'], false);
const jobId = cache.resolveLatest(
(!flags['use-most-recent'] && !flags['job-id']) || flags['use-most-recent'],
flags['job-id']
);

const deployOpts = cache.maybeGet(jobId);
const wait = flags['wait'];
Expand Down
9 changes: 6 additions & 3 deletions src/commands/project/deploy/resume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ export default class DeployMetadataResume extends SfCommand<DeployResultJson> {
length: 'both',
description: messages.getMessage('flags.job-id.description'),
summary: messages.getMessage('flags.job-id.summary'),
exactlyOne: ['use-most-recent', 'job-id'],
exclusive: ['use-most-recent'],
}),
'use-most-recent': Flags.boolean({
char: 'r',
description: messages.getMessage('flags.use-most-recent.description'),
summary: messages.getMessage('flags.use-most-recent.summary'),
exactlyOne: ['use-most-recent', 'job-id'],
exclusive: ['job-id'],
}),
verbose: Flags.boolean({
summary: messages.getMessage('flags.verbose.summary'),
Expand Down Expand Up @@ -81,7 +81,10 @@ export default class DeployMetadataResume extends SfCommand<DeployResultJson> {

public async run(): Promise<DeployResultJson> {
const [{ flags }, cache] = await Promise.all([this.parse(DeployMetadataResume), DeployCache.create()]);
const jobId = cache.resolveLatest(flags['use-most-recent'], flags['job-id'], true);
const jobId = cache.resolveLatest(
(!flags['use-most-recent'] && !flags['job-id']) || flags['use-most-recent'],
flags['job-id']
);

// if it was async before, then it should not be async now.
const deployOpts = { ...cache.maybeGet(jobId), async: false };
Expand Down
2 changes: 1 addition & 1 deletion test/commands/deploy/metadata/cancel.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('deploy metadata cancel NUTs', () => {
}
});

it.skip('should cancel most recently started deployment without specifying the flag', () => {
it('should cancel most recently started deployment without specifying the flag', () => {
const first = execCmd<DeployResultJson>(
'deploy:metadata --source-dir force-app --async --ignore-conflicts --json',
{
Expand Down
2 changes: 1 addition & 1 deletion test/commands/deploy/metadata/quick.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('deploy metadata quick NUTs', () => {
await testkit.expect.filesToBeDeployed(['force-app/**/*'], ['force-app/test/**/*']);
});

it.skip('should deploy previously validated deployment without specifying the flag', async () => {
it('should deploy previously validated deployment without specifying the flag', async () => {
const validation = await testkit.execute<DeployResultJson>('project:deploy:validate', {
args: '--source-dir force-app',
json: true,
Expand Down
15 changes: 15 additions & 0 deletions test/commands/deploy/metadata/report.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ describe('[project deploy report] NUTs with source-dir', () => {
assert(isObject(deploy));
await testkit.expect.filesToBeDeployedViaResult(['force-app/**/*'], ['force-app/test/**/*'], deploy.result.files);
});

it('should report most recently started deployment without flag', async () => {
await testkit.execute<DeployResultJson>('project deploy start', {
args: '--source-dir force-app --async',
json: true,
exitCode: 0,
});

const deploy = await testkit.execute<DeployResultJson>('project deploy report', {
json: true,
exitCode: 0,
});
assert(isObject(deploy));
await testkit.expect.filesToBeDeployedViaResult(['force-app/**/*'], ['force-app/test/**/*'], deploy.result.files);
});
});

describe('--job-id', () => {
Expand Down
26 changes: 26 additions & 0 deletions test/commands/deploy/metadata/resume.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,32 @@ describe('[project deploy resume] NUTs', () => {
expect(cacheAfter[first.result.id]).have.property('status');
expect(cacheAfter[first.result.id].status).to.equal(RequestStatus.Succeeded);
});

it('should resume most recently started deployment without flag', async () => {
const first = await testkit.execute<DeployResultJson>('project deploy start', {
args: '--source-dir force-app --async',
json: true,
exitCode: 0,
});
assert(first);
assert(first.result.id);

const cacheBefore = readDeployCache(testkit.projectDir);
expect(cacheBefore).to.have.property(first.result.id);

const deploy = await testkit.execute<DeployResultJson>('project deploy resume', {
json: true,
exitCode: 0,
});
assert(deploy);
await testkit.expect.filesToBeDeployedViaResult(['force-app/**/*'], ['force-app/test/**/*'], deploy.result.files);

const cacheAfter = readDeployCache(testkit.projectDir);

expect(cacheAfter).to.have.property(first.result.id);
expect(cacheAfter[first.result.id]).have.property('status');
expect(cacheAfter[first.result.id].status).to.equal(RequestStatus.Succeeded);
});
});

describe('--job-id', () => {
Expand Down
Loading

0 comments on commit cefaf0f

Please sign in to comment.