carlin 1.19.6 → 1.19.7

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.
@@ -63,9 +63,6 @@ const getEcsTaskTags = async ({ ecsTaskArn, }) => {
63
63
  }
64
64
  };
65
65
  exports.getEcsTaskTags = getEcsTaskTags;
66
- (0, exports.getEcsTaskTags)({
67
- ecsTaskArn: 'arn:aws:ecs:us-east-1:483684946879:task/CarlinCicdCarlinMonorepo-RepositoryTasksECSCluster-1J6saGT91hCr/f70d559c47804d6383df170712d3e455',
68
- }).then();
69
66
  /**
70
67
  * This method is invoked when an ECS task is executed and the success or
71
68
  * failure commands calls `carlin cicd-ecs-task-report --status=<status>`.
@@ -1,36 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.executeTasks = exports.shConditionalCommands = void 0;
3
+ exports.executeTasks = void 0;
4
4
  const aws_sdk_1 = require("aws-sdk");
5
+ const shConditionalCommands_1 = require("./shConditionalCommands");
5
6
  const getProcessEnvVariable_1 = require("./getProcessEnvVariable");
6
7
  const ecs = new aws_sdk_1.ECS({ apiVersion: '2014-11-13', maxRetries: 3 });
7
- const compileCommands = (commands) => {
8
- return commands.map((c) => c.replace(/;$/, '')).join(' && ');
9
- };
10
- const approvedStatus = 'Approved';
11
- const rejectedStatus = 'Rejected';
12
- const successCommands = [
13
- `carlin cicd-ecs-task-report --status=${approvedStatus}`,
14
- ];
15
- const failureCommands = [
16
- `carlin cicd-ecs-task-report --status=${rejectedStatus}`,
17
- ];
18
- const shConditionalCommands = ({ conditionalCommands, }) => {
19
- const conditionalCommand = compileCommands(conditionalCommands);
20
- const successCommand = compileCommands([
21
- 'echo "Success Command"',
22
- ...successCommands,
23
- ]);
24
- const failureCommand = compileCommands([
25
- 'echo "Failure Command"',
26
- ...failureCommands,
27
- ]);
28
- const finallyCommand = compileCommands(['echo "Finally Command"']);
29
- return `if ${conditionalCommand}; then ${successCommand}; else ${failureCommand}; fi; ${finallyCommand}`;
30
- };
31
- exports.shConditionalCommands = shConditionalCommands;
32
8
  const executeTasks = async ({ commands = [], cpu, memory, taskEnvironment = [], tags = [], }) => {
33
- const command = compileCommands([
9
+ const command = (0, shConditionalCommands_1.compileCommands)([
34
10
  /**
35
11
  * https://stackoverflow.com/questions/2853803/how-to-echo-shell-commands-as-they-are-executed/2853811
36
12
  */
@@ -8,6 +8,7 @@ const webhooks_1 = require("@octokit/webhooks");
8
8
  const executeTasks_1 = require("./executeTasks");
9
9
  const getProcessEnvVariable_1 = require("./getProcessEnvVariable");
10
10
  const getTriggerPipelineObjectKey_1 = require("../getTriggerPipelineObjectKey");
11
+ const shConditionalCommands_1 = require("./shConditionalCommands");
11
12
  const adm_zip_1 = tslib_1.__importDefault(require("adm-zip"));
12
13
  const s3 = new aws_sdk_1.S3();
13
14
  /**
@@ -59,7 +60,7 @@ exports.webhooks.on(['pull_request.opened', 'pull_request.reopened', 'pull_reque
59
60
  }
60
61
  await (0, executeTasks_1.executeTasks)({
61
62
  commands: [
62
- (0, executeTasks_1.shConditionalCommands)({
63
+ (0, shConditionalCommands_1.shConditionalCommands)({
63
64
  conditionalCommands: (0, pipelines_1.getPrCommands)({
64
65
  branch: payload.pull_request.head.ref,
65
66
  }),
@@ -85,7 +86,7 @@ exports.webhooks.on(['pull_request.closed'], async ({ payload }) => {
85
86
  cpu: '512',
86
87
  memory: '2048',
87
88
  commands: [
88
- (0, executeTasks_1.shConditionalCommands)({
89
+ (0, shConditionalCommands_1.shConditionalCommands)({
89
90
  conditionalCommands: (0, pipelines_1.getClosedPrCommands)({
90
91
  branch: payload.pull_request.head.ref,
91
92
  }),
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.imageUpdaterScheduleHandler = void 0;
4
+ const config_1 = require("../config");
4
5
  const executeTasks_1 = require("./executeTasks");
6
+ const shConditionalCommands_1 = require("./shConditionalCommands");
5
7
  /**
6
8
  * Update CI/CD resources with the newest carlin and repository image.
7
9
  */
