2020-07-04 21:26:38 +08:00
|
|
|
const core = require('@actions/core');
|
2020-07-04 23:47:33 +08:00
|
|
|
const execlib = require('@actions/exec');
|
2020-07-04 21:26:38 +08:00
|
|
|
|
|
|
|
try {
|
2020-07-05 14:46:24 +08:00
|
|
|
getBranchName()
|
2020-07-05 14:49:01 +08:00
|
|
|
.then(name => {
|
|
|
|
core.setOutput("branchname", name)
|
2020-07-05 15:18:35 +08:00
|
|
|
|
|
|
|
const versionNumber = extractVersion(name);
|
|
|
|
|
|
|
|
if (versionNumber) {
|
2020-07-05 15:50:20 +08:00
|
|
|
core.setOutput('VERSION', versionNumber.version);
|
|
|
|
core.setOutput('MAJOR_VERSION', versionNumber.major);
|
|
|
|
core.setOutput('MINOR_VERSION', versionNumber.minor);
|
|
|
|
core.setOutput('PATCH_VERSION', versionNumber.patch);
|
2020-07-05 15:18:35 +08:00
|
|
|
}
|
2020-07-05 14:49:01 +08:00
|
|
|
});
|
2020-07-05 00:45:30 +08:00
|
|
|
} catch (error) {
|
|
|
|
core.setFailed(error.message);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getBranchName() {
|
2020-07-04 23:42:55 +08:00
|
|
|
let output = '';
|
2020-07-04 23:47:33 +08:00
|
|
|
const options = {
|
|
|
|
listeners: {
|
2020-07-05 14:42:39 +08:00
|
|
|
stdout: (data) => {
|
|
|
|
output += data.toString();
|
|
|
|
}
|
2020-07-05 01:03:59 +08:00
|
|
|
}
|
2020-07-04 23:47:33 +08:00
|
|
|
};
|
|
|
|
|
2020-07-05 15:32:42 +08:00
|
|
|
await execlib.exec('git', ['branch', '--show-current'], options);
|
2020-07-05 00:45:30 +08:00
|
|
|
|
|
|
|
return output;
|
2020-07-05 15:18:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function extractVersion(branch) {
|
2020-07-05 15:32:42 +08:00
|
|
|
const regexp = /([0-9]\.[0-9]\.[0-9])|([0-9]\.[0-9])|([0-9])/g;
|
|
|
|
const matches = branch.match(regexp);
|
2020-07-05 15:50:20 +08:00
|
|
|
|
2020-07-05 15:52:49 +08:00
|
|
|
var versions = null;
|
2020-07-05 15:50:20 +08:00
|
|
|
|
|
|
|
if (matches) {
|
|
|
|
const version = matches.shift();
|
2020-07-05 15:52:49 +08:00
|
|
|
const versionParts = version.split('.');
|
2020-07-05 15:50:20 +08:00
|
|
|
|
2020-07-05 15:52:49 +08:00
|
|
|
const major = versionParts[0];
|
|
|
|
const minor = versionParts.length >= 2 ? versionParts[1] : null;
|
|
|
|
const patch = versionParts.length >= 3 ? versionParts[2] : null;
|
2020-07-05 15:50:20 +08:00
|
|
|
|
|
|
|
versions = {
|
|
|
|
version: version,
|
|
|
|
major: major,
|
|
|
|
minor: minor,
|
|
|
|
patch: patch
|
|
|
|
}
|
|
|
|
}
|
2020-07-05 15:32:42 +08:00
|
|
|
|
2020-07-05 15:50:20 +08:00
|
|
|
return versions
|
2020-07-04 21:26:38 +08:00
|
|
|
}
|