carlin 0.19.5 → 0.19.6

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 CHANGED
@@ -3,6 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.19.6](https://github.com/ttoss/carlin/compare/v0.19.5...v0.19.6) (2021-09-18)
7
+
8
+ ### Bug Fixes
9
+
10
+ - pipeline bucket object duplication ([3090748](https://github.com/ttoss/carlin/commit/3090748258818af3c5ca8a38a1c65c0fc1b21760))
11
+
6
12
  ## [0.19.5](https://github.com/ttoss/carlin/compare/v0.19.4...v0.19.5) (2021-09-17)
7
13
 
8
14
  ### Bug Fixes
@@ -183,6 +183,16 @@ const getRepositoryImageBuilder = () => ({
183
183
  },
184
184
  });
185
185
  exports.getRepositoryImageBuilder = getRepositoryImageBuilder;
186
+ /**
187
+ * This variable is used inside GitHub webhooks to identify the object key
188
+ * prefix of the file that triggers the pipelines.
189
+ */
190
+ const triggerPipelinesObjectKeyPrefix = [
191
+ 'cicd',
192
+ 'pipelines',
193
+ 'triggers',
194
+ utils_1.getProjectName(),
195
+ ].join('/');
186
196
  const getCicdTemplate = ({ pipelines = [], cpu = config_2.ECS_TASK_DEFAULT_CPU, memory = config_2.ECS_TASK_DEFAULT_MEMORY, s3, slackWebhookUrl, taskEnvironment = [], }) => {
187
197
  const resources = {};
188
198
  const executeEcsTaskVariables = {
@@ -391,7 +401,7 @@ const getCicdTemplate = ({ pipelines = [], cpu = config_2.ECS_TASK_DEFAULT_CPU,
391
401
  Effect: 'Allow',
392
402
  Resource: {
393
403
  'Fn::Sub': [
394
- `arn:aws:s3:::\${BucketName}/${getTriggerPipelineObjectKey_1.TRIGGER_PIPELINES_OBJECT_KEY_PREFIX}*`,
404
+ `arn:aws:s3:::\${BucketName}/${triggerPipelinesObjectKeyPrefix}*`,
395
405
  {
396
406
  BucketName: {
397
407
  'Fn::ImportValue': config_1.BASE_STACK_BUCKET_NAME_EXPORTED_NAME,
@@ -481,6 +491,7 @@ const getCicdTemplate = ({ pipelines = [], cpu = config_2.ECS_TASK_DEFAULT_CPU,
481
491
  BASE_STACK_BUCKET_NAME: {
482
492
  'Fn::ImportValue': config_1.BASE_STACK_BUCKET_NAME_EXPORTED_NAME,
483
493
  },
494
+ TRIGGER_PIPELINES_OBJECT_KEY_PREFIX: triggerPipelinesObjectKeyPrefix,
484
495
  PIPELINES_JSON: JSON.stringify(pipelines),
485
496
  ...executeEcsTaskVariables,
486
497
  },
@@ -729,7 +740,7 @@ const getCicdTemplate = ({ pipelines = [], cpu = config_2.ECS_TASK_DEFAULT_CPU,
729
740
  Action: 's3:*',
730
741
  Resource: {
731
742
  'Fn::Sub': [
732
- `arn:aws:s3:::\${BucketName}/${getTriggerPipelineObjectKey_1.TRIGGER_PIPELINES_OBJECT_KEY_PREFIX}*`,
743
+ `arn:aws:s3:::\${BucketName}/${triggerPipelinesObjectKeyPrefix}*`,
733
744
  {
734
745
  BucketName: {
735
746
  'Fn::ImportValue': config_1.BASE_STACK_BUCKET_NAME_EXPORTED_NAME,
@@ -786,7 +797,10 @@ const getCicdTemplate = ({ pipelines = [], cpu = config_2.ECS_TASK_DEFAULT_CPU,
786
797
  S3Bucket: {
787
798
  'Fn::ImportValue': config_1.BASE_STACK_BUCKET_NAME_EXPORTED_NAME,
788
799
  },
789
- S3ObjectKey: getTriggerPipelineObjectKey_1.getTriggerPipelinesObjectKey(pipeline),
800
+ S3ObjectKey: getTriggerPipelineObjectKey_1.getTriggerPipelinesObjectKey({
801
+ prefix: triggerPipelinesObjectKeyPrefix,
802
+ pipeline,
803
+ }),
790
804
  },
791
805
  Name: `Pipeline${pipelinePascalCase}S3SourceAction`,
792
806
  OutputArtifacts: [
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTriggerPipelinesObjectKey = exports.TRIGGER_PIPELINES_OBJECT_KEY_PREFIX = void 0;
4
- exports.TRIGGER_PIPELINES_OBJECT_KEY_PREFIX = 'cicd/pipelines/triggers/';
3
+ exports.getTriggerPipelinesObjectKey = void 0;
5
4
  /**
6
5
  * The file with this key inside the source S3 key of main and tag pipelines
7
6
  * will trigger those pipelines.
8
7
  */
9
- const getTriggerPipelinesObjectKey = (pipeline) => {
10
- return `${exports.TRIGGER_PIPELINES_OBJECT_KEY_PREFIX}${pipeline}.zip`;
8
+ const getTriggerPipelinesObjectKey = ({ prefix, pipeline, }) => {
9
+ return `${prefix}/${pipeline}.zip`;
11
10
  };
12
11
  exports.getTriggerPipelinesObjectKey = getTriggerPipelinesObjectKey;
@@ -5,6 +5,6 @@ const getProcessEnvVariable = (env) => {
5
5
  if (process.env[env]) {
6
6
  return process.env[env];
7
7
  }
8
- throw new Error(`process.env.${env} doesn't exist.`);
8
+ throw new Error(`process.env.${env} is not defined.`);
9
9
  };
10
10
  exports.getProcessEnvVariable = getProcessEnvVariable;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.githubWebhooksApiV1Handler = void 0;
6
+ exports.githubWebhooksApiV1Handler = exports.webhooks = void 0;
7
7
  const webhooks_1 = require("@octokit/webhooks");
8
8
  const adm_zip_1 = __importDefault(require("adm-zip"));
9
9
  const aws_sdk_1 = require("aws-sdk");
@@ -12,10 +12,15 @@ const pipelines_1 = require("../pipelines");
12
12
  const executeTasks_1 = require("./executeTasks");
13
13
  const getProcessEnvVariable_1 = require("./getProcessEnvVariable");
14
14
  const s3 = new aws_sdk_1.S3();
15
+ /**
16
+ * Put outside of the handler to be able to spy on it.
17
+ */
18
+ exports.webhooks = new webhooks_1.Webhooks({ secret: '123' });
15
19
  /**
16
20
  * When this file is saved on S3, a CodePipeline pipeline is started.
17
21
  */
18
22
  const putJobDetails = async ({ pipeline, details, }) => {
23
+ const prefix = getProcessEnvVariable_1.getProcessEnvVariable('TRIGGER_PIPELINES_OBJECT_KEY_PREFIX');
19
24
  const zip = new adm_zip_1.default();
20
25
  const content = JSON.stringify(details);
21
26
  zip.addFile(pipeline, Buffer.from(content));
@@ -23,7 +28,7 @@ const putJobDetails = async ({ pipeline, details, }) => {
23
28
  .putObject({
24
29
  Body: zip.toBuffer(),
25
30
  Bucket: getProcessEnvVariable_1.getProcessEnvVariable('BASE_STACK_BUCKET_NAME'),
26
- Key: getTriggerPipelineObjectKey_1.getTriggerPipelinesObjectKey(pipeline),
31
+ Key: getTriggerPipelineObjectKey_1.getTriggerPipelinesObjectKey({ prefix, pipeline }),
27
32
  })
28
33
  .promise();
29
34
  };
@@ -49,10 +54,9 @@ const githubWebhooksApiV1Handler = async (event, context) => {
49
54
  if (!xHubSignature) {
50
55
  throw new Error("X-Hub-Signature-256 or X-Hub-Signature doesn't exist.");
51
56
  }
52
- const webhooks = new webhooks_1.Webhooks({ secret: '123' });
53
57
  const pipelines = JSON.parse(process.env.PIPELINES_JSON || JSON.stringify([]));
54
58
  if (pipelines.includes('pr')) {
55
- webhooks.on([
59
+ exports.webhooks.on([
56
60
  'pull_request.opened',
57
61
  'pull_request.reopened',
58
62
  'pull_request.ready_for_review',
@@ -79,7 +83,9 @@ const githubWebhooksApiV1Handler = async (event, context) => {
79
83
  ],
80
84
  });
81
85
  });
82
- webhooks.on(['pull_request.closed'], async ({ payload }) => {
86
+ }
87
+ if (pipelines.includes('closed-pr')) {
88
+ exports.webhooks.on(['pull_request.closed'], async ({ payload }) => {
83
89
  /**
84
90
  * https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-cpu-memory-error.html
85
91
  */
@@ -105,29 +111,27 @@ const githubWebhooksApiV1Handler = async (event, context) => {
105
111
  });
106
112
  }
107
113
  if (pipelines.includes('main')) {
108
- webhooks.on('push', async (details) => {
114
+ exports.webhooks.on('push', async (details) => {
109
115
  if (details.payload.ref === 'refs/heads/main') {
110
116
  await putJobDetails({ pipeline: 'main', details });
111
117
  }
112
118
  });
113
119
  }
114
120
  if (pipelines.includes('tag')) {
115
- webhooks.on('push', async (details) => {
121
+ exports.webhooks.on('push', async (details) => {
116
122
  if (details.payload.ref.startsWith('refs/tags/')) {
117
123
  await putJobDetails({ pipeline: 'tag', details });
118
124
  }
119
125
  });
120
126
  }
121
- webhooks.onError((onErrorEvent) => {
122
- console.error('Webhooks on error.');
123
- console.error(JSON.stringify(onErrorEvent, null, 2));
127
+ exports.webhooks.onError((onErrorEvent) => {
124
128
  throw onErrorEvent;
125
129
  });
126
130
  /**
127
131
  * Replace "receive" for "verifyAndReceive" when WebCrypto exist on Node.js
128
132
  * API.
129
133
  */
130
- await webhooks.receive({
134
+ await exports.webhooks.receive({
131
135
  id: xGitHubDelivery,
132
136
  name: xGitHubEvent,
133
137
  // signature: xHubSignature,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carlin",
3
- "version": "0.19.5",
3
+ "version": "0.19.6",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {