-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (44 loc) · 1.77 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
const core = require('@actions/core');
const github = require('@actions/github');
const exec = require('@actions/exec');
const path = require('path');
const fs = require('fs');
const fullUrl = /^https?:\/\//i;
const defaultFeed = 'https://feed.piral.cloud/api/v1/pilet';
async function runAction() {
const workspace = process.env.GITHUB_WORKSPACE;
console.log(`Triggered action: ${github.context.action}`);
try {
const feed = core.getInput('feed');
const apiKey = core.getInput('api-key');
const bundler = core.getInput('bundler') || 'webpack5';
const baseDir = core.getInput('base-dir') || '.';
const cwd = path.resolve(workspace, baseDir);
const url = fullUrl.test(feed) ? feed : `${defaultFeed}/${feed}`;
const packageJsonPath = path.resolve(cwd, 'package.json');
const piralCliPath = path.resolve(cwd, 'node_modules', 'piral-cli');
const { version } = require(packageJsonPath);
if (!fs.existsSync(path.resolve(cwd, 'node_modules'))) {
console.warn('Did not find a `node_modules` directory. Trying to resolve dependencies first ...');
await exec.exec('npm install', undefined, { cwd });
}
if (!fs.existsSync(piralCliPath)) {
console.warn('Did not find a local `piral-cli` instance. Installing latest ...');
await exec.exec(`npm install piral-cli piral-cli-${bundler} --no-save`, undefined, { cwd });
}
const piralCli = require(piralCliPath);
const { loadPlugins } = require(`${piralCliPath}/lib/plugin`);
await loadPlugins();
await piralCli.apps.publishPilet(cwd, {
fresh: true,
apiKey,
url,
});
core.setOutput('version', version);
return process.exit(0);
} catch (error) {
core.setFailed(error.message);
return process.exit(1);
}
}
runAction();