@speedkit/cli 4.35.0 → 4.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/README.md +42 -7
- package/dist/commands/bulk-deploy.d.ts +19 -0
- package/dist/commands/bulk-deploy.js +52 -0
- package/dist/commands/deploy.d.ts +2 -0
- package/dist/commands/deploy.js +32 -2
- package/dist/hooks/init/http1-global-dispatcher.d.ts +12 -0
- package/dist/hooks/init/http1-global-dispatcher.js +14 -0
- package/dist/hooks/init/http1-global-dispatcher.spec.d.ts +1 -0
- package/dist/hooks/init/http1-global-dispatcher.spec.js +42 -0
- package/dist/services/cli/cli-service.js +42 -2
- package/dist/services/cli/cli-service.spec.js +41 -0
- package/dist/services/deploy/bulk/bulk-deploy-model.d.ts +46 -0
- package/dist/services/deploy/bulk/bulk-deploy-model.js +27 -0
- package/dist/services/deploy/bulk/bulk-deploy-service-factory.d.ts +11 -0
- package/dist/services/deploy/bulk/bulk-deploy-service-factory.js +24 -0
- package/dist/services/deploy/bulk/bulk-deploy-service.d.ts +47 -0
- package/dist/services/deploy/bulk/bulk-deploy-service.js +201 -0
- package/dist/services/deploy/bulk/bulk-deploy-service.spec.d.ts +1 -0
- package/dist/services/deploy/bulk/bulk-deploy-service.spec.js +146 -0
- package/dist/services/deploy/bulk/config-deploy-factory.d.ts +13 -0
- package/dist/services/deploy/bulk/config-deploy-factory.js +20 -0
- package/dist/services/deploy/bulk/index.d.ts +5 -0
- package/dist/services/deploy/bulk/index.js +5 -0
- package/dist/services/deploy/bulk/touched-configs.d.ts +12 -0
- package/dist/services/deploy/bulk/touched-configs.js +54 -0
- package/dist/services/deploy/bulk/touched-configs.spec.d.ts +1 -0
- package/dist/services/deploy/bulk/touched-configs.spec.js +77 -0
- package/dist/services/deploy/checks/activation/customer-approval-check.d.ts +3 -1
- package/dist/services/deploy/checks/activation/customer-approval-check.js +5 -2
- package/dist/services/deploy/checks/activation/customer-approval-check.spec.js +18 -15
- package/dist/services/deploy/checks/post-deploy/deprecated-deployment-detection-check.d.ts +3 -1
- package/dist/services/deploy/checks/post-deploy/deprecated-deployment-detection-check.js +6 -3
- package/dist/services/deploy/checks/post-deploy/save-files-check.d.ts +3 -1
- package/dist/services/deploy/checks/post-deploy/save-files-check.js +5 -2
- package/dist/services/deploy/checks/pre-deploy/device-detection-changed-check.d.ts +3 -1
- package/dist/services/deploy/checks/pre-deploy/device-detection-changed-check.js +9 -5
- package/dist/services/deploy/checks/pre-deploy/split-change-check.d.ts +3 -1
- package/dist/services/deploy/checks/pre-deploy/split-change-check.js +8 -5
- package/dist/services/deploy/checks/pre-deploy/split-change-check.spec.d.ts +1 -0
- package/dist/services/deploy/checks/pre-deploy/split-change-check.spec.js +55 -0
- package/dist/services/deploy/context/deploy-context.d.ts +21 -1
- package/dist/services/deploy/context/deploy-context.js +30 -1
- package/dist/services/deploy/deploy-service-factory.d.ts +13 -1
- package/dist/services/deploy/deploy-service-factory.js +36 -15
- package/dist/services/deploy/error/deploy-aborted-error.d.ts +12 -0
- package/dist/services/deploy/error/deploy-aborted-error.js +16 -0
- package/dist/services/deploy/handler/customer-config-handler.d.ts +3 -1
- package/dist/services/deploy/handler/customer-config-handler.js +11 -7
- package/dist/services/deploy/handler/install-resource-handler.d.ts +3 -1
- package/dist/services/deploy/handler/install-resource-handler.js +12 -7
- package/dist/services/deploy/handler/install-resource-modifier/deleted-file-check.d.ts +3 -1
- package/dist/services/deploy/handler/install-resource-modifier/deleted-file-check.js +5 -2
- package/dist/services/deploy/handler/module-handler.d.ts +3 -1
- package/dist/services/deploy/handler/module-handler.js +7 -4
- package/dist/services/deploy/handler/module-handler.spec.d.ts +1 -0
- package/dist/services/deploy/handler/module-handler.spec.js +49 -0
- package/dist/services/deploy/handler/server-config-handler.d.ts +3 -1
- package/dist/services/deploy/handler/server-config-handler.js +6 -3
- package/dist/services/deploy/mr/base-config-reader.d.ts +25 -0
- package/dist/services/deploy/mr/base-config-reader.js +52 -0
- package/dist/services/deploy/mr/index.d.ts +6 -0
- package/dist/services/deploy/mr/index.js +6 -0
- package/dist/services/deploy/mr/live-state-check.d.ts +38 -0
- package/dist/services/deploy/mr/live-state-check.js +81 -0
- package/dist/services/deploy/mr/live-state-check.spec.d.ts +1 -0
- package/dist/services/deploy/mr/live-state-check.spec.js +74 -0
- package/dist/services/deploy/mr/merge-request-deploy-model.d.ts +59 -0
- package/dist/services/deploy/mr/merge-request-deploy-model.js +50 -0
- package/dist/services/deploy/mr/merge-request-deploy-service-factory.d.ts +20 -0
- package/dist/services/deploy/mr/merge-request-deploy-service-factory.js +46 -0
- package/dist/services/deploy/mr/merge-request-deploy-service.d.ts +61 -0
- package/dist/services/deploy/mr/merge-request-deploy-service.js +189 -0
- package/dist/services/deploy/mr/merge-request-description.d.ts +16 -0
- package/dist/services/deploy/mr/merge-request-description.js +27 -0
- package/dist/services/deploy/mr/merge-request-description.spec.d.ts +1 -0
- package/dist/services/deploy/mr/merge-request-description.spec.js +55 -0
- package/dist/services/deploy/policy/auto-deploy-policy.d.ts +43 -0
- package/dist/services/deploy/policy/auto-deploy-policy.js +77 -0
- package/dist/services/deploy/policy/auto-deploy-policy.spec.d.ts +1 -0
- package/dist/services/deploy/policy/auto-deploy-policy.spec.js +83 -0
- package/dist/services/deploy/policy/deploy-policy-model.d.ts +61 -0
- package/dist/services/deploy/policy/deploy-policy-model.js +41 -0
- package/dist/services/deploy/policy/index.d.ts +2 -0
- package/dist/services/deploy/policy/index.js +2 -0
- package/dist/services/deploy/policy/interactive-deploy-policy.d.ts +15 -0
- package/dist/services/deploy/policy/interactive-deploy-policy.js +16 -0
- package/dist/services/diff/diff-model.d.ts +5 -1
- package/dist/services/diff/diff-model.js +5 -1
- package/dist/services/diff/diff-service-factory.js +1 -1
- package/dist/services/diff/diff-service.d.ts +2 -1
- package/dist/services/diff/diff-service.js +6 -4
- package/dist/services/git/git-repository-model.d.ts +13 -0
- package/dist/services/git/git-repository-model.js +1 -0
- package/dist/services/git/git-repository.d.ts +35 -0
- package/dist/services/git/git-repository.js +120 -0
- package/dist/services/git/git-repository.spec.d.ts +1 -0
- package/dist/services/git/git-repository.spec.js +87 -0
- package/dist/services/git/index.d.ts +2 -0
- package/dist/services/git/index.js +2 -0
- package/dist/services/integration-api/spec/speed-kit-config-file.spec.js +1 -1
- package/oclif.manifest.json +107 -1
- package/package.json +4 -3
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { FILE_TYPE, } from "../../integration-api/index.js";
|
|
2
2
|
import { safe } from "../../../helpers/safe.js";
|
|
3
3
|
import { buildTestingInstallationLinks } from "./testing-installation-links.js";
|
|
4
|
+
import { DeployQuestion } from "../policy/index.js";
|
|
5
|
+
import { DeployAbortedError } from "../error/deploy-aborted-error.js";
|
|
4
6
|
export default class InstallResourceHandler {
|
|
5
7
|
customer;
|
|
6
8
|
configApi;
|
|
@@ -10,7 +12,8 @@ export default class InstallResourceHandler {
|
|
|
10
12
|
builder;
|
|
11
13
|
deletedFilesChecker;
|
|
12
14
|
customerApprovalCheck;
|
|
13
|
-
|
|
15
|
+
policy;
|
|
16
|
+
constructor(customer, configApi, configName, diffService, cli, builder, deletedFilesChecker, customerApprovalCheck, policy) {
|
|
14
17
|
this.customer = customer;
|
|
15
18
|
this.configApi = configApi;
|
|
16
19
|
this.diffService = diffService;
|
|
@@ -19,6 +22,7 @@ export default class InstallResourceHandler {
|
|
|
19
22
|
this.builder = builder;
|
|
20
23
|
this.deletedFilesChecker = deletedFilesChecker;
|
|
21
24
|
this.customerApprovalCheck = customerApprovalCheck;
|
|
25
|
+
this.policy = policy;
|
|
22
26
|
}
|
|
23
27
|
canHandle(type) {
|
|
24
28
|
return type === FILE_TYPE.INSTALL_FILE;
|
|
@@ -47,8 +51,8 @@ export default class InstallResourceHandler {
|
|
|
47
51
|
this.cli.write("");
|
|
48
52
|
this.cli.write("Summary");
|
|
49
53
|
this.cli.writeBuffer();
|
|
50
|
-
if (!(await this.
|
|
51
|
-
|
|
54
|
+
if (!(await this.policy.confirm(DeployQuestion.UploadInstallResource, "InstallResource will be created now. Proceed?"))) {
|
|
55
|
+
throw new DeployAbortedError("the new installation was not confirmed");
|
|
52
56
|
}
|
|
53
57
|
const install = await this.getInstallResource();
|
|
54
58
|
await this.deletedFilesChecker.checkForDeletedLocalFiles(install);
|
|
@@ -62,7 +66,8 @@ export default class InstallResourceHandler {
|
|
|
62
66
|
// Without the customer's approval the installation may only go live as a
|
|
63
67
|
// testing installation, so the regular activation is not even offered.
|
|
64
68
|
const approved = await this.customerApprovalCheck.isActivationApproved(install);
|
|
65
|
-
if (approved &&
|
|
69
|
+
if (approved &&
|
|
70
|
+
(await this.policy.confirm(DeployQuestion.Activate, "Activate new installation?"))) {
|
|
66
71
|
await this.activate(install);
|
|
67
72
|
return;
|
|
68
73
|
}
|
|
@@ -81,7 +86,7 @@ export default class InstallResourceHandler {
|
|
|
81
86
|
const question = wasActivationOffered
|
|
82
87
|
? "Activate as testing installation instead?"
|
|
83
88
|
: "Activate as testing installation?";
|
|
84
|
-
if (!(await this.
|
|
89
|
+
if (!(await this.policy.confirm(DeployQuestion.ActivateAsTesting, question))) {
|
|
85
90
|
return;
|
|
86
91
|
}
|
|
87
92
|
this.cli.startAction("DEPLOY:ACTIVATE:INSTALL_RESOURCE_TEST", "activate testing installResource");
|
|
@@ -122,7 +127,7 @@ export default class InstallResourceHandler {
|
|
|
122
127
|
await this.confirm(file);
|
|
123
128
|
}
|
|
124
129
|
async confirm(file, isNew = false) {
|
|
125
|
-
const confirm = await this.
|
|
130
|
+
const confirm = await this.policy.confirm(DeployQuestion.UpdateFile, `${isNew ? "Create" : "Update"} ${file.name}?`);
|
|
126
131
|
if (confirm) {
|
|
127
132
|
if (isNew) {
|
|
128
133
|
this.cli.write(`consider new ${file.name}`, true);
|
|
@@ -146,7 +151,7 @@ export default class InstallResourceHandler {
|
|
|
146
151
|
this.cli.successAction("DEPLOY:CREATE:INSTALL_RESOURCE");
|
|
147
152
|
const remoteClone = result.data;
|
|
148
153
|
install = this.builder.updateFromRemote(remoteClone);
|
|
149
|
-
install.description = await this.
|
|
154
|
+
install.description = await this.policy.text(DeployQuestion.Description, "Describe new configuration:", {
|
|
150
155
|
defaultAnswer: install.description ?? this.configName,
|
|
151
156
|
validator: (input) => (input.trim() ? "" : "Please enter something"),
|
|
152
157
|
});
|
|
@@ -2,11 +2,13 @@ import Install from "../../interface/install.js";
|
|
|
2
2
|
import { CliService } from "../../../cli/index.js";
|
|
3
3
|
import InstallResourceBuilder from "../../builder/install-resource-builder.js";
|
|
4
4
|
import { InstallResourceInterface } from "../../../integration-api/integration-api-model.js";
|
|
5
|
+
import { DeployPolicyInterface } from "../../policy/index.js";
|
|
5
6
|
export default class DeletedFileCheck {
|
|
7
|
+
private policy;
|
|
6
8
|
private cli;
|
|
7
9
|
private readonly hasFileSelection;
|
|
8
10
|
private keysToDelete;
|
|
9
|
-
constructor(cli: CliService, hasFileSelection?: boolean);
|
|
11
|
+
constructor(cli: CliService, policy: DeployPolicyInterface, hasFileSelection?: boolean);
|
|
10
12
|
hasDeletedFiles(builder: InstallResourceBuilder, files: InstallResourceInterface[]): Promise<void>;
|
|
11
13
|
checkForDeletedLocalFiles(installResource: Install): Promise<void>;
|
|
12
14
|
private getFileByRemoteKey;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DeployQuestion } from "../../policy/index.js";
|
|
1
2
|
const INSTALL_RESOURCE_FILE_KEYS = [
|
|
2
3
|
"custom",
|
|
3
4
|
"sw",
|
|
@@ -9,10 +10,12 @@ const INSTALL_RESOURCE_FILE_KEYS = [
|
|
|
9
10
|
"customStyle",
|
|
10
11
|
];
|
|
11
12
|
export default class DeletedFileCheck {
|
|
13
|
+
policy;
|
|
12
14
|
cli;
|
|
13
15
|
hasFileSelection;
|
|
14
16
|
keysToDelete = [];
|
|
15
|
-
constructor(cli, hasFileSelection = false) {
|
|
17
|
+
constructor(cli, policy, hasFileSelection = false) {
|
|
18
|
+
this.policy = policy;
|
|
16
19
|
this.cli = cli;
|
|
17
20
|
this.hasFileSelection = hasFileSelection;
|
|
18
21
|
}
|
|
@@ -24,7 +27,7 @@ export default class DeletedFileCheck {
|
|
|
24
27
|
for (const key of INSTALL_RESOURCE_FILE_KEYS) {
|
|
25
28
|
const file = this.getFileByRemoteKey(key, files);
|
|
26
29
|
if (!file && installResource[key]?.length > 0) {
|
|
27
|
-
const deleteResource = await this.
|
|
30
|
+
const deleteResource = await this.policy.confirm(DeployQuestion.DeleteInstallResourceKey, `Do you want to delete ${key} on installResource?`);
|
|
28
31
|
if (deleteResource) {
|
|
29
32
|
this.keysToDelete.push(key);
|
|
30
33
|
builder.changed = true;
|
|
@@ -4,12 +4,14 @@ import { DiffService } from "../../diff/index.js";
|
|
|
4
4
|
import { CliService } from "../../cli/index.js";
|
|
5
5
|
import RuntimeModifier from "../interface/runtime-modifier.js";
|
|
6
6
|
import { ConfigApiService } from "../../config-api/index.js";
|
|
7
|
+
import { DeployPolicyInterface } from "../policy/index.js";
|
|
7
8
|
export default class ModuleHandler implements DeployHandlerInterface {
|
|
8
9
|
private readonly configApi;
|
|
9
10
|
private diffService;
|
|
10
11
|
private cli;
|
|
11
12
|
private modifiers;
|
|
12
|
-
|
|
13
|
+
private policy;
|
|
14
|
+
constructor(configApi: ConfigApiService, diffService: DiffService, cli: CliService, modifiers: RuntimeModifier[], policy: DeployPolicyInterface);
|
|
13
15
|
canHandle(type: FILE_TYPE): boolean;
|
|
14
16
|
handle(files: ModuleFile[]): Promise<void>;
|
|
15
17
|
upload(files: ModuleFile[]): Promise<void>;
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { FILE_TYPE } from "../../integration-api/index.js";
|
|
2
2
|
import { safe } from "../../../helpers/safe.js";
|
|
3
3
|
import { DeployModuleFileError } from "../error/deploy-module-file-error.js";
|
|
4
|
+
import { DeployQuestion } from "../policy/index.js";
|
|
4
5
|
export default class ModuleHandler {
|
|
5
6
|
configApi;
|
|
6
7
|
diffService;
|
|
7
8
|
cli;
|
|
8
9
|
modifiers;
|
|
9
|
-
|
|
10
|
+
policy;
|
|
11
|
+
constructor(configApi, diffService, cli, modifiers, policy) {
|
|
10
12
|
this.configApi = configApi;
|
|
11
13
|
this.diffService = diffService;
|
|
12
14
|
this.cli = cli;
|
|
13
15
|
this.modifiers = modifiers;
|
|
16
|
+
this.policy = policy;
|
|
14
17
|
}
|
|
15
18
|
canHandle(type) {
|
|
16
19
|
return type === FILE_TYPE.MODULE_FILE;
|
|
@@ -48,8 +51,8 @@ export default class ModuleHandler {
|
|
|
48
51
|
this.cli.write("");
|
|
49
52
|
this.cli.write("Summary");
|
|
50
53
|
this.cli.writeBuffer();
|
|
51
|
-
if (await this.
|
|
52
|
-
for (const file_ of
|
|
54
|
+
if (await this.policy.confirm(DeployQuestion.UploadModules, `${filesToUpload.length} Module(s) will be uploaded now. Proceed?`)) {
|
|
55
|
+
for (const file_ of filesToUpload) {
|
|
53
56
|
const file = file_;
|
|
54
57
|
this.cli.startAction("DEPLOY:UPDATE:MODULE", `update module ${file.name}`);
|
|
55
58
|
const result = await safe(this.configApi.setModule(file.getContent(), file.name));
|
|
@@ -67,7 +70,7 @@ export default class ModuleHandler {
|
|
|
67
70
|
}
|
|
68
71
|
}
|
|
69
72
|
async confirm(file, isNew = false) {
|
|
70
|
-
const confirm = await this.
|
|
73
|
+
const confirm = await this.policy.confirm(DeployQuestion.UpdateFile, `${isNew ? "Create" : "Update"} ${file.name}?`);
|
|
71
74
|
if (confirm) {
|
|
72
75
|
if (isNew) {
|
|
73
76
|
this.cli.write(`consider new ${file.name}`, true);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import ModuleHandler from "./module-handler.js";
|
|
4
|
+
import { ModuleFile } from "../../integration-api/index.js";
|
|
5
|
+
function moduleFile(name) {
|
|
6
|
+
return new ModuleFile(name, `/tmp/${name}.js`, `// ${name}`, {});
|
|
7
|
+
}
|
|
8
|
+
/** A handler whose questions are all answered with yes. */
|
|
9
|
+
function handlerUploadingTo(uploaded) {
|
|
10
|
+
const cli = {
|
|
11
|
+
write: () => undefined,
|
|
12
|
+
writeBuffer: () => undefined,
|
|
13
|
+
startAction: () => undefined,
|
|
14
|
+
successAction: () => undefined,
|
|
15
|
+
failAction: () => undefined,
|
|
16
|
+
};
|
|
17
|
+
const configApi = {
|
|
18
|
+
setModule: async (content, name) => {
|
|
19
|
+
uploaded.push(name);
|
|
20
|
+
return name;
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
const policy = {
|
|
24
|
+
confirm: async () => true,
|
|
25
|
+
text: async () => "",
|
|
26
|
+
};
|
|
27
|
+
return new ModuleHandler(configApi, {}, cli, [], policy);
|
|
28
|
+
}
|
|
29
|
+
describe("ModuleHandler", () => {
|
|
30
|
+
it("uploads the modules that were confirmed", async () => {
|
|
31
|
+
const uploaded = [];
|
|
32
|
+
await handlerUploadingTo(uploaded).upload([moduleFile("wanted")]);
|
|
33
|
+
expect(uploaded).to.deep.equal(["wanted"]);
|
|
34
|
+
});
|
|
35
|
+
it("leaves out a module that was skipped", async () => {
|
|
36
|
+
const uploaded = [];
|
|
37
|
+
const skipped = moduleFile("skipped");
|
|
38
|
+
skipped.skipFile();
|
|
39
|
+
await handlerUploadingTo(uploaded).upload([skipped, moduleFile("wanted")]);
|
|
40
|
+
expect(uploaded).to.deep.equal(["wanted"]);
|
|
41
|
+
});
|
|
42
|
+
it("uploads nothing while every module is skipped", async () => {
|
|
43
|
+
const uploaded = [];
|
|
44
|
+
const skipped = moduleFile("skipped");
|
|
45
|
+
skipped.skipFile();
|
|
46
|
+
await handlerUploadingTo(uploaded).upload([skipped]);
|
|
47
|
+
expect(uploaded).to.deep.equal([]);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -3,11 +3,13 @@ import { DiffService } from "../../diff/index.js";
|
|
|
3
3
|
import { CliService } from "../../cli/index.js";
|
|
4
4
|
import { FILE_TYPE, ServerConfigFile } from "../../integration-api/index.js";
|
|
5
5
|
import { ConfigApiService } from "../../config-api/index.js";
|
|
6
|
+
import { DeployPolicyInterface } from "../policy/index.js";
|
|
6
7
|
export default class ServerConfigHandler implements DeployHandlerInterface {
|
|
7
8
|
private configApi;
|
|
8
9
|
private diffService;
|
|
9
10
|
private cli;
|
|
10
|
-
|
|
11
|
+
private policy;
|
|
12
|
+
constructor(configApi: ConfigApiService, diffService: DiffService, cli: CliService, policy: DeployPolicyInterface);
|
|
11
13
|
canHandle(type: FILE_TYPE): boolean;
|
|
12
14
|
handle(files: ServerConfigFile[]): Promise<void>;
|
|
13
15
|
upload(files: ServerConfigFile[]): Promise<void>;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { FILE_TYPE } from "../../integration-api/index.js";
|
|
2
2
|
import { safe } from "../../../helpers/safe.js";
|
|
3
3
|
import { DeployServerConfigError } from "../error/deploy-server-config-error.js";
|
|
4
|
+
import { DeployQuestion } from "../policy/index.js";
|
|
4
5
|
export default class ServerConfigHandler {
|
|
5
6
|
configApi;
|
|
6
7
|
diffService;
|
|
7
8
|
cli;
|
|
8
|
-
|
|
9
|
+
policy;
|
|
10
|
+
constructor(configApi, diffService, cli, policy) {
|
|
9
11
|
this.configApi = configApi;
|
|
10
12
|
this.diffService = diffService;
|
|
11
13
|
this.cli = cli;
|
|
14
|
+
this.policy = policy;
|
|
12
15
|
}
|
|
13
16
|
canHandle(type) {
|
|
14
17
|
return type === FILE_TYPE.SERVER_FILE;
|
|
@@ -41,7 +44,7 @@ export default class ServerConfigHandler {
|
|
|
41
44
|
this.cli.write("");
|
|
42
45
|
this.cli.write("Summary");
|
|
43
46
|
this.cli.writeBuffer();
|
|
44
|
-
if (!(await this.
|
|
47
|
+
if (!(await this.policy.confirm(DeployQuestion.UploadServerConfig, `ServerConfig will be uploaded now. Proceed?`))) {
|
|
45
48
|
return;
|
|
46
49
|
}
|
|
47
50
|
this.cli.startAction("DEPLOY:UPDATE:RUNTIME_CONFIG", "upload serverconfig");
|
|
@@ -55,7 +58,7 @@ export default class ServerConfigHandler {
|
|
|
55
58
|
this.cli.successAction("DEPLOY:UPDATE:RUNTIME_CONFIG");
|
|
56
59
|
}
|
|
57
60
|
async confirm(file, isNew = false) {
|
|
58
|
-
const confirm = await this.
|
|
61
|
+
const confirm = await this.policy.confirm(DeployQuestion.UpdateFile, `Deploy ${file.name}?`, true);
|
|
59
62
|
if (confirm) {
|
|
60
63
|
if (isNew) {
|
|
61
64
|
this.cli.writeSuccess(`${file.name} is new`, true);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { UserCliConfig } from "../../../helpers/cli-config.js";
|
|
2
|
+
import { GitRepository } from "../../git/index.js";
|
|
3
|
+
import { FileListInterface } from "../../integration-api/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Reads a customer configuration as it was before a merge request.
|
|
6
|
+
*
|
|
7
|
+
* The files of the commit are written to a temporary directory and read back
|
|
8
|
+
* through the integration API, so the result is built exactly like the
|
|
9
|
+
* configuration on disk, including the files of the environment.
|
|
10
|
+
*/
|
|
11
|
+
export declare class BaseConfigReader {
|
|
12
|
+
private readonly repository;
|
|
13
|
+
private readonly cliConfig;
|
|
14
|
+
constructor(repository: GitRepository, cliConfig: UserCliConfig);
|
|
15
|
+
/**
|
|
16
|
+
* The configuration at the commit, or null while the commit has none.
|
|
17
|
+
*
|
|
18
|
+
* @param customerPath the customer directory in the working tree
|
|
19
|
+
* @param configName the environment to read
|
|
20
|
+
* @param sha the commit to read the files from
|
|
21
|
+
*/
|
|
22
|
+
read(customerPath: string, configName: string, sha: string): Promise<FileListInterface | null>;
|
|
23
|
+
/** Writes the files of the commit to a temporary copy of the directory. */
|
|
24
|
+
private write;
|
|
25
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createTemporalDirectory } from "../../../helpers/file-helper.js";
|
|
4
|
+
import ApplicationError from "../../error-handling/error/application-error.js";
|
|
5
|
+
import { IntegrationApiContext, IntegrationApiFactory, } from "../../integration-api/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Reads a customer configuration as it was before a merge request.
|
|
8
|
+
*
|
|
9
|
+
* The files of the commit are written to a temporary directory and read back
|
|
10
|
+
* through the integration API, so the result is built exactly like the
|
|
11
|
+
* configuration on disk, including the files of the environment.
|
|
12
|
+
*/
|
|
13
|
+
export class BaseConfigReader {
|
|
14
|
+
repository;
|
|
15
|
+
cliConfig;
|
|
16
|
+
constructor(repository, cliConfig) {
|
|
17
|
+
this.repository = repository;
|
|
18
|
+
this.cliConfig = cliConfig;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The configuration at the commit, or null while the commit has none.
|
|
22
|
+
*
|
|
23
|
+
* @param customerPath the customer directory in the working tree
|
|
24
|
+
* @param configName the environment to read
|
|
25
|
+
* @param sha the commit to read the files from
|
|
26
|
+
*/
|
|
27
|
+
async read(customerPath, configName, sha) {
|
|
28
|
+
const directory = this.repository.relative(customerPath);
|
|
29
|
+
const paths = this.repository.pathsAt(sha, directory);
|
|
30
|
+
if (paths.length === 0) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const target = await this.write(paths, directory, sha);
|
|
34
|
+
return new IntegrationApiFactory(new IntegrationApiContext(target, configName, []), this.cliConfig)
|
|
35
|
+
.buildService()
|
|
36
|
+
.run();
|
|
37
|
+
}
|
|
38
|
+
/** Writes the files of the commit to a temporary copy of the directory. */
|
|
39
|
+
async write(paths, directory, sha) {
|
|
40
|
+
const temporalDirectory = await createTemporalDirectory();
|
|
41
|
+
if (!temporalDirectory) {
|
|
42
|
+
throw new ApplicationError("Unable to create a temporary directory for the configuration to compare with");
|
|
43
|
+
}
|
|
44
|
+
const target = path.join(temporalDirectory, path.basename(directory));
|
|
45
|
+
for (const filePath of paths) {
|
|
46
|
+
const file = path.join(target, path.relative(directory, filePath));
|
|
47
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
48
|
+
writeFileSync(file, this.repository.contentAt(sha, filePath));
|
|
49
|
+
}
|
|
50
|
+
return target;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "./base-config-reader.js";
|
|
2
|
+
export * from "./live-state-check.js";
|
|
3
|
+
export * from "./merge-request-deploy-model.js";
|
|
4
|
+
export * from "./merge-request-description.js";
|
|
5
|
+
export * from "./merge-request-deploy-service.js";
|
|
6
|
+
export * from "./merge-request-deploy-service-factory.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "./base-config-reader.js";
|
|
2
|
+
export * from "./live-state-check.js";
|
|
3
|
+
export * from "./merge-request-deploy-model.js";
|
|
4
|
+
export * from "./merge-request-description.js";
|
|
5
|
+
export * from "./merge-request-deploy-service.js";
|
|
6
|
+
export * from "./merge-request-deploy-service-factory.js";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { DiffService } from "../../diff/index.js";
|
|
2
|
+
import { FileListInterface } from "../../integration-api/index.js";
|
|
3
|
+
import Install from "../interface/install.js";
|
|
4
|
+
/** How the live installation relates to the merge request. */
|
|
5
|
+
export declare enum LiveState {
|
|
6
|
+
/** Live is the state before the merge request, so the deploy is reviewed. */
|
|
7
|
+
Reviewed = "reviewed",
|
|
8
|
+
/** Live already carries the merge request. Nothing is left to deploy. */
|
|
9
|
+
AlreadyDeployed = "alreadyDeployed",
|
|
10
|
+
/** Live carries changes that never reached git. */
|
|
11
|
+
Drifted = "drifted",
|
|
12
|
+
/** The app has no active installation of this configuration. */
|
|
13
|
+
Missing = "missing"
|
|
14
|
+
}
|
|
15
|
+
export interface LiveStateResult {
|
|
16
|
+
state: LiveState;
|
|
17
|
+
/** The files that live and the state before the merge request disagree on. */
|
|
18
|
+
driftedFiles: string[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Compares the live installation with the state before the merge request.
|
|
22
|
+
*
|
|
23
|
+
* A deploy overwrites every file it finds different, so a change that only
|
|
24
|
+
* lives in the app would be reverted without anybody noticing. The comparison
|
|
25
|
+
* covers every file the deploy uploads, not only the files of the merge
|
|
26
|
+
* request, and only an equal result makes the deploy safe.
|
|
27
|
+
*/
|
|
28
|
+
export declare class LiveStateCheck {
|
|
29
|
+
private readonly diff;
|
|
30
|
+
constructor(diff: DiffService);
|
|
31
|
+
compare(base: FileListInterface, local: FileListInterface, install: Install | null): LiveStateResult;
|
|
32
|
+
/** Whether the merge request changes anything this deploy would upload. */
|
|
33
|
+
isUnchanged(base: FileListInterface, local: FileListInterface): boolean;
|
|
34
|
+
/** The names of everything the two states disagree on. */
|
|
35
|
+
private differences;
|
|
36
|
+
private stateOfFiles;
|
|
37
|
+
private stateOfInstall;
|
|
38
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { InstallResourceToFileMapping } from "../../pull/index.js";
|
|
2
|
+
/** How the live installation relates to the merge request. */
|
|
3
|
+
export var LiveState;
|
|
4
|
+
(function (LiveState) {
|
|
5
|
+
/** Live is the state before the merge request, so the deploy is reviewed. */
|
|
6
|
+
LiveState["Reviewed"] = "reviewed";
|
|
7
|
+
/** Live already carries the merge request. Nothing is left to deploy. */
|
|
8
|
+
LiveState["AlreadyDeployed"] = "alreadyDeployed";
|
|
9
|
+
/** Live carries changes that never reached git. */
|
|
10
|
+
LiveState["Drifted"] = "drifted";
|
|
11
|
+
/** The app has no active installation of this configuration. */
|
|
12
|
+
LiveState["Missing"] = "missing";
|
|
13
|
+
})(LiveState || (LiveState = {}));
|
|
14
|
+
/** The origins are one file of the comparison, under the name of their file. */
|
|
15
|
+
const ORIGINS = "config_customer(origins)";
|
|
16
|
+
/**
|
|
17
|
+
* Compares the live installation with the state before the merge request.
|
|
18
|
+
*
|
|
19
|
+
* A deploy overwrites every file it finds different, so a change that only
|
|
20
|
+
* lives in the app would be reverted without anybody noticing. The comparison
|
|
21
|
+
* covers every file the deploy uploads, not only the files of the merge
|
|
22
|
+
* request, and only an equal result makes the deploy safe.
|
|
23
|
+
*/
|
|
24
|
+
export class LiveStateCheck {
|
|
25
|
+
diff;
|
|
26
|
+
constructor(diff) {
|
|
27
|
+
this.diff = diff;
|
|
28
|
+
}
|
|
29
|
+
compare(base, local, install) {
|
|
30
|
+
if (!install) {
|
|
31
|
+
return { state: LiveState.Missing, driftedFiles: [] };
|
|
32
|
+
}
|
|
33
|
+
const live = this.stateOfInstall(install);
|
|
34
|
+
const driftedFiles = this.differences(this.stateOfFiles(base), live);
|
|
35
|
+
if (driftedFiles.length === 0) {
|
|
36
|
+
return { state: LiveState.Reviewed, driftedFiles };
|
|
37
|
+
}
|
|
38
|
+
if (this.differences(this.stateOfFiles(local), live).length === 0) {
|
|
39
|
+
return { state: LiveState.AlreadyDeployed, driftedFiles: [] };
|
|
40
|
+
}
|
|
41
|
+
return { state: LiveState.Drifted, driftedFiles };
|
|
42
|
+
}
|
|
43
|
+
/** Whether the merge request changes anything this deploy would upload. */
|
|
44
|
+
isUnchanged(base, local) {
|
|
45
|
+
return (this.differences(this.stateOfFiles(base), this.stateOfFiles(local))
|
|
46
|
+
.length === 0);
|
|
47
|
+
}
|
|
48
|
+
/** The names of everything the two states disagree on. */
|
|
49
|
+
differences(left, right) {
|
|
50
|
+
const differences = [];
|
|
51
|
+
for (const key of Object.keys(InstallResourceToFileMapping)) {
|
|
52
|
+
if (!this.diff.isContentEqual(left.contents[key], right.contents[key])) {
|
|
53
|
+
differences.push(InstallResourceToFileMapping[key].fileName);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (JSON.stringify([...left.origins].sort()) !==
|
|
57
|
+
JSON.stringify([...right.origins].sort())) {
|
|
58
|
+
differences.push(ORIGINS);
|
|
59
|
+
}
|
|
60
|
+
return differences;
|
|
61
|
+
}
|
|
62
|
+
stateOfFiles(files) {
|
|
63
|
+
const contents = {};
|
|
64
|
+
for (const file of files.getInstallResources()) {
|
|
65
|
+
if (!file.shouldSkipFile()) {
|
|
66
|
+
contents[file.remoteKey] = file.getContent();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
contents,
|
|
71
|
+
origins: files.getCustomerConfig()?.config?.origins ?? [],
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
stateOfInstall(install) {
|
|
75
|
+
const contents = {};
|
|
76
|
+
for (const key of Object.keys(InstallResourceToFileMapping)) {
|
|
77
|
+
contents[key] = install[key] ?? "";
|
|
78
|
+
}
|
|
79
|
+
return { contents, origins: install.origins ?? [] };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import { LiveState, LiveStateCheck } from "./live-state-check.js";
|
|
4
|
+
import { DiffService } from "../../diff/index.js";
|
|
5
|
+
const ORIGINS = ["https://www.example.com"];
|
|
6
|
+
/** A configuration of the install resource files it holds. */
|
|
7
|
+
function configuration(files, origins = ORIGINS) {
|
|
8
|
+
const resources = Object.entries(files).map(([remoteKey, content]) => ({
|
|
9
|
+
remoteKey,
|
|
10
|
+
name: remoteKey,
|
|
11
|
+
getContent: () => content,
|
|
12
|
+
shouldSkipFile: () => false,
|
|
13
|
+
}));
|
|
14
|
+
return {
|
|
15
|
+
getInstallResources: () => resources,
|
|
16
|
+
getCustomerConfig: () => ({ config: { origins } }),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function installOf(files, origins = ORIGINS) {
|
|
20
|
+
return { domain: "production", origins, ...files };
|
|
21
|
+
}
|
|
22
|
+
const check = new LiveStateCheck(new DiffService({}));
|
|
23
|
+
describe("LiveStateCheck", () => {
|
|
24
|
+
it("calls the deploy reviewed while live is the state before the merge request", () => {
|
|
25
|
+
const base = configuration({ config: "before" });
|
|
26
|
+
const local = configuration({ config: "after" });
|
|
27
|
+
const result = check.compare(base, local, installOf({ config: "before" }));
|
|
28
|
+
expect(result.state).to.equal(LiveState.Reviewed);
|
|
29
|
+
expect(result.driftedFiles).to.deep.equal([]);
|
|
30
|
+
});
|
|
31
|
+
it("ignores whitespace, as the deploy itself does", () => {
|
|
32
|
+
const base = configuration({
|
|
33
|
+
config: "window.speedKit = {\n split: 1 };",
|
|
34
|
+
});
|
|
35
|
+
const local = configuration({ config: "window.speedKit = { split: 0 };" });
|
|
36
|
+
const result = check.compare(base, local, installOf({ config: "window.speedKit={split:1};" }));
|
|
37
|
+
expect(result.state).to.equal(LiveState.Reviewed);
|
|
38
|
+
});
|
|
39
|
+
it("reports a merge request that is live already", () => {
|
|
40
|
+
const base = configuration({ config: "before" });
|
|
41
|
+
const local = configuration({ config: "after" });
|
|
42
|
+
const result = check.compare(base, local, installOf({ config: "after" }));
|
|
43
|
+
expect(result.state).to.equal(LiveState.AlreadyDeployed);
|
|
44
|
+
});
|
|
45
|
+
it("names the files that only live carries", () => {
|
|
46
|
+
const base = configuration({ config: "before", loader: "loader" });
|
|
47
|
+
const local = configuration({ config: "after", loader: "loader" });
|
|
48
|
+
const result = check.compare(base, local, installOf({ config: "a hotfix", loader: "loader" }));
|
|
49
|
+
expect(result.state).to.equal(LiveState.Drifted);
|
|
50
|
+
expect(result.driftedFiles).to.deep.equal(["config_SpeedKit"]);
|
|
51
|
+
});
|
|
52
|
+
it("counts a file that live has and git never had", () => {
|
|
53
|
+
const base = configuration({ config: "same" });
|
|
54
|
+
const local = configuration({ config: "same" });
|
|
55
|
+
const result = check.compare(base, local, installOf({ config: "same", customStyle: ".a { color: red }" }));
|
|
56
|
+
expect(result.state).to.equal(LiveState.Drifted);
|
|
57
|
+
expect(result.driftedFiles).to.deep.equal(["config_dynamicStyles"]);
|
|
58
|
+
});
|
|
59
|
+
it("counts origins that were changed in the app", () => {
|
|
60
|
+
const base = configuration({ config: "same" });
|
|
61
|
+
const local = configuration({ config: "same" });
|
|
62
|
+
const result = check.compare(base, local, installOf({ config: "same" }, [
|
|
63
|
+
"https://www.example.com",
|
|
64
|
+
"https://m.example.com",
|
|
65
|
+
]));
|
|
66
|
+
expect(result.state).to.equal(LiveState.Drifted);
|
|
67
|
+
expect(result.driftedFiles).to.deep.equal(["config_customer(origins)"]);
|
|
68
|
+
});
|
|
69
|
+
it("reports a configuration that the app does not have", () => {
|
|
70
|
+
const base = configuration({ config: "before" });
|
|
71
|
+
const result = check.compare(base, base, null);
|
|
72
|
+
expect(result.state).to.equal(LiveState.Missing);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ApprovalAnswer } from "../policy/auto-deploy-policy.js";
|
|
2
|
+
/** What `sk deploy --mr` is asked to deploy. */
|
|
3
|
+
export declare class MergeRequestDeployContext {
|
|
4
|
+
readonly customerPath: string;
|
|
5
|
+
readonly configName: string;
|
|
6
|
+
/** The number of the merged merge request. */
|
|
7
|
+
readonly iid: number;
|
|
8
|
+
readonly approval: ApprovalAnswer;
|
|
9
|
+
/** The description of the installations. It is asked while it is left out. */
|
|
10
|
+
readonly description?: string;
|
|
11
|
+
readonly dryRun: boolean;
|
|
12
|
+
/** Leave out the checks that run after the upload, as a bulk run does. */
|
|
13
|
+
readonly skipPostDeployChecks: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Whether a person watches this deploy.
|
|
16
|
+
*
|
|
17
|
+
* They get the diff of every file the merge request changed, in the diff
|
|
18
|
+
* tool they use for every other deploy, and they confirm the upload.
|
|
19
|
+
*/
|
|
20
|
+
readonly interactive: boolean;
|
|
21
|
+
constructor(customerPath: string, configName: string,
|
|
22
|
+
/** The number of the merged merge request. */
|
|
23
|
+
iid: number, approval: ApprovalAnswer,
|
|
24
|
+
/** The description of the installations. It is asked while it is left out. */
|
|
25
|
+
description?: string, dryRun?: boolean,
|
|
26
|
+
/** Leave out the checks that run after the upload, as a bulk run does. */
|
|
27
|
+
skipPostDeployChecks?: boolean,
|
|
28
|
+
/**
|
|
29
|
+
* Whether a person watches this deploy.
|
|
30
|
+
*
|
|
31
|
+
* They get the diff of every file the merge request changed, in the diff
|
|
32
|
+
* tool they use for every other deploy, and they confirm the upload.
|
|
33
|
+
*/
|
|
34
|
+
interactive?: boolean);
|
|
35
|
+
}
|
|
36
|
+
/** What a deploy of one configuration ended with, or would end with. */
|
|
37
|
+
export declare enum DeployOutcome {
|
|
38
|
+
/** A plan only: the live installation is the state before the merge request. */
|
|
39
|
+
Deployable = "deployable",
|
|
40
|
+
/** The merge request changes nothing this configuration deploys. */
|
|
41
|
+
Unchanged = "unchanged",
|
|
42
|
+
/** The configuration was deployed. */
|
|
43
|
+
Applied = "applied",
|
|
44
|
+
/** The configuration was left to a developer. */
|
|
45
|
+
Skipped = "skipped",
|
|
46
|
+
/** The live installation already carried the merge request. */
|
|
47
|
+
AlreadyDeployed = "alreadyDeployed",
|
|
48
|
+
/** The deploy of the configuration failed. */
|
|
49
|
+
Failed = "failed"
|
|
50
|
+
}
|
|
51
|
+
export interface MergeRequestDeployResult {
|
|
52
|
+
customerPath: string;
|
|
53
|
+
configName: string;
|
|
54
|
+
outcome: DeployOutcome;
|
|
55
|
+
/** Why the configuration was not deployed. */
|
|
56
|
+
reason?: string;
|
|
57
|
+
/** The files of the merge request that this deploy never uploads. */
|
|
58
|
+
notDeployed?: string[];
|
|
59
|
+
}
|