forked from coveo/search-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
invalidate.cloudfront.js
52 lines (48 loc) · 1.59 KB
/
invalidate.cloudfront.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
const exec = require('child_process').exec;
const colors = require('colors');
const AWS = require('aws-sdk');
const cloudfront = new AWS.CloudFront();
const pathToInvalidate = `/searchui/v${process.env.PACKAGE_JSON_VERSION}/*`;
const shouldDoInvalidation = () => {
if (!process.env.TRAVIS) {
return false;
}
if (!process.env.TRAVIS_TAG) {
return false;
}
if (process.env.TRAVIS_TAG.indexOf('beta') != -1) {
return false;
}
return true;
};
if (shouldDoInvalidation()) {
const invalidationRequest = cloudfront.createInvalidation({
DistributionId: process.env.AWS_CLOUDFRONT_DISTRIBUTION_ID,
InvalidationBatch: {
CallerReference: new Date().getTime().toString(),
Paths: {
Quantity: 1,
Items: [pathToInvalidate]
}
}
});
invalidationRequest.send((error, success) => {
if (error) {
console.log(colors.red('ERROR WHILE INVALIDATING RESSOURCES ON CLOUDFRONT'));
console.log(colors.red('*************'));
console.log(colors.red(error.message));
console.log(colors.red('*************'));
exec('travis_terminate 1');
throw error;
}
if (success) {
console.log(colors.green('INVALIDATION ON CLOUDFRONT SUCCESSFUL'));
console.log(colors.green('*************'));
console.log(colors.green(`PATH INVALIDATED: ${pathToInvalidate}`));
console.log(colors.green(`INVALIDATION ID : ${success.Invalidation.Id}`));
console.log(colors.green('*************'));
}
});
} else {
console.log(colors.white('INVALIDATION FROM CLOUDFRONT SKIPPED BECAUSE THIS IS NOT AN OFFICIAL RELEASE'));
}