mirror of
https://github.com/diligencia/semantic-branch-version.git
synced 2024-11-23 09:23:51 +08:00
Add Major/Minor/Patch versions
This commit is contained in:
parent
bf791bd8c8
commit
ff65870724
2
.github/workflows/main.yml
vendored
2
.github/workflows/main.yml
vendored
@ -13,4 +13,4 @@ jobs:
|
|||||||
id: getversion
|
id: getversion
|
||||||
uses: diligencia/semantic-git-version-action@master
|
uses: diligencia/semantic-git-version-action@master
|
||||||
- name: Echo name
|
- name: Echo name
|
||||||
run: echo "The version of the branch is ${{ steps.getversion.outputs.version }}!"
|
run: echo "The version of the branch is ${{ steps.getversion.outputs.version }}. Major -> ${{ steps.getversion.outputs.major}} Minor -> ${{ steps.getversion.outputs.minor}} Patch -> ${{ steps.getversion.outputs.patch}}"
|
||||||
|
26
index.js
26
index.js
@ -9,8 +9,10 @@ try {
|
|||||||
const versionNumber = extractVersion(name);
|
const versionNumber = extractVersion(name);
|
||||||
|
|
||||||
if (versionNumber) {
|
if (versionNumber) {
|
||||||
core.setOutput('version', versionNumber);
|
core.setOutput('VERSION', versionNumber.version);
|
||||||
console.log(versionNumber);
|
core.setOutput('MAJOR_VERSION', versionNumber.major);
|
||||||
|
core.setOutput('MINOR_VERSION', versionNumber.minor);
|
||||||
|
core.setOutput('PATCH_VERSION', versionNumber.patch);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -35,6 +37,24 @@ async function getBranchName() {
|
|||||||
function extractVersion(branch) {
|
function extractVersion(branch) {
|
||||||
const regexp = /([0-9]\.[0-9]\.[0-9])|([0-9]\.[0-9])|([0-9])/g;
|
const regexp = /([0-9]\.[0-9]\.[0-9])|([0-9]\.[0-9])|([0-9])/g;
|
||||||
const matches = branch.match(regexp);
|
const matches = branch.match(regexp);
|
||||||
|
|
||||||
|
const versions = null;
|
||||||
|
|
||||||
return matches ? matches.shift() : null;
|
if (matches) {
|
||||||
|
const version = matches.shift();
|
||||||
|
var versionParts = version.split('.');
|
||||||
|
|
||||||
|
var major = versionParts[0];
|
||||||
|
var minor = versionParts.length >= 2 ? versionParts[1] : null;
|
||||||
|
var patch = versionParts.length >= 3 ? versionParts[2] : null;
|
||||||
|
|
||||||
|
versions = {
|
||||||
|
version: version,
|
||||||
|
major: major,
|
||||||
|
minor: minor,
|
||||||
|
patch: patch
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return versions
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user