forked from webfactory/create-aws-codedeploy-deployment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
87 lines (72 loc) · 2.56 KB
/
cli.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
81
82
83
84
85
86
87
'use strict';
(async function () {
var core = require('@actions/core');
core.setOutput = function () {};
core.setFailed = function (message) {
console.log(message instanceof Error ? message.toString() : message);
process.exitCode = 1;
}
const fs = require('fs');
if (!fs.existsSync('./appspec.yml')) {
core.setFailed("❓ ./appspec.yml does not exist. Make sure you are in the project's top level directory.");
process.exit();
}
const simpleGit = require('simple-git');
const git = simpleGit();
var branchName, commitId;
try {
await git.init();
const remotes = await git.getRemotes(true);
var applicationName, fullRepositoryName;
for (const remote of remotes) {
if (remote.name !== 'origin') {
continue;
}
const url = remote.refs.push;
var matches
if (matches = url.match(/[email protected]:([a-z0-9_-]+)\/([a-z0-9_-]+).git/)) {
applicationName = matches[2];
fullRepositoryName = `${matches[1]}/${matches[2]}`;
}
}
branchName = await git.revparse(['--abbrev-ref', 'HEAD']);
commitId = await git.revparse(['HEAD']);
} catch (e) {
core.setFailed('🌩 Failed to parse git information. Are you sure this is a git repo?')
process.exit();
}
if (!applicationName || !fullRepositoryName) {
core.setFailed("❓ Unable to parse GitHub repository name from the 'origin' remote.");
process.exit();
}
console.log("🚂 OK, let's ship this...");
console.log(`GitHub 💎 repository '${fullRepositoryName}'`);
console.log(`Branch 🎋 ${branchName}`);
console.log(`Commit ⚙️ ${commitId}`);
const prompt = require('prompt');
prompt.message = '';
prompt.start();
try {
await prompt.get({
properties: {
confirm: {
name: 'yes',
message: 'Type "yes" to create deployment',
validator: /yes/,
warning: 'Must respond yes to continue',
default: ''
}
}
});
} catch (e) {
core.setFailed('🙈 Aborted.');
process.exit();
}
const action = require('./create-deployment');
try {
await action.createDeployment(applicationName, fullRepositoryName, branchName, commitId, null, core);
} catch (e) {
console.log(`👉🏻 ${e.message}`);
process.exit(1);
}
})();