forked from shellbear/helm-release-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
85 lines (72 loc) · 1.93 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const core = require('@actions/core');
const exec = require('@actions/exec');
const path = require('path');
const fs = require('fs');
const HELM = 'helm';
const REPO_ALIAS = 'repo';
const RELEASE_DIR = '.release/';
// Returns argument required to register the S3 repository.
function repo() {
const repo = core.getInput('repo', {
required: true,
});
return [
'repo',
'add',
REPO_ALIAS,
repo,
];
}
// Returns argument required to generate the chart package.
function package() {
const args = [
'pack',
core.getInput('chart'),
'--dependency-update',
'--destination',
RELEASE_DIR,
...core.getInput('packageExtraArgs').split(/\s+/),
];
const version = core.getInput('version');
if (version) {
args.push('--version', version);
}
return args;
}
// Returns argument required to push the chart release to S3 repository.
function push() {
const releaseFile = path.join(RELEASE_DIR, fs.readdirSync(RELEASE_DIR)[0]);
const args = [
's3',
'push',
releaseFile,
REPO_ALIAS,
];
const forceRelease = core.getInput('forceRelease', { required: true }) === 'true';
if (forceRelease) {
args.push('--force');
} else {
args.push('--ignore-if-exists');
}
return args;
}
// Returns argument required to install helm-s3 and helm-pack plugins.
function installPlugins() {
const plugins = [
{ name: 'https://github.com/hypnoglow/helm-s3.git', version: core.getInput('HelmS3Version') },
{ name: 'https://github.com/thynquest/helm-pack.git', version: core.getInput('HelmPackVersion') },
];
return Promise.all(plugins.map(plugin => exec.exec(HELM, ['plugin', 'install', plugin.name, '--version', plugin.version])));
}
async function main() {
try {
await installPlugins();
await exec.exec(HELM, repo()),
await exec.exec(HELM, package()),
await exec.exec(HELM, push())
} catch (err) {
core.error(err);
core.setFailed(err.message);
}
}
main();