Skip to content

Commit

Permalink
feat: zipSize and zipFileCount in DeployResult (#1138)
Browse files Browse the repository at this point in the history
* feat: handle event from SDR to display zip file size and file count

* feat: zipSize and zipFileCount in DeployResult

* test: tests for verbose zip file size and file count

* test: tests for verbose zip file size and file count

* fix: always add zipSize and zipFileCount to JSON

* chore: bump SDR

* fix: check size range to allow for OS differences

---------

Co-authored-by: Cristian Dominguez <[email protected]>
  • Loading branch information
shetzel and cristiand391 authored Aug 27, 2024
1 parent 06b3982 commit a03a580
Show file tree
Hide file tree
Showing 13 changed files with 255 additions and 40 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@salesforce/kit": "^3.2.1",
"@salesforce/plugin-info": "^3.3.28",
"@salesforce/sf-plugins-core": "^11.3.2",
"@salesforce/source-deploy-retrieve": "^12.5.1",
"@salesforce/source-deploy-retrieve": "^12.6.0",
"@salesforce/source-tracking": "^7.1.7",
"@salesforce/ts-types": "^2.0.12",
"ansis": "^3.3.2"
Expand Down
22 changes: 17 additions & 5 deletions schemas/project-deploy-cancel.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
"type": "object",
"additionalProperties": false,
"properties": {
"files": {
"type": "array",
"items": {
"$ref": "#/definitions/FileResponse"
}
},
"replacements": {
"type": "object",
"additionalProperties": {
Expand All @@ -17,11 +23,11 @@
}
}
},
"files": {
"type": "array",
"items": {
"$ref": "#/definitions/FileResponse"
}
"zipSize": {
"type": "number"
},
"zipFileCount": {
"type": "number"
},
"id": {
"type": "string"
Expand Down Expand Up @@ -496,6 +502,12 @@
"$ref": "#/definitions/FileResponse"
}
},
"zipSize": {
"type": "number"
},
"zipFileCount": {
"type": "number"
},
"canceledBy": {
"type": "string"
},
Expand Down
22 changes: 17 additions & 5 deletions schemas/project-deploy-quick.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
"type": "object",
"additionalProperties": false,
"properties": {
"files": {
"type": "array",
"items": {
"$ref": "#/definitions/FileResponse"
}
},
"replacements": {
"type": "object",
"additionalProperties": {
Expand All @@ -17,11 +23,11 @@
}
}
},
"files": {
"type": "array",
"items": {
"$ref": "#/definitions/FileResponse"
}
"zipSize": {
"type": "number"
},
"zipFileCount": {
"type": "number"
},
"id": {
"type": "string"
Expand Down Expand Up @@ -496,6 +502,12 @@
"$ref": "#/definitions/FileResponse"
}
},
"zipSize": {
"type": "number"
},
"zipFileCount": {
"type": "number"
},
"canceledBy": {
"type": "string"
},
Expand Down
22 changes: 17 additions & 5 deletions schemas/project-deploy-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
"type": "object",
"additionalProperties": false,
"properties": {
"files": {
"type": "array",
"items": {
"$ref": "#/definitions/FileResponse"
}
},
"replacements": {
"type": "object",
"additionalProperties": {
Expand All @@ -17,11 +23,11 @@
}
}
},
"files": {
"type": "array",
"items": {
"$ref": "#/definitions/FileResponse"
}
"zipSize": {
"type": "number"
},
"zipFileCount": {
"type": "number"
},
"id": {
"type": "string"
Expand Down Expand Up @@ -496,6 +502,12 @@
"$ref": "#/definitions/FileResponse"
}
},
"zipSize": {
"type": "number"
},
"zipFileCount": {
"type": "number"
},
"canceledBy": {
"type": "string"
},
Expand Down
22 changes: 17 additions & 5 deletions schemas/project-deploy-resume.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
"type": "object",
"additionalProperties": false,
"properties": {
"files": {
"type": "array",
"items": {
"$ref": "#/definitions/FileResponse"
}
},
"replacements": {
"type": "object",
"additionalProperties": {
Expand All @@ -17,11 +23,11 @@
}
}
},
"files": {
"type": "array",
"items": {
"$ref": "#/definitions/FileResponse"
}
"zipSize": {
"type": "number"
},
"zipFileCount": {
"type": "number"
},
"id": {
"type": "string"
Expand Down Expand Up @@ -496,6 +502,12 @@
"$ref": "#/definitions/FileResponse"
}
},
"zipSize": {
"type": "number"
},
"zipFileCount": {
"type": "number"
},
"canceledBy": {
"type": "string"
},
Expand Down
22 changes: 17 additions & 5 deletions schemas/project-deploy-start.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
"type": "object",
"additionalProperties": false,
"properties": {
"files": {
"type": "array",
"items": {
"$ref": "#/definitions/FileResponse"
}
},
"replacements": {
"type": "object",
"additionalProperties": {
Expand All @@ -17,11 +23,11 @@
}
}
},
"files": {
"type": "array",
"items": {
"$ref": "#/definitions/FileResponse"
}
"zipSize": {
"type": "number"
},
"zipFileCount": {
"type": "number"
},
"id": {
"type": "string"
Expand Down Expand Up @@ -496,6 +502,12 @@
"$ref": "#/definitions/FileResponse"
}
},
"zipSize": {
"type": "number"
},
"zipFileCount": {
"type": "number"
},
"canceledBy": {
"type": "string"
},
Expand Down
22 changes: 17 additions & 5 deletions schemas/project-deploy-validate.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
"type": "object",
"additionalProperties": false,
"properties": {
"files": {
"type": "array",
"items": {
"$ref": "#/definitions/FileResponse"
}
},
"replacements": {
"type": "object",
"additionalProperties": {
Expand All @@ -17,11 +23,11 @@
}
}
},
"files": {
"type": "array",
"items": {
"$ref": "#/definitions/FileResponse"
}
"zipSize": {
"type": "number"
},
"zipFileCount": {
"type": "number"
},
"id": {
"type": "string"
Expand Down Expand Up @@ -496,6 +502,12 @@
"$ref": "#/definitions/FileResponse"
}
},
"zipSize": {
"type": "number"
},
"zipFileCount": {
"type": "number"
},
"canceledBy": {
"type": "string"
},
Expand Down
33 changes: 29 additions & 4 deletions src/commands/project/deploy/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@

import ansis from 'ansis';
import { EnvironmentVariable, Lifecycle, Messages, OrgConfigProperties, SfError } from '@salesforce/core';
import { DeployVersionData } from '@salesforce/source-deploy-retrieve';
import { type DeployVersionData, DeployZipData } from '@salesforce/source-deploy-retrieve';
import { Duration } from '@salesforce/kit';
import { SfCommand, toHelpSection, Flags } from '@salesforce/sf-plugins-core';
import { SourceConflictError } from '@salesforce/source-tracking';
import { AsyncDeployResultFormatter } from '../../../formatters/asyncDeployResultFormatter.js';
import { DeployResultFormatter } from '../../../formatters/deployResultFormatter.js';
import { AsyncDeployResultJson, DeployResultJson, TestLevel } from '../../../utils/types.js';
import { DeployProgress } from '../../../utils/progressBar.js';
import { DeployResultJson, TestLevel } from '../../../utils/types.js';
import { executeDeploy, resolveApi, validateTests, determineExitCode } from '../../../utils/deploy.js';
import { DeployCache } from '../../../utils/deployCache.js';
import { DEPLOY_STATUS_CODES_DESCRIPTIONS } from '../../../utils/errorCodes.js';
import { ConfigVars } from '../../../configMeta.js';
import { coverageFormattersFlag, fileOrDirFlag, testLevelFlag, testsFlag } from '../../../utils/flags.js';
import { writeConflictTable } from '../../../utils/conflicts.js';
import { getOptionalProject } from '../../../utils/project.js';
import { getZipFileSize } from '../../../utils/output.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'deploy.metadata');
Expand Down Expand Up @@ -176,6 +177,9 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {

public static errorCodes = toHelpSection('ERROR CODES', DEPLOY_STATUS_CODES_DESCRIPTIONS);

private zipSize?: number;
private zipFileCount?: number;

public async run(): Promise<DeployResultJson> {
const { flags } = await this.parse(DeployMetadata);
const project = await getOptionalProject();
Expand Down Expand Up @@ -214,6 +218,16 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {
);
});

// eslint-disable-next-line @typescript-eslint/require-await
Lifecycle.getInstance().on('deployZipData', async (zipData: DeployZipData) => {
this.zipSize = zipData.zipSize;
if (flags.verbose && this.zipSize) this.log(`Deploy size: ${getZipFileSize(this.zipSize)} of ~39 MB limit`);
if (zipData.zipFileCount) {
this.zipFileCount = zipData.zipFileCount;
if (flags.verbose && this.zipSize) this.log(`Deployed files count: ${this.zipFileCount} of 10,000 limit`);
}
});

const { deploy } = await executeDeploy(
{
...flags,
Expand All @@ -239,7 +253,8 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {
}
const asyncFormatter = new AsyncDeployResultFormatter(deploy.id);
if (!this.jsonEnabled()) asyncFormatter.display();
return asyncFormatter.getJson();

return this.mixinZipMeta(await asyncFormatter.getJson());
}

new DeployProgress(deploy, this.jsonEnabled()).start();
Expand All @@ -255,7 +270,7 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {

await DeployCache.update(deploy.id, { status: result.response.status });

return formatter.getJson();
return this.mixinZipMeta(await formatter.getJson());
}

protected catch(error: Error | SfError): Promise<never> {
Expand All @@ -281,4 +296,14 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {
}
return super.catch(error);
}

private mixinZipMeta(json: AsyncDeployResultJson | DeployResultJson): AsyncDeployResultJson | DeployResultJson {
if (this.zipSize) {
json.zipSize = this.zipSize;
}
if (this.zipFileCount) {
json.zipFileCount = this.zipFileCount;
}
return json;
}
}
9 changes: 9 additions & 0 deletions src/utils/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ export const exitCodeAsNumber = (): number | undefined => {
}
};

