forked from shellbear/helm-release-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
77 lines (64 loc) · 1.87 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
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, '--relative'];
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 = [
{ url: 'https://github.com/hypnoglow/helm-s3.git', version: 'v0.12.0' },
{ url: 'https://github.com/thynquest/helm-pack.git', version: 'v0.2.2' },
];
return Promise.all(
plugins.map((plugin) =>
exec.exec(HELM, ['plugin', 'install', plugin.url, '--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();