-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.js
executable file
·80 lines (70 loc) · 2.75 KB
/
make.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
require('error-object-polyfill');
const path = require('path');
const { config } = require('aws-sdk');
const AwsArchitect = require('aws-architect');
const commander = require('commander');
const REGION = 'us-east-1';
config.region = REGION;
function getVersion() {
let release_version = '0.0';
const pull_request = '';
const branch = process.env.GITHUB_REF;
const build_number = `${process.env.GITHUB_RUN_NUMBER}`;
// Builds of pull requests
if (pull_request && !pull_request.match(/false/i)) {
release_version = `0.${pull_request}`;
} else if (!branch || !branch.match(/^(refs\/heads\/)?release[/-]/i)) {
// Builds of branches that aren't master or release
release_version = '0.0';
} else {
// Builds of release branches (or locally or on server)
release_version = branch.match(/^(?:refs\/heads\/)?release[/-](\d+(?:\.\d+){0,3})$/i)[1];
}
return `${release_version}.${(build_number || '0')}.0.0.0.0`.split('.').slice(0, 3).join('.');
}
const version = getVersion();
commander.version(version);
const packageMetadata = require('./package.json');
packageMetadata.version = version;
const apiOptions = {
deploymentBucket: 'authress-identity-aware-proxy-public-artifacts',
sourceDirectory: path.join(__dirname, 'src'),
description: packageMetadata.description,
regions: [REGION]
};
commander
.command('run')
.description('Run lambda web service locally.')
.action(async () => {
const awsArchitect = new AwsArchitect(packageMetadata, apiOptions);
try {
const result = await awsArchitect.Run(8080, () => { /* Do not log from server when running locally */ });
console.log(JSON.stringify(result.title, null, 2));
} catch (failure) {
console.log(JSON.stringify(failure, null, 2));
}
});
commander
.command('publish-lambda-code-package')
.description('Deploy to AWS.')
.action(async () => {
try {
const awsArchitect = new AwsArchitect(packageMetadata, apiOptions);
await awsArchitect.publishLambdaArtifactPromise();
console.log(`***** S3 Package Path: ${packageMetadata.name}/${packageMetadata.version}/lambda.zip`);
packageMetadata.version = version.replace(/\.\d+$/, '');
const awsArchitectReleaseVersion = new AwsArchitect(packageMetadata, apiOptions);
await awsArchitectReleaseVersion.publishLambdaArtifactPromise();
console.log(`***** S3 Release Package Path: ${packageMetadata.name}/${packageMetadata.version}/lambda.zip`);
} catch (failure) {
console.log(JSON.stringify(failure, null, 2));
process.exit(1);
}
});
commander.on('*', () => {
if (commander.args.join(' ') === 'tests/**/*.js') { return; }
console.log(`Unknown Command: ${commander.args.join(' ')}`);
commander.help();
process.exit(0);
});
commander.parse(process.argv[2] ? process.argv : process.argv.concat(['build']));