-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.index.js
63 lines (61 loc) · 2.15 KB
/
action.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
const deployment = require('./src/deployment')
const github = require('@actions/github');
const utils = require('./src/utils')
const core = require('@actions/core');
const workingDirectory = core.getInput('working_directory')
const mainPkgManager = core.getInput('main_pkg_manager');
const packageManagers = core.getInput('pkg_managers');
const githubAccessToken = core.getInput('github_access_token');
const npmAccessToken = core.getInput('npm_access_token');
const npmRegistry = core.getInput('npm_registry');
const npmScope = core.getInput('npm_scope')
const dryRun = core.getInput('dry_run')
const prettyPrint = core.getInput('pretty_print')
const debug = core.getInput('debug');
const isNPM = packageManagers.indexOf('npm') !== -1;
const isGitHub = packageManagers.indexOf('github') !== -1;
let pkgName = core.getInput('pkg_name');
/**
* Verifying GitHub action inputs
* @param {*} data The data to verify to inputs of
*/
async function verifyInputs(data) {
if(!data.pkgName || data.pkgName === '')
throw new Error('Missing input "pkg_name"');
if(data.npm){
if(!data.npm.token || data.npm.token === '')
throw new Error('Mising input "npm_access_token"');
}
if(data.github){
if(!data.github.token || data.github.token === '')
throw new Error('Mising input "github_access_token"');
}
}
(async () => {
try {
const data = {
workingDirectory: workingDirectory,
pkgName: pkgName,
debug: utils.stringToBoolean(debug),
prettyPrint: utils.stringToBoolean(prettyPrint),
dryRun: utils.stringToBoolean(dryRun),
mainPackageManager: mainPkgManager
}
data.npm = isNPM ? {
token: npmAccessToken,
registry: npmRegistry,
scope: npmScope
}: undefined;
data.github = isGitHub ? {
owner: github.context.repo.owner,
repo: github.context.repo.repo,
token: githubAccessToken
}: undefined;
//Verifying inputs
verifyInputs(data);
await deployment.deploy(data);
}
catch(e) {
core.setFailed(e.toString());
}
})();