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

Sh/deploy zip size #1138

Merged
merged 10 commits into from
Aug 27, 2024
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
Loading