-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.mjs
More file actions
52 lines (43 loc) · 1.75 KB
/
index.mjs
File metadata and controls
52 lines (43 loc) · 1.75 KB
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
import core from '@actions/core'
const branchVersionRegex = /^.*?\/(?<version>\d+\.\d+\.\d+)(?:\/(?:.*)+)?$/;
const versionTagRegex = /^v(?<version>\d+\.\d+\.\d+)$/;
const maxBranchNameLength = 32;
function getBranchInfoNumber(refName) {
const name = refName
.replaceAll(/[\/_]/g, '-')
.replaceAll(/[^0-9A-Za-z-]/g, '');
if (name.length > maxBranchNameLength) {
return name.substring(0, maxBranchNameLength);
}
return name;
}
function extractVersionNumber() {
const refName = process.env.GITHUB_REF_NAME;
const runNumber = process.env.GITHUB_RUN_NUMBER;
const result = branchVersionRegex.exec(refName) ?? versionTagRegex.exec(refName);
const mainVersion = core.getInput('main_version');
let version;
if (result === null) {
version = mainVersion;
if (refName !== 'master') {
core.info('Not on master branch, adding branch name to build name');
version += "-" + getBranchInfoNumber(refName);
}
core.info(`Version number was not found in branch name, assuming latest. Got RefName: '${refName}'. Falling back to main version: '${version}'`);
} else {
version = result.groups.version;
if (!refName.startsWith('release/')) {
core.info('not on a strict release branch, adding more info to build number')
version += "-" + getBranchInfoNumber(refName);
}
core.info(`Version was extracted from refname without issues: '${version}'`);
}
const fullVersionNumber = `${version}-${runNumber}`;
core.setOutput('version', fullVersionNumber);
core.setOutput('release_version', result?.groups?.version ?? mainVersion);
}
try {
extractVersionNumber();
} catch (error) {
core.setFailed(error.message);
}