carlin 1.19.11 → 1.19.13

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.
Files changed (73) hide show
  1. package/dist/cli.js +232 -0
  2. package/dist/config.js +10 -0
  3. package/dist/deploy/addDefaults.cloudFormation.js +138 -0
  4. package/dist/deploy/baseStack/command.js +9 -0
  5. package/dist/deploy/baseStack/config.js +30 -0
  6. package/dist/deploy/baseStack/deployBaseStack.js +59 -0
  7. package/dist/deploy/baseStack/getBaseStackResource.js +26 -0
  8. package/dist/deploy/baseStack/getBucket.template.js +44 -0
  9. package/dist/deploy/baseStack/getLambdaImageBuilder.template.js +186 -0
  10. package/dist/deploy/baseStack/getLambdaLayerBuilder.template.js +140 -0
  11. package/dist/deploy/baseStack/getVpc.template.js +169 -0
  12. package/dist/deploy/cicd/cicd.template.js +922 -0
  13. package/dist/deploy/cicd/command.js +27 -0
  14. package/dist/deploy/cicd/command.options.js +71 -0
  15. package/dist/deploy/cicd/config.js +8 -0
  16. package/dist/deploy/cicd/deployCicd.js +93 -0
  17. package/dist/deploy/cicd/ecsTaskReportCommand.js +51 -0
  18. package/dist/deploy/cicd/getCicdStackName.js +11 -0
  19. package/dist/deploy/cicd/getTriggerPipelineObjectKey.js +11 -0
  20. package/dist/deploy/cicd/lambdas/cicdApiV1.handler.js +124 -0
  21. package/dist/deploy/cicd/lambdas/ecsTaskReport.handler.js +126 -0
  22. package/dist/deploy/cicd/lambdas/executeTasks.js +67 -0
  23. package/dist/deploy/cicd/lambdas/getProcessEnvVariable.js +10 -0
  24. package/dist/deploy/cicd/lambdas/githubWebhooksApiV1.handler.js +146 -0
  25. package/dist/deploy/cicd/lambdas/imageUpdaterSchedule.handler.js +44 -0
  26. package/dist/deploy/cicd/lambdas/index.js +13 -0
  27. package/dist/deploy/cicd/lambdas/pipelines.handler.js +134 -0
  28. package/dist/deploy/cicd/lambdas/putApprovalResultManualTask.js +52 -0
  29. package/dist/deploy/cicd/lambdas/shConditionalCommands.js +30 -0
  30. package/dist/deploy/cicd/pipelines.js +76 -0
  31. package/dist/deploy/cicd/readSSHKey.js +10 -0
  32. package/dist/deploy/cloudFormation.core.js +300 -0
  33. package/dist/deploy/cloudFormation.js +182 -0
  34. package/dist/deploy/command.js +185 -0
  35. package/dist/deploy/lambda/buildLambdaSingleFile.js +30 -0
  36. package/dist/deploy/lambda/deployLambdaCode.js +41 -0
  37. package/dist/deploy/lambda/deployLambdaLayers.js +34 -0
  38. package/dist/deploy/lambda/uploadCodeToECR.js +53 -0
  39. package/dist/deploy/lambda/uploadCodeToS3.js +31 -0
  40. package/dist/deploy/lambdaLayer/command.js +48 -0
  41. package/dist/deploy/lambdaLayer/deployLambdaLayer.js +140 -0
  42. package/dist/deploy/readDockerfile.js +18 -0
  43. package/dist/deploy/s3.js +165 -0
  44. package/dist/deploy/stackName.js +78 -0
  45. package/dist/deploy/staticApp/command.js +79 -0
  46. package/dist/deploy/staticApp/deployStaticApp.js +64 -0
  47. package/dist/deploy/staticApp/findDefaultBuildFolder.js +27 -0
  48. package/dist/deploy/staticApp/getOriginShieldRegion.js +30 -0
  49. package/dist/deploy/staticApp/getStaticAppBucket.js +19 -0
  50. package/dist/deploy/staticApp/invalidateCloudFront.js +42 -0
  51. package/dist/deploy/staticApp/removeOldVersions.js +43 -0
  52. package/dist/deploy/staticApp/staticApp.template.js +303 -0
  53. package/dist/deploy/staticApp/uploadBuiltAppToS3.js +27 -0
  54. package/dist/deploy/utils.js +29 -0
  55. package/dist/generateEnv/generateEnv.js +46 -0
  56. package/dist/generateEnv/generateEnvCommand.js +9 -0
  57. package/dist/index.js +5 -0
  58. package/dist/utils/addGroupToOptions.js +11 -0
  59. package/dist/utils/cloudFormationTemplate.js +132 -0
  60. package/dist/utils/codeBuild.js +50 -0
  61. package/dist/utils/environmentVariables.js +11 -0
  62. package/dist/utils/exec.js +22 -0
  63. package/dist/utils/formatCode.js +12 -0
  64. package/dist/utils/getAwsAccountId.js +10 -0
  65. package/dist/utils/getCurrentBranch.js +33 -0
  66. package/dist/utils/getEnvironment.js +6 -0
  67. package/dist/utils/getIamPath.js +6 -0
  68. package/dist/utils/getProjectName.js +35 -0
  69. package/dist/utils/index.js +17 -0
  70. package/dist/utils/packageJson.js +25 -0
  71. package/dist/utils/readCloudFormationTemplate.js +33 -0
  72. package/dist/utils/readObjectFile.js +46 -0
  73. package/package.json +3 -3
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.githubWebhooksApiV1Handler = exports.webhooks = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const pipelines_1 = require("../pipelines");
6
+ const aws_sdk_1 = require("aws-sdk");
7
+ const webhooks_1 = require("@octokit/webhooks");
8
+ const executeTasks_1 = require("./executeTasks");
9
+ const getProcessEnvVariable_1 = require("./getProcessEnvVariable");
10
+ const getTriggerPipelineObjectKey_1 = require("../getTriggerPipelineObjectKey");
11
+ const shConditionalCommands_1 = require("./shConditionalCommands");
12
+ const adm_zip_1 = tslib_1.__importDefault(require("adm-zip"));
13
+ const s3 = new aws_sdk_1.S3();
14
+ /**
15
+ * When this file is saved on S3, a CodePipeline pipeline is started.
16
+ */
17
+ const putJobDetails = async ({ pipeline, details, }) => {
18
+ const prefix = (0, getProcessEnvVariable_1.getProcessEnvVariable)('TRIGGER_PIPELINES_OBJECT_KEY_PREFIX');
19
+ const zip = new adm_zip_1.default();
20
+ const content = JSON.stringify(details);
21
+ zip.addFile(pipeline, Buffer.from(content));
22
+ return s3
23
+ .putObject({
24
+ Body: zip.toBuffer(),
25
+ Bucket: (0, getProcessEnvVariable_1.getProcessEnvVariable)('BASE_STACK_BUCKET_NAME'),
26
+ Key: (0, getTriggerPipelineObjectKey_1.getTriggerPipelinesObjectKey)({ prefix, pipeline }),
27
+ })
28
+ .promise();
29
+ };
30
+ /**
31
+ * Put outside of the handler to be able to spy on it.
32
+ */
33
+ exports.webhooks = new webhooks_1.Webhooks({ secret: '123' });
34
+ const getPipelines = () => {
35
+ const pipelines = JSON.parse(process.env.PIPELINES_JSON || JSON.stringify([]));
36
+ return pipelines;
37
+ };
38
+ exports.webhooks.on('push', async (details) => {
39
+ if (!getPipelines().includes('tag')) {
40
+ return;
41
+ }
42
+ if (details.payload.ref.startsWith('refs/tags/')) {
43
+ await putJobDetails({ pipeline: 'tag', details });
44
+ }
45
+ });
46
+ exports.webhooks.on('push', async (details) => {
47
+ if (!getPipelines().includes('main')) {
48
+ return;
49
+ }
50
+ if (details.payload.ref === 'refs/heads/main') {
51
+ await putJobDetails({ pipeline: 'main', details });
52
+ }
53
+ });
54
+ exports.webhooks.on(['pull_request.opened', 'pull_request.reopened', 'pull_request.synchronize'], async ({ payload }) => {
55
+ if (!getPipelines().includes('pr')) {
56
+ return;
57
+ }
58
+ if (payload.pull_request.draft) {
59
+ return;
60
+ }
61
+ await (0, executeTasks_1.executeTasks)({
62
+ commands: [
63
+ (0, shConditionalCommands_1.shConditionalCommands)({
64
+ conditionalCommands: (0, pipelines_1.getPrCommands)({
65
+ branch: payload.pull_request.head.ref,
66
+ }),
67
+ }),
68
+ ],
69
+ tags: [
70
+ { key: 'Pipeline', value: 'pr' },
71
+ { key: 'PullRequest', value: payload.number.toString() },
72
+ { key: 'PullRequestUrl', value: payload.pull_request.url },
73
+ { key: 'Action', value: payload.action },
74
+ { key: 'Branch', value: payload.pull_request.head.ref },
75
+ ],
76
+ });
77
+ });
78
+ exports.webhooks.on(['pull_request.closed'], async ({ payload }) => {
79
+ if (!getPipelines().includes('pr')) {
80
+ return;
81
+ }
82
+ /**
83
+ * https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-cpu-memory-error.html
84
+ */
85
+ await (0, executeTasks_1.executeTasks)({
86
+ cpu: '512',
87
+ memory: '2048',
88
+ commands: [
89
+ (0, shConditionalCommands_1.shConditionalCommands)({
90
+ conditionalCommands: (0, pipelines_1.getClosedPrCommands)({
91
+ branch: payload.pull_request.head.ref,
92
+ }),
93
+ }),
94
+ ],
95
+ tags: [
96
+ { key: 'Pipeline', value: 'pr' },
97
+ { key: 'PullRequest', value: payload.number.toString() },
98
+ { key: 'PullRequestTitle', value: payload.pull_request.title },
99
+ { key: 'PullRequestUrl', value: payload.pull_request.url },
100
+ { key: 'Action', value: payload.action },
101
+ { key: 'Branch', value: payload.pull_request.head.ref },
102
+ ],
103
+ });
104
+ });
105
+ const githubWebhooksApiV1Handler = async (event, context) => {
106
+ try {
107
+ /**
108
+ * Ends function immediately after callback.
109
+ */
110
+ context.callbackWaitsForEmptyEventLoop = false;
111
+ const { body, headers } = event;
112
+ if (!body) {
113
+ throw new Error("event.body doesn't exist.");
114
+ }
115
+ const xGitHubDelivery = headers['X-GitHub-Delivery'];
116
+ const xGitHubEvent = headers['X-GitHub-Event'];
117
+ const xHubSignature = headers['X-Hub-Signature-256'] || headers['X-Hub-Signature'];
118
+ if (!xGitHubDelivery) {
119
+ throw new Error("X-GitHub-Delivery doesn't exist.");
120
+ }
121
+ if (!xGitHubEvent) {
122
+ throw new Error("X-GitHub-Event doesn't exist.");
123
+ }
124
+ if (!xHubSignature) {
125
+ throw new Error("X-Hub-Signature-256 or X-Hub-Signature doesn't exist.");
126
+ }
127
+ exports.webhooks.onError((onErrorEvent) => {
128
+ throw onErrorEvent;
129
+ });
130
+ /**
131
+ * Replace "receive" for "verifyAndReceive" when WebCrypto exist on Node.js
132
+ * API.
133
+ */
134
+ await exports.webhooks.receive({
135
+ id: xGitHubDelivery,
136
+ name: xGitHubEvent,
137
+ // signature: xHubSignature,
138
+ payload: JSON.parse(body),
139
+ });
140
+ return { statusCode: 200, body: JSON.stringify({ ok: true }) };
141
+ }
142
+ catch (error) {
143
+ return { statusCode: error.status || 500, body: error.message };
144
+ }
145
+ };
146
+ exports.githubWebhooksApiV1Handler = githubWebhooksApiV1Handler;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.imageUpdaterScheduleHandler = void 0;
4
+ const config_1 = require("../config");
5
+ const executeTasks_1 = require("./executeTasks");
6
+ const shConditionalCommands_1 = require("./shConditionalCommands");
7
+ /**
8
+ * Update CI/CD resources with the newest carlin and repository image.
9
+ */
10
+ const imageUpdaterScheduleHandler = async () => {
11
+ const cicdConfig = process.env.CICD_CONFIG;
12
+ if (!cicdConfig) {
13
+ return;
14
+ }
15
+ const command = (0, shConditionalCommands_1.shConditionalCommands)({
16
+ conditionalCommands: [
17
+ /**
18
+ * -e Exit immediately if a command exits with a non-zero status.
19
+ */
20
+ 'set -e',
21
+ 'git status',
22
+ 'git fetch',
23
+ 'git pull origin main',
24
+ 'git rev-parse HEAD',
25
+ 'yarn global add carlin',
26
+ `cd ${config_1.CICD_FOLDER_NAME}`,
27
+ 'echo $CICD_CONFIG > carlin.json',
28
+ 'cat carlin.json',
29
+ `carlin deploy cicd -c carlin.json`,
30
+ ],
31
+ });
32
+ await (0, executeTasks_1.executeTasks)({
33
+ commands: [command],
34
+ cpu: '512',
35
+ memory: '2048',
36
+ taskEnvironment: [
37
+ {
38
+ name: 'CICD_CONFIG',
39
+ value: cicdConfig,
40
+ },
41
+ ],
42
+ });
43
+ };
44
+ exports.imageUpdaterScheduleHandler = imageUpdaterScheduleHandler;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pipelinesHandler = exports.imageUpdaterScheduleHandler = exports.githubWebhooksApiV1Handler = exports.ecsTaskReportHandler = exports.cicdApiV1Handler = void 0;
4
+ var cicdApiV1_handler_1 = require("./cicdApiV1.handler");
5
+ Object.defineProperty(exports, "cicdApiV1Handler", { enumerable: true, get: function () { return cicdApiV1_handler_1.cicdApiV1Handler; } });
6
+ var ecsTaskReport_handler_1 = require("./ecsTaskReport.handler");
7
+ Object.defineProperty(exports, "ecsTaskReportHandler", { enumerable: true, get: function () { return ecsTaskReport_handler_1.ecsTaskReportHandler; } });
8
+ var githubWebhooksApiV1_handler_1 = require("./githubWebhooksApiV1.handler");
9
+ Object.defineProperty(exports, "githubWebhooksApiV1Handler", { enumerable: true, get: function () { return githubWebhooksApiV1_handler_1.githubWebhooksApiV1Handler; } });
10
+ var imageUpdaterSchedule_handler_1 = require("./imageUpdaterSchedule.handler");
11
+ Object.defineProperty(exports, "imageUpdaterScheduleHandler", { enumerable: true, get: function () { return imageUpdaterSchedule_handler_1.imageUpdaterScheduleHandler; } });
12
+ var pipelines_handler_1 = require("./pipelines.handler");
13
+ Object.defineProperty(exports, "pipelinesHandler", { enumerable: true, get: function () { return pipelines_handler_1.pipelinesHandler; } });
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pipelinesHandler = exports.getJobDetails = exports.getJobDetailsFilename = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs = tslib_1.__importStar(require("fs"));
6
+ const aws_sdk_1 = require("aws-sdk");
7
+ const pipelines_1 = require("../pipelines");
8
+ const executeTasks_1 = require("./executeTasks");
9
+ const putApprovalResultManualTask_1 = require("./putApprovalResultManualTask");
10
+ const shConditionalCommands_1 = require("./shConditionalCommands");
11
+ const adm_zip_1 = tslib_1.__importDefault(require("adm-zip"));
12
+ const codepipeline = new aws_sdk_1.CodePipeline();
13
+ const getUserParameters = (event) => {
14
+ const [pipeline, stage] = event['CodePipeline.job'].data.actionConfiguration.configuration.UserParameters.split('&');
15
+ return { pipeline: pipeline, stage };
16
+ };
17
+ const getJobDetailsFilename = (jobId) => `/tmp/${jobId}.zip`;
18
+ exports.getJobDetailsFilename = getJobDetailsFilename;
19
+ const getJobDetails = async (event) => {
20
+ const jobId = event['CodePipeline.job'].id;
21
+ const s3 = new aws_sdk_1.S3({
22
+ credentials: event['CodePipeline.job'].data.artifactCredentials,
23
+ });
24
+ const { bucketName, objectKey } = event['CodePipeline.job'].data.inputArtifacts[0].location.s3Location;
25
+ const { Body } = await s3
26
+ .getObject({ Bucket: bucketName, Key: objectKey })
27
+ .promise();
28
+ if (!Body) {
29
+ throw new Error('Cannot retrieve the job description (there is no input artifact).');
30
+ }
31
+ const filename = (0, exports.getJobDetailsFilename)(jobId);
32
+ await fs.promises.writeFile(filename, Body, {});
33
+ const zip = new adm_zip_1.default(filename);
34
+ const file = zip.readAsText(getUserParameters(event).pipeline);
35
+ try {
36
+ return JSON.parse(file);
37
+ }
38
+ catch {
39
+ throw new Error(`Job details is not a valid json. ${file}`);
40
+ }
41
+ };
42
+ exports.getJobDetails = getJobDetails;
43
+ const pipelinesHandler = async (event) => {
44
+ var _a, _b;
45
+ const jobId = event['CodePipeline.job'].id;
46
+ let pipelineName;
47
+ try {
48
+ const { pipeline } = getUserParameters(event);
49
+ const gitHubJobDetails = await (0, exports.getJobDetails)(event);
50
+ const { jobDetails } = await codepipeline
51
+ .getJobDetails({ jobId })
52
+ .promise();
53
+ pipelineName = (_b = (_a = jobDetails === null || jobDetails === void 0 ? void 0 : jobDetails.data) === null || _a === void 0 ? void 0 : _a.pipelineContext) === null || _b === void 0 ? void 0 : _b.pipelineName;
54
+ const executeTasksInput = (() => {
55
+ const tags = [
56
+ {
57
+ key: 'Pipeline',
58
+ value: pipeline,
59
+ },
60
+ {
61
+ key: 'AfterCommit',
62
+ value: gitHubJobDetails.payload.after,
63
+ },
64
+ ];
65
+ const taskEnvironment = [];
66
+ if (pipelineName) {
67
+ tags.push({
68
+ key: 'PipelineName',
69
+ value: pipelineName,
70
+ });
71
+ taskEnvironment.push({
72
+ name: 'PIPELINE_NAME',
73
+ value: pipelineName,
74
+ });
75
+ }
76
+ if (pipeline === 'main') {
77
+ return {
78
+ commands: [
79
+ (0, shConditionalCommands_1.shConditionalCommands)({
80
+ conditionalCommands: (0, pipelines_1.getMainCommands)(),
81
+ }),
82
+ ],
83
+ tags,
84
+ taskEnvironment,
85
+ };
86
+ }
87
+ if (pipeline === 'tag') {
88
+ const tag = gitHubJobDetails.payload.ref.split('/')[2];
89
+ return {
90
+ commands: [
91
+ (0, shConditionalCommands_1.shConditionalCommands)({
92
+ conditionalCommands: (0, pipelines_1.getTagCommands)({ tag }),
93
+ }),
94
+ ],
95
+ tags: [
96
+ ...tags,
97
+ {
98
+ key: 'Tag',
99
+ value: tag,
100
+ },
101
+ ],
102
+ taskEnvironment,
103
+ };
104
+ }
105
+ return undefined;
106
+ })();
107
+ if (!executeTasksInput) {
108
+ throw new Error('executeTasksInputUndefined');
109
+ }
110
+ await (0, executeTasks_1.executeTasks)(executeTasksInput);
111
+ await codepipeline.putJobSuccessResult({ jobId }).promise();
112
+ }
113
+ catch (error) {
114
+ if (pipelineName) {
115
+ await (0, putApprovalResultManualTask_1.putApprovalResultManualTask)({
116
+ pipelineName,
117
+ /**
118
+ * https://docs.aws.amazon.com/codepipeline/latest/APIReference/API_ApprovalResult.html
119
+ */
120
+ result: { status: 'Rejected', summary: error.message.slice(0, 511) },
121
+ });
122
+ }
123
+ await codepipeline
124
+ .putJobFailureResult({
125
+ jobId,
126
+ failureDetails: {
127
+ type: 'JobFailed',
128
+ message: error.message.slice(0, 4999),
129
+ },
130
+ })
131
+ .promise();
132
+ }
133
+ };
134
+ exports.pipelinesHandler = pipelinesHandler;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.putApprovalResultManualTask = void 0;
4
+ const aws_sdk_1 = require("aws-sdk");
5
+ const config_1 = require("../config");
6
+ const codepipeline = new aws_sdk_1.CodePipeline();
7
+ const FIVE_SECONDS = 5 * 1000;
8
+ const getApprovalActionToken = ({ actionName, stageName, pipelineName, }) => new Promise((resolve, reject) => {
9
+ setTimeout(() => {
10
+ codepipeline.getPipelineState({ name: pipelineName }, async (err, { stageStates = [] }) => {
11
+ var _a;
12
+ if (err) {
13
+ return reject(err);
14
+ }
15
+ const approvalStageState = stageStates.find((s) => s.stageName === stageName);
16
+ if (!approvalStageState) {
17
+ throw new Error('ApprovalStageStateIsUndefined');
18
+ }
19
+ const approvalActionState = (_a = approvalStageState.actionStates) === null || _a === void 0 ? void 0 : _a.find((a) => a.actionName === actionName);
20
+ if (!approvalActionState) {
21
+ throw new Error('ApprovalActionStateIsUndefined');
22
+ }
23
+ const { latestExecution } = approvalActionState;
24
+ if (latestExecution && latestExecution.status === 'InProgress') {
25
+ return resolve(latestExecution.token);
26
+ }
27
+ try {
28
+ return resolve(await getApprovalActionToken({
29
+ actionName,
30
+ stageName,
31
+ pipelineName,
32
+ }));
33
+ }
34
+ catch (error) {
35
+ return reject(error);
36
+ }
37
+ });
38
+ }, FIVE_SECONDS);
39
+ });
40
+ const putApprovalResultManualTask = async ({ pipelineName, result, }) => {
41
+ const actionName = config_1.PIPELINE_ECS_TASK_EXECUTION_MANUAL_APPROVAL_ACTION_NAME;
42
+ const stageName = config_1.PIPELINE_ECS_TASK_EXECUTION_STAGE_NAME;
43
+ const token = await getApprovalActionToken({
44
+ actionName,
45
+ stageName,
46
+ pipelineName,
47
+ });
48
+ await codepipeline
49
+ .putApprovalResult({ pipelineName, stageName, actionName, result, token })
50
+ .promise();
51
+ };
52
+ exports.putApprovalResultManualTask = putApprovalResultManualTask;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.shConditionalCommands = exports.compileCommands = void 0;
4
+ const compileCommands = (commands) => {
5
+ return commands.map((c) => c.replace(/;$/, '')).join(' && ');
6
+ };
7
+ exports.compileCommands = compileCommands;
8
+ const approvedStatus = 'Approved';
9
+ const rejectedStatus = 'Rejected';
10
+ const defaultSuccessCommands = [
11
+ `carlin cicd-ecs-task-report --status=${approvedStatus}`,
12
+ ];
13
+ const defaultFailureCommands = [
14
+ `carlin cicd-ecs-task-report --status=${rejectedStatus}`,
15
+ ];
16
+ const defaultFinallyCommands = ['echo "Finally Command"'];
17
+ const shConditionalCommands = ({ conditionalCommands, successCommands = defaultSuccessCommands, failureCommands = defaultFailureCommands, finallyCommands = defaultFinallyCommands, }) => {
18
+ const conditionalCommand = (0, exports.compileCommands)(conditionalCommands);
19
+ const successCommand = (0, exports.compileCommands)([
20
+ 'echo "Success Command"',
21
+ ...successCommands,
22
+ ]);
23
+ const failureCommand = (0, exports.compileCommands)([
24
+ 'echo "Failure Command"',
25
+ ...failureCommands,
26
+ ]);
27
+ const finallyCommand = (0, exports.compileCommands)(finallyCommands);
28
+ return `if ${conditionalCommand}; then ${successCommand}; else ${failureCommand}; fi; ${finallyCommand}`;
29
+ };
30
+ exports.shConditionalCommands = shConditionalCommands;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTagCommands = exports.getMainCommands = exports.getClosedPrCommands = exports.getPrCommands = exports.getCommandFileDir = exports.pipelines = void 0;
4
+ const config_1 = require("./config");
5
+ exports.pipelines = ['pr', 'main', 'tag'];
6
+ const getCommandFileDir = (pipeline) => `./${config_1.CICD_FOLDER_NAME}/commands/${pipeline}.sh`;
7
+ exports.getCommandFileDir = getCommandFileDir;
8
+ const getPrCommands = ({ branch }) => [
9
+ /**
10
+ * -e Exit immediately if a command exits with a non-zero status.
11
+ */
12
+ 'set -e',
13
+ 'git status',
14
+ 'git fetch',
15
+ /**
16
+ * Update to the most recent main branch to Lerna performs the diff properly.
17
+ */
18
+ 'git pull origin main',
19
+ `git checkout ${branch} || (echo 'branch not found, probably deleted'; exit 0)`,
20
+ `git pull origin ${branch}`,
21
+ 'git rev-parse HEAD',
22
+ 'git status',
23
+ 'yarn install --frozen-lockfile',
24
+ `sh -e ${(0, exports.getCommandFileDir)('pr')}`,
25
+ ];
26
+ exports.getPrCommands = getPrCommands;
27
+ const getClosedPrCommands = ({ branch }) => [
28
+ 'git status',
29
+ 'git fetch',
30
+ /**
31
+ * Get the most recent main because the PR was approved.
32
+ */
33
+ 'git pull origin main',
34
+ 'git rev-parse HEAD',
35
+ `export CARLIN_BRANCH=${branch}`,
36
+ /**
37
+ * Exit without error if `closed-pr` does not exist.
38
+ */
39
+ `[ ! -f "${(0, exports.getCommandFileDir)('closed-pr')}" ] && echo 'closed-pr command not found' || sh ${(0, exports.getCommandFileDir)('closed-pr')}`,
40
+ ];
41
+ exports.getClosedPrCommands = getClosedPrCommands;
42
+ const getMainCommands = () => [
43
+ /**
44
+ * -e Exit immediately if a command exits with a non-zero status.
45
+ */
46
+ 'set -e',
47
+ `export CARLIN_ENVIRONMENT=Staging`,
48
+ 'git status',
49
+ 'git fetch',
50
+ 'git pull origin main',
51
+ 'git rev-parse HEAD',
52
+ /**
53
+ * Reporting `MainTagFound` before exiting the process. This command blocks
54
+ * the process if tag was found. If we don't do this, the loop would never
55
+ * end because `main` command can create a tag, that would trigger this
56
+ * pipeline again.
57
+ */
58
+ 'if git describe --exact-match; then echo "Tag found" && carlin cicd-ecs-task-report --status=MainTagFound && exit 0; fi',
59
+ 'yarn install --frozen-lockfile',
60
+ `sh -e ${(0, exports.getCommandFileDir)('main')}`,
61
+ ];
62
+ exports.getMainCommands = getMainCommands;
63
+ const getTagCommands = ({ tag }) => [
64
+ /**
65
+ * -e Exit immediately if a command exits with a non-zero status.
66
+ */
67
+ 'set -e',
68
+ `export CARLIN_ENVIRONMENT=Production`,
69
+ 'git status',
70
+ 'git fetch --tags',
71
+ `git checkout tags/${tag} -b ${tag}-branch`,
72
+ 'git rev-parse HEAD',
73
+ 'yarn install --frozen-lockfile',
74
+ `sh -e ${(0, exports.getCommandFileDir)('tag')}`,
75
+ ];
76
+ exports.getTagCommands = getTagCommands;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readSSHKey = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs = tslib_1.__importStar(require("fs"));
6
+ /**
7
+ * Created to allow mocking.
8
+ */
9
+ const readSSHKey = (dir) => fs.readFileSync(dir, 'utf-8');
10
+ exports.readSSHKey = readSSHKey;