-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
60 lines (45 loc) · 1.7 KB
/
index.js
File metadata and controls
60 lines (45 loc) · 1.7 KB
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
const core = require('@actions/core');
const { exec } = require('@actions/exec');
const path = require('path');
async function run() {
try {
await exec('git', ['config', '--local', 'user.name', 'GitHub Action']);
await exec('git', ['config', '--local', 'user.email', 'action@github.com']);
// get input
const inputBranch = core.getInput('branch');
const commitMsg = core.getInput('commit_msg');
const nccArgs = core.getInput('ncc_args');
const allowUnrelated = core.getInput('allow_unrelated');
const src = path.resolve(path.join(process.cwd(), core.getInput('src')));
// pull latest
await exec('git', ['pull', 'origin', inputBranch, allowUnrelated ? '--allow-unrelated-histories' : '', '--rebase']);
core.startGroup(`Compiling ${src}`);
// install dependencies
await exec('npm', ['install']);
// compile code
const compileArgs = ['@vercel/ncc', 'build', src];
if (nccArgs) {
const args = nccArgs.split(',').map(c => c.trim());
compileArgs.push(...args);
}
await exec('npx', compileArgs);
core.endGroup(`Compiling ${src}`);
core.startGroup('Pushing dist');
// push dist
try {
await exec('git', ['add', 'dist/index.js']);
await exec('git', ['commit', '-a', '-m', commitMsg]);
} catch (error) {
if (error.stdout.includes('nothing to commit, working tree clean')) {
return core.info('Nothing to commit! 🙂');
}
throw error;
}
core.endGroup('Pushing dist');
await exec('git', ['push', 'origin', `HEAD:${inputBranch}`]);
core.info('Compiled and pushed successfully 📦 🎉 ');
} catch (error) {
core.setFailed(`ncc failed! ${error.message}`);
}
}
run();