@@ -10,20 +12,25 @@ const imageUpdaterScheduleHandler = async () => {
10
12
  if (!cicdConfig) {
11
13
  return;
12
14
  }
13
- const commands = [
14
- 'set -e',
15
- 'git status',
16
- 'git fetch',
17
- 'git pull origin main',
18
- 'git rev-parse HEAD',
19
- 'yarn global add carlin',
20
- 'cd cicd',
21
- 'echo $CICD_CONFIG > carlin.json',
22
- 'cat carlin.json',
23
- `carlin deploy cicd -c carlin.json`,
24
- ];
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
+ });
25
32
  await (0, executeTasks_1.executeTasks)({
26
- commands,
33
+ commands: [command],
27
34
  cpu: '512',
28
35
  memory: '2048',
29
36
  taskEnvironment: [
@@ -7,6 +7,7 @@ const aws_sdk_1 = require("aws-sdk");
7
7
  const pipelines_1 = require("../pipelines");
8
8
  const executeTasks_1 = require("./executeTasks");
9
9
  const putApprovalResultManualTask_1 = require("./putApprovalResultManualTask");
10
+ const shConditionalCommands_1 = require("./shConditionalCommands");
10
11
  const adm_zip_1 = tslib_1.__importDefault(require("adm-zip"));
11
12
  const codepipeline = new aws_sdk_1.CodePipeline();
12
13
  const getUserParameters = (event) => {
@@ -75,7 +76,7 @@ const pipelinesHandler = async (event) => {
75
76
  if (pipeline === 'main') {
76
77
  return {
77
78
  commands: [
78
- (0, executeTasks_1.shConditionalCommands)({
79
+ (0, shConditionalCommands_1.shConditionalCommands)({
79
80
  conditionalCommands: (0, pipelines_1.getMainCommands)(),
80
81
  }),
81
82
  ],
@@ -87,7 +88,7 @@ const pipelinesHandler = async (event) => {
87
88
  const tag = gitHubJobDetails.payload.ref.split('/')[2];
88
89
  return {
89
90
  commands: [
90
- (0, executeTasks_1.shConditionalCommands)({
91
+ (0, shConditionalCommands_1.shConditionalCommands)({
91
92
  conditionalCommands: (0, pipelines_1.getTagCommands)({ tag }),
92
93
  }),
93
94
  ],
@@ -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;
@@ -6,6 +6,9 @@ exports.pipelines = ['pr', 'main', 'tag'];
6
6
  const getCommandFileDir = (pipeline) => `./${config_1.CICD_FOLDER_NAME}/commands/${pipeline}`;
7
7
  exports.getCommandFileDir = getCommandFileDir;
8
8
  const getPrCommands = ({ branch }) => [
9
+ /**
10
+ * -e Exit immediately if a command exits with a non-zero status.
11
+ */
9
12
  'set -e',
10
13
  'git status',
11
14
  'git fetch',
@@ -37,6 +40,9 @@ const getClosedPrCommands = ({ branch }) => [
37
40
  ];
38
41
  exports.getClosedPrCommands = getClosedPrCommands;
39
42
  const getMainCommands = () => [
43
+ /**
44
+ * -e Exit immediately if a command exits with a non-zero status.
45
+ */
40
46
  'set -e',
41
47
  `export CARLIN_ENVIRONMENT=Staging`,
42
48
  'git status',
@@ -55,6 +61,9 @@ const getMainCommands = () => [
55
61
  ];
56
62
  exports.getMainCommands = getMainCommands;
57
63
  const getTagCommands = ({ tag }) => [
64
+ /**
65
+ * -e Exit immediately if a command exits with a non-zero status.
66
+ */
58
67
  'set -e',
59
68
  `export CARLIN_ENVIRONMENT=Production`,
60
69
  'git status',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carlin",
3
- "version": "1.19.6",
3
+ "version": "1.19.7",
4
4
  "description": "",
5
5
  "license": "GPL-3.0",
6
6
  "author": "Pedro Arantes <arantespp@gmail.com> (https://twitter.com/arantespp)",
@@ -71,5 +71,5 @@
71
71
  "publishConfig": {
72
72
  "registry": "https://registry.npmjs.org/"
73
73
  },
74
- "gitHead": "f5cd08c3e4f80d41492f5d56879348b1bc2948cb"
74
+ "gitHead": "7e731b5b04483047f3a3a2087fa3de253a4ed134"
75
75
  }