-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
68 lines (65 loc) · 2.3 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import * as core from "@actions/core";
import { existsSync } from "node:fs";
import { readdir } from "node:fs/promises";
import { SfdxCommand } from "./classes/SfdxCommand.js";
import { ArgumentsWrapper } from "./classes/ArgumentsWrapper.js";
(async function start() {
const SfdxArguments = new ArgumentsWrapper();
if (SfdxArguments.username === undefined) return;
await constructDestructiveChangesArgs(SfdxArguments);
deploy(SfdxArguments);
})();
async function constructDestructiveChangesArgs(SfdxArguments) {
if (!existsSync(SfdxArguments.pathToDestructiveChanges)) return;
for (const file of await readdir(SfdxArguments.pathToDestructiveChanges)) {
if (file === "destructiveChangesPost.xml") {
SfdxArguments.destructiveChanges.push(
"--postdestructivechanges",
`${SfdxArguments.pathToDestructiveChanges}/destructiveChangesPost.xml`
);
core.setOutput("DESTRUCTIVE_CHANGES", true);
} else if (file === "destructiveChangesPre.xml") {
SfdxArguments.destructiveChanges.push(
"--predestructivechanges",
`${SfdxArguments.pathToDestructiveChanges}/destructiveChangesPre.xml`
);
core.setOutput("DESTRUCTIVE_CHANGES", true);
} else {
core.setOutput("DESTRUCTIVE_CHANGES", false);
}
}
}
function deploy(SfdxArguments) {
const GenerateManifestCommand = new SfdxCommand(
[
"force:source:manifest:create",
"--sourcepath",
SfdxArguments.pathToSalesforceProject,
"--manifestname",
"temp-deploy-manifest",
],
"An error occurred while trying to run force:source:manifest:create."
);
GenerateManifestCommand.run();
if (!GenerateManifestCommand.succeeded) return;
const deployArgs = [
"force:source:deploy",
"--manifest",
"temp-deploy-manifest.xml",
"--testlevel",
SfdxArguments.testLevel,
"--targetusername",
SfdxArguments.username,
"--verbose",
];
if (SfdxArguments.destructiveChanges.length > 0)
deployArgs.push(...SfdxArguments.destructiveChanges);
if (SfdxArguments.timeout !== undefined)
deployArgs.push("--wait", SfdxArguments.timeout);
const DeployCommand = new SfdxCommand(
deployArgs,
"An error occurred while trying to run force:source:deploy."
);
DeployCommand.run();
if (DeployCommand.succeeded === true) core.setOutput("DEPLOYED", true);
}