-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (52 loc) · 1.96 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
const core = require('@actions/core');
const github = require('@actions/github');
const semver = require('semver');
try {
const tag = core.getInput('latestTag');
const buildNumber = core.getInput('buildNumber');
const bumpMaster = core.getInput('bumpMaster');
let { runNumber, payload } = github.context;
if (buildNumber !== '' && !isNaN(buildNumber)) {
runNumber = buildNumber;
}
const isPR = !!payload.pull_request
const prNumber = isPR ? payload.pull_request.number : null;
const branchRef = isPR ? payload.pull_request.head.ref : github.context.ref
const branchName = branchRef.replace('refs/heads/', '');
const currentVersion = semver.clean(tag)
if (!currentVersion) {
throw Error('Failed to extract latest release')
}
if (branchName === 'master' || branchName === 'main') {
core.debug('Branch master or main');
if (bumpMaster === 'true') {
const nextHelmVersion = semver.inc(currentVersion, 'patch')
core.setOutput('helmVersion', nextHelmVersion);
return;
}
core.setOutput('helmVersion', currentVersion);
return;
}
if (branchName === 'develop') {
core.debug('Branch develop');
const nextHelmVersion = semver.inc(currentVersion, 'prerelease', `dev-${runNumber}`)
core.setOutput('helmVersion', nextHelmVersion);
return;
}
if (isPR) {
core.debug('Pull Request');
const nextHelmVersion = semver.inc(currentVersion, 'prerelease', `PR-${prNumber}-${runNumber}`)
core.setOutput('helmVersion', nextHelmVersion);
return;
}
if (branchName.match('^(feature|bugfix|renovate|staging)')) {
core.debug('feature/bugfix branch');
const preReleaseName = branchName.replace(/\//g, '-')
const nextHelmVersion = semver.inc(currentVersion, 'prerelease', `${preReleaseName}-${runNumber}`)
core.setOutput('helmVersion', nextHelmVersion);
return;
}
throw Error ('Branch "' + branchName + '" is not allowed to get built')
} catch (error) {
core.setFailed(error.message);
}