-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdeploy.js
47 lines (38 loc) · 1.24 KB
/
deploy.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
#! /usr/bin/env node
/* eslint-disable no-console */
/* eslint import/no-extraneous-dependencies: ["error", {"devDependencies": true}] */
const shelljs = require('shelljs');
const {
executeCommands,
} = require('@hollowverse/utils/helpers/executeCommands');
const { IS_PULL_REQUEST, BRANCH } = shelljs.env;
const isPullRequest = IS_PULL_REQUEST !== 'false';
const whitelistedBranches = ['master', 'beta', 'internal'];
async function main() {
const buildCommands = ['yarn test', 'yarn coverage/report'];
const deploymentCommands = [
`NODE_ENV=production serverless deploy --stage ${BRANCH} --aws-s3-accelerate`,
];
let isDeployment = false;
if (isPullRequest === true) {
console.info('Skipping deployment commands in PRs');
buildCommands.push(
`NODE_ENV=production serverless package --stage ${BRANCH}`,
);
} else if (!whitelistedBranches.includes(BRANCH)) {
console.info(
`Skipping deployment because the branch "${BRANCH}" is not whitelisted`,
);
} else {
isDeployment = true;
}
try {
await executeCommands(
isDeployment ? [...buildCommands, ...deploymentCommands] : buildCommands,
);
} catch (e) {
console.error('Build/deployment failed:', e);
process.exit(1);
}
}
main();