-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
136 lines (109 loc) · 3.28 KB
/
index.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// https://github.com/actions/toolkit
const core = require("@actions/core");
const github = require("@actions/github");
const tc = require("@actions/tool-cache");
const exec = require("@actions/exec");
/*
* Generic helpers
*/
function is_true(b) {
if (b !== null && (b === true || b == "true" || b == "1" || b == "ok")) {
return true;
}
return false;
}
function is_false(b) {
return is_true(b) ? false : true;
}
/*
* cNext action
*/
var cNext = function cNext() {
this.workflow = "cnext";
// this.install = core.getInput("install");
// this.cpanfile = core.getInput("cpanfile");
// this.tests = core.getInput("tests");
// this.args = core.getInput("args");
return;
};
cNext.prototype.install_cnext = async function () {
const cnext = await tc.downloadTool("https://git.io/cnext");
core.setOutput("cnext", cnext);
await this.do_exec(["perl", cnext, "self-install"]);
return;
};
cNext.prototype.get_tarball_value = function () {
const use_ci = is_true(core.getInput("ci"));
if (!use_ci) {
return core.getInput("tarball");
}
/* when using ci then build a tarball URL from context */
const repository = github.context.payload.repository.full_name;
const sha = github.context.sha;
return `https://github.com/${repository}/archive/${sha}.tar.gz`;
};
cNext.prototype.do_exec = async function (cmd) {
const sudo = is_true(core.getInput("sudo"));
const bin = sudo ? "sudo" : cmd.shift();
console.log(`do_exec: ${bin}`);
await exec.exec(bin, cmd);
};
cNext.prototype.run = async function () {
await this.install_cnext();
// Get the JSON webhook payload for the event that triggered the workflow
//const payload = JSON.stringify(github.context.payload, undefined, 2)
//console.log(`The event payload: ${payload}`);
// input arguments
const install = core.getInput("install");
const cpanfile = core.getInput("cpanfile");
const tests = core.getInput("tests");
const args = core.getInput("args");
const tarball = this.get_tarball_value();
const w_test = is_true(tests) ? "--test" : "--no-test";
var w_args = [];
if (args !== null && args.length) {
w_args = args.split(/\s+/);
}
if (install !== null && install.length) {
console.log(`install: ${install}!`);
const list = install.split("\n");
var cmd = ["cnext", "install", "-d", w_test];
if (w_args.length) {
cmd = cmd.concat(w_args);
}
cmd = cmd.concat(list);
await this.do_exec(cmd);
}
if (cpanfile !== null && cpanfile.length) {
console.log(`cpanfile: ${cpanfile}!`);
var cmd = ["cnext", "cpanfile", "-d", w_test];
if (w_args.length) {
cmd = cmd.concat(w_args);
}
cmd.push(cpanfile);
await this.do_exec(cmd);
}
if (tarball !== null && tarball.length) {
console.log(`tarball: ${tarball}!`);
var cmd = ["cnext", "from-tarball", "-d", w_test];
if (w_args.length) {
cmd = cmd.concat(w_args);
}
cmd.push(tarball);
await this.do_exec(cmd);
}
return;
};
/* ------------------- */
/* calling the action */
/* ------------------- */
// https://alphacoder.xyz/nodejs-unhandled-promise-rejection-warning/
(async function() {
try {
const action = new cNext();
await action.run();
} catch(error) {
core.setFailed(error.message);
}
})();
/* ------------------- */