-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.js
39 lines (32 loc) · 1.09 KB
/
main.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
'use strict';
const { spawn } = require('child_process');
const core = require('@actions/core');
function docker(cmd) {
const docker = spawn('docker', cmd);
docker.stdout.on('data', data => {
process.stdout.write(data);
});
docker.stderr.on('data', data => {
process.stdout.write(data);
});
docker.on('close', code => {
if (code != 0)
core.setFailed(`Action failed with error ${code}`);
});
}
// Generate label
const label = (core.getInput('version') == '' ? '' : `${core.getInput('version')}-`) + core.getInput('image');
console.log(`Using klakegg/hugo:${label}`);
// Prepare command
const command = core.getInput('command') == '' ? [] :
core.getInput('command').split(' ');
// Pull image
docker(['pull', `klakegg/hugo:${label}`]);
// Run build
docker(['run', '--rm' , '-i',
'-v', `${process.env.GITHUB_WORKSPACE}/${core.getInput('source')}:/src`,
'-v', `${process.env.GITHUB_WORKSPACE}/${core.getInput('target')}:/target`,
'-e', `HUGO_ENV=${core.getInput('env')}`,
'-e', `HUGO_PANDOC=${core.getInput('pandoc_command')}`,
`klakegg/hugo:${label}`]
.concat(command));