-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
57 lines (52 loc) · 1.76 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
const core = require('@actions/core');
const github = require('@actions/github');
const semver = require('semver');
function getAppDiff(newTag, oldTag) {
// get semVer diff between new and old tag
if (!semver.valid(semver.coerce(newTag)) && !semver.valid(semver.coerce(oldTag))) {
core.setFailed('Invalid tag format detected');
return;
}
const diff = semver.diff(semver.coerce(newTag), semver.coerce(oldTag));
return diff;
}
function createNewChartVersion(chartVersion, diff) {
// if diff is null, exit
if (!diff) {
core.setFailed('No new version detected');
return;
}
// if diff is major, exit
if (diff === 'major') {
core.setFailed('Major version detected');
return;
}
// else create chart version
// if diff is minor, increment minor version of chart
if (diff === 'minor') {
return chartVersion = semver.inc(chartVersion, 'minor');
} else if (diff === 'patch') {
return chartVersion = semver.inc(chartVersion, 'patch');
} else {
core.setFailed('Unknown version detected');
return;
}
}
async function run() {
try {
const newTag = core.getInput('new_tag');
const oldTag = core.getInput('old_tag');
const chartVersion = core.getInput('chart_version');
core.debug(`New tag: ${newTag}`);
core.debug(`Old tag: ${oldTag}`);
core.debug(`Chart version: ${chartVersion}`);
const diff = getAppDiff(newTag, oldTag);
core.setOutput('diff', diff);
core.debug(`Diff: ${diff}`);
const newChartVersion = createNewChartVersion(chartVersion, diff);
core.setOutput('new_chart_version', newChartVersion);
} catch (error) {
core.setFailed(error.message);
}
}
run();