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) {
|
|
|
|
core.setOutput('version', versionNumber);
|
2020-07-05 15:22:32 +08:00
|
|
|
console.log(versionNumber);
|
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 00:43:20 +08:00
|
|
|
await execlib.exec('git', ['branch'], options);
|
2020-07-05 00:45:30 +08:00
|
|
|
|
|
|
|
return output;
|
2020-07-05 15:18:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function extractVersion(branch) {
|
|
|
|
const regexp = /^([0-9]\.[0-9]\.[0-9])|([0-9]\.[0-9])|([0-9])$/;
|
|
|
|
return branch.match(regexp);
|
2020-07-04 21:26:38 +08:00
|
|
|
}
|