export const getZipFileSize = (bytes: number): string => {
const units = ['B', 'KB', 'MB', 'GB'];
while (bytes > 1024 && units.length) {
bytes /= 1024;
units.shift();
}
return parseFloat(bytes.toFixed(2)) + ' ' + units[0];
};

/** oclif table doesn't like "interface" but likes "type". SDR exports an interface */
export const getFileResponseSuccessProps = (
s: FileResponseSuccess
Expand Down
9 changes: 8 additions & 1 deletion src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export type Verbosity = 'verbose' | 'concise' | 'normal';
export type AsyncDeployResultJson = Omit<Partial<MetadataApiDeployStatus>, 'status'> & {
status: RequestStatus | 'Queued' | 'Nothing to deploy';
files: FileResponse[];
zipSize?: number;
zipFileCount?: number;
};

type ConvertEntry = {
Expand Down Expand Up @@ -72,7 +74,12 @@ export type DeleteSourceJson = {
export type CoverageResultsFileInfo = Record<keyof Partial<typeof DefaultReportOptions>, string>;

export type DeployResultJson =
| (MetadataApiDeployStatus & { files: FileResponse[] } & { replacements?: Record<string, string[]> })
| (MetadataApiDeployStatus & {
files: FileResponse[];
replacements?: Record<string, string[]>;
zipSize?: number;
zipFileCount?: number;
})
| AsyncDeployResultJson;

export type MetadataRetrieveResultJson = Omit<MetadataApiRetrieveStatus, 'zipFile'> & {
Expand Down
Loading

0 comments on commit a03a580

Please sign in to comment.