-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
42 lines (34 loc) · 1.37 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
const core = require('@actions/core');
const exec = require('@actions/exec');
const artifact = require('@actions/artifact');
const glob = require('@actions/glob');
const path = require('path');
const checkBin = require('../util/bin');
const projectDirectory = core.getInput('project_directory');
const serviceId = core.getInput('service_id');
const comment = core.getInput('comment');
const verbose = core.getBooleanInput('verbose');
const version = core.getInput('version');
checkBin('fastly', 'version').then(async () => {
let params = ['compute', 'deploy', '--non-interactive'];
if (serviceId !== 'default') params.push('--service-id=' + serviceId);
if (verbose) params.push('--verbose');
if (comment) params.push('--comment=' + comment);
if (version) params.push('--version=' + version);
const result = await exec.exec('fastly', params, {
cwd: projectDirectory
});
return uploadArtifact(result);
}).catch((err) => {
core.setFailed(err.message);
});
async function uploadArtifact() {
const globber = await glob.create(path.join(projectDirectory, 'pkg', '*.tar.gz'));
const files = await globber.glob();
if (files.length < 1) {
throw "There is no archive in the pkg directory to upload.";
}
const artifactName = path.parse(files[0]).name;
const artifactClient = artifact.create();
await artifactClient.uploadArtifact(artifactName, files, '.', {});
}