Skip to content

Commit

Permalink
Merge branch 'main' into wr/overwriteObjectFile
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Jun 10, 2024
2 parents 429d1ae + 4460cca commit a3542e2
Show file tree
Hide file tree
Showing 15 changed files with 1,145 additions and 2,019 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/create-github-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ on:
- main
- prerelease/**
tags-ignore:
- "*"
- '*'
workflow_dispatch:
inputs:
prerelease:
type: string
description: "Name to use for the prerelease: beta, dev, etc. NOTE: If this is already set in the package.json, it does not need to be passed in here."
description: 'Name to use for the prerelease: beta, dev, etc. NOTE: If this is already set in the package.json, it does not need to be passed in here.'

jobs:
release:
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/releaseWithCoreBundle.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: publish source-deploy-retrieve-bundle
on:
workflow_run:
workflows:
- publish
types:
- completed
workflow_dispatch:
inputs:
branch:
Expand All @@ -10,7 +15,8 @@ on:

jobs:
call-release-workflow:
if: ${{ inputs.branch || (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success')}}
uses: forcedotcom/bundle-publish-scripts/.github/workflows/releaseWithCoreBundle.yml@main
secrets: inherit
with:
branch: ${{ inputs.branch }}
branch: ${{ inputs.branch || 'main' }}
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ jobs:
- 'yarn test:nuts:convert'
- 'yarn test:nuts:deb'
- 'yarn test:nuts:delete'
- 'yarn test:nuts:deploy'
- 'yarn test:nuts:deploy:metadata:manifest'
- 'yarn test:nuts:deploy:metadata:metadata'
- 'yarn test:nuts:deploy:metadata:metadata-dir'
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/testWithCoreBundle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Test With Core Bundle
on:
push:
branches-ignore: [main]

jobs:
build-and-test:
uses: forcedotcom/bundle-publish-scripts/.github/workflows/validateBuildWithCoreBundle.yml@main
secrets: inherit
1,932 changes: 408 additions & 1,524 deletions CHANGELOG.md

Large diffs are not rendered by default.

1,045 changes: 632 additions & 413 deletions METADATA_SUPPORT.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contributing/metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Got questions?

- If you work for Salesforce,
- For general questions, post in [#platform-cli](https://salesforce-internal.slack.com/archives/C01LKDT1P6J)
- For PR reviews, post in [#platform-cli-collaboration](https://salesforce.enterprise.slack.com/archives/C06V045BZD0)
- For PR reviews, post in [#platform-cli-collaboration](https://salesforce.enterprise.slack.com/archives/C06V045BZD0)
- If not, [open an issue](https://github.com/forcedotcom/cli/issues)

## Adding new types to the registry via a script
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@salesforce/source-deploy-retrieve",
"version": "11.6.5",
"version": "11.6.6",
"description": "JavaScript library to run Salesforce metadata deploys and retrieves",
"main": "lib/src/index.js",
"author": "Salesforce",
Expand All @@ -25,7 +25,7 @@
"node": ">=18.0.0"
},
"dependencies": {
"@salesforce/core": "^7.3.9",
"@salesforce/core": "^7.3.12",
"@salesforce/kit": "^3.1.1",
"@salesforce/ts-types": "^2.0.9",
"fast-levenshtein": "^3.0.0",
Expand All @@ -40,8 +40,8 @@
},
"devDependencies": {
"@jsforce/jsforce-node": "^3.2.0",
"@salesforce/cli-plugins-testkit": "^5.3.8",
"@salesforce/dev-scripts": "^9.1.2",
"@salesforce/cli-plugins-testkit": "^5.3.10",
"@salesforce/dev-scripts": "^10.1.0",
"@types/deep-equal-in-any-order": "^1.0.1",
"@types/fast-levenshtein": "^0.0.4",
"@types/graceful-fs": "^4.1.9",
Expand Down
3 changes: 3 additions & 0 deletions src/client/metadataApiDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ export class MetadataApiDeploy extends MetadataTransfer<
this.options = Object.assign({}, options);
this.isRestDeploy = !!options.apiOptions?.rest;
this.registry = options.registry ?? new RegistryAccess();
if (this.mdapiTempDir) {
this.mdapiTempDir = join(this.mdapiTempDir, `${new Date().toISOString()}_deploy`);
}
}

/**
Expand Down
25 changes: 20 additions & 5 deletions src/client/metadataApiRetrieve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 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 { join, parse } from 'node:path';
import fs from 'graceful-fs';
import JSZip from 'jszip';
import { asBoolean, isString } from '@salesforce/ts-types';
Expand Down Expand Up @@ -125,6 +125,9 @@ export class MetadataApiRetrieve extends MetadataTransfer<
public constructor(options: MetadataApiRetrieveOptions) {
super(options);
this.options = Object.assign({}, MetadataApiRetrieve.DEFAULT_OPTIONS, options);
if (this.mdapiTempDir) {
this.mdapiTempDir = join(this.mdapiTempDir, `${new Date().toISOString()}_retrieve`);
}
}

/**
Expand Down Expand Up @@ -172,6 +175,18 @@ export class MetadataApiRetrieve extends MetadataTransfer<
if (isMdapiRetrieve) {
await handleMdapiResponse(this.options, zipFileContents);
} else {
// If mdapiTempDir is set, write the raw retrieve result to the temp dir
if (this.mdapiTempDir && zipFileContents) {
const outputDir = join(this.mdapiTempDir, 'metadata');
fs.mkdirSync(outputDir, { recursive: true });
const mdapiTempOptions = {
usernameOrConnection: this.options.usernameOrConnection,
output: outputDir,
unzip: true,
};
await handleMdapiResponse(mdapiTempOptions, zipFileContents);
}

({ componentSet, partialDeleteFileResponses } = await extract({
zip: zipFileContents,
options: this.options,
Expand Down Expand Up @@ -272,22 +287,22 @@ export type ScopedPostRetrieve = {

const handleMdapiResponse = async (options: MetadataApiRetrieveOptions, zipFileContents: Buffer): Promise<void> => {
const name = options.zipFileName ?? 'unpackaged.zip';
const zipFilePath = path.join(options.output, name);
const zipFilePath = join(options.output, name);
fs.writeFileSync(zipFilePath, zipFileContents);

if (options.unzip) {
const zip = await JSZip.loadAsync(zipFileContents, { base64: true, createFolders: true });
const extractPath = path.join(options.output, path.parse(name).name);
const extractPath = join(options.output, parse(name).name);
fs.mkdirSync(extractPath, { recursive: true });
for (const filePath of Object.keys(zip.files)) {
const zipObj = zip.file(filePath);
if (!zipObj || zipObj?.dir) {
fs.mkdirSync(path.join(extractPath, filePath), { recursive: true });
fs.mkdirSync(join(extractPath, filePath), { recursive: true });
} else {
// eslint-disable-next-line no-await-in-loop
const content = await zipObj?.async('nodebuffer');
if (content) {
fs.writeFileSync(path.join(extractPath, filePath), content);
fs.writeFileSync(join(extractPath, filePath), content);
}
}
}
Expand Down
16 changes: 9 additions & 7 deletions src/client/metadataTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export abstract class MetadataTransfer<
protected components?: ComponentSet;
protected logger: Logger;
protected canceled = false;
protected mdapiTempDir?: string;
private transferId: Options['id'];
private event = new EventEmitter();
private usernameOrConnection: string | Connection;
Expand All @@ -53,6 +54,7 @@ export abstract class MetadataTransfer<
this.apiVersion = apiVersion;
this.transferId = id;
this.logger = Logger.childFromRoot(this.constructor.name);
this.mdapiTempDir = process.env.SF_MDAPI_TEMP_DIR;
}

// if you passed in an id, you don't have to worry about whether there'll be one if you ask for it
Expand Down Expand Up @@ -160,24 +162,24 @@ export abstract class MetadataTransfer<
}

protected async maybeSaveTempDirectory(target: SfdxFileFormat, cs?: ComponentSet): Promise<void> {
const mdapiTempDir = process.env.SF_MDAPI_TEMP_DIR;
if (mdapiTempDir) {
if (this.mdapiTempDir) {
await Lifecycle.getInstance().emitWarning(
'The SF_MDAPI_TEMP_DIR environment variable is set, which may degrade performance'
);
this.logger.debug(
`Converting metadata to: ${mdapiTempDir} because the SF_MDAPI_TEMP_DIR environment variable is set`
`Converting metadata to: ${this.mdapiTempDir} because the SF_MDAPI_TEMP_DIR environment variable is set`
);
try {
const source = cs ?? this.components ?? new ComponentSet();
const converter = new MetadataConverter();
await converter.convert(source, target, {
const outputDirectory = join(this.mdapiTempDir, target);
await new MetadataConverter().convert(source, target, {
type: 'directory',
outputDirectory: mdapiTempDir,
outputDirectory,
genUniqueDir: false,
});
if (target === 'source') {
// for source convert the package.xml isn't included so write it separately
await fs.promises.writeFile(join(mdapiTempDir, 'package.xml'), await source.getPackageXml());
await fs.promises.writeFile(join(outputDirectory, 'package.xml'), await source.getPackageXml());
}
} catch (e) {
this.logger.debug(e);
Expand Down
7 changes: 5 additions & 2 deletions test/client/metadataApiDeploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 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 { basename, join } from 'node:path';
import { basename, join, sep } from 'node:path';
import { MockTestOrgData, TestContext } from '@salesforce/core/testSetup';
import chai, { assert, expect } from 'chai';
import { AnyJson, getString } from '@salesforce/ts-types';
Expand Down Expand Up @@ -100,7 +100,10 @@ describe('MetadataApiDeploy', () => {

expect(deployStub.calledOnce).to.be.true;
expect(deployStub.firstCall.args[0]).to.equal(zipBuffer);
expect(getString(convertStub.secondCall.args[2], 'outputDirectory', '')).to.equal('test');
// @ts-expect-error protected property
const expectedDir = join(operation.mdapiTempDir, 'metadata');
expect(expectedDir.startsWith(`test${sep}`)).to.be.true;
expect(getString(convertStub.secondCall.args[2], 'outputDirectory', '')).to.equal(expectedDir);
} finally {
delete process.env.SF_MDAPI_TEMP_DIR;
}
Expand Down
9 changes: 7 additions & 2 deletions test/client/metadataApiRetrieve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { fail } from 'node:assert';
import { join } from 'node:path';
import { join, sep } from 'node:path';
import { Messages } from '@salesforce/core';
import { assert, expect } from 'chai';
import chai = require('chai');
Expand Down Expand Up @@ -311,11 +311,16 @@ describe('MetadataApiRetrieve', () => {
successes: toRetrieve,
});
$$.SANDBOX.stub(fs.promises, 'writeFile');
$$.SANDBOX.stub(fs, 'mkdirSync');
$$.SANDBOX.stub(fs, 'writeFileSync');

await operation.start();
await operation.pollStatus();

expect(getString(convertStub.secondCall.args[2], 'outputDirectory', '')).to.equal('test');
// @ts-expect-error protected property
const expectedDir = join(operation.mdapiTempDir, 'source');
expect(expectedDir.startsWith(`test${sep}`)).to.be.true;
expect(getString(convertStub.secondCall.args[2], 'outputDirectory', '')).to.equal(expectedDir);
} finally {
delete process.env.SF_MDAPI_TEMP_DIR;
}
Expand Down
3 changes: 2 additions & 1 deletion test/snapshot/sampleProjects/mpdWithLabels/snapshots.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { ComponentSetBuilder } from '../../../../src/collections/componentSetBui
const folder = 'mpdWithLabels';
const tmpFolder = `${folder}Tmp`;
const testOriginalDir = path.join('test', 'snapshot', 'sampleProjects', folder);
const testDir = testOriginalDir.replace(folder, `${folder}Tmp`);
const testDir = testOriginalDir.replace(folder, tmpFolder);
const pkgDirs = ['force-app', 'my-app', path.join('foo-bar', 'app')];
const resolvedPkgDirs = pkgDirs.map((d) => path.join(testDir, d));

Expand All @@ -32,6 +32,7 @@ describe('recompose/decompose mpd project with labels', () => {
});
const cs = await ComponentSetBuilder.build({
sourcepath: resolvedPkgDirs,
apiversion: '60.0',
});
const converter = new MetadataConverter();
await converter.convert(cs, 'metadata', {
Expand Down
Loading

2 comments on commit a3542e2

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: a3542e2 Previous: 5628e66 Ratio
eda-componentSetCreate-linux 183 ms 178 ms 1.03
eda-sourceToMdapi-linux 2054 ms 1970 ms 1.04
eda-sourceToZip-linux 1498 ms 1412 ms 1.06
eda-mdapiToSource-linux 2913 ms 2800 ms 1.04
lotsOfClasses-componentSetCreate-linux 372 ms 353 ms 1.05
lotsOfClasses-sourceToMdapi-linux 3989 ms 3727 ms 1.07
lotsOfClasses-sourceToZip-linux 3232 ms 2986 ms 1.08
lotsOfClasses-mdapiToSource-linux 3660 ms 3452 ms 1.06
lotsOfClassesOneDir-componentSetCreate-linux 650 ms 603 ms 1.08
lotsOfClassesOneDir-sourceToMdapi-linux 6868 ms 6466 ms 1.06
lotsOfClassesOneDir-sourceToZip-linux 5998 ms 5503 ms 1.09
lotsOfClassesOneDir-mdapiToSource-linux 6576 ms 6230 ms 1.06

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: a3542e2 Previous: 5628e66 Ratio
eda-componentSetCreate-win32 429 ms 412 ms 1.04
eda-sourceToMdapi-win32 3692 ms 3752 ms 0.98
eda-sourceToZip-win32 2164 ms 2377 ms 0.91
eda-mdapiToSource-win32 5465 ms 6070 ms 0.90
lotsOfClasses-componentSetCreate-win32 853 ms 917 ms 0.93
lotsOfClasses-sourceToMdapi-win32 7396 ms 7994 ms 0.93
lotsOfClasses-sourceToZip-win32 4800 ms 5107 ms 0.94
lotsOfClasses-mdapiToSource-win32 7479 ms 7926 ms 0.94
lotsOfClassesOneDir-componentSetCreate-win32 1505 ms 1444 ms 1.04
lotsOfClassesOneDir-sourceToMdapi-win32 13420 ms 13190 ms 1.02
lotsOfClassesOneDir-sourceToZip-win32 8692 ms 8382 ms 1.04
lotsOfClassesOneDir-mdapiToSource-win32 13476 ms 13226 ms 1.02

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.