mirror of
https://github.com/diligencia/semantic-branch-version.git
synced 2024-11-23 09:43:50 +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
|
||||
uses: diligencia/semantic-git-version-action@master
|
||||
- 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);
|
||||
|
||||
if (versionNumber) {
|
||||
core.setOutput('version', versionNumber);
|
||||
console.log(versionNumber);
|
||||
core.setOutput('VERSION', versionNumber.version);
|
||||
core.setOutput('MAJOR_VERSION', versionNumber.major);
|
||||
core.setOutput('MINOR_VERSION', versionNumber.minor);
|
||||
core.setOutput('PATCH_VERSION', versionNumber.patch);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
@ -36,5 +38,23 @@ function extractVersion(branch) {
|
||||
const regexp = /([0-9]\.[0-9]\.[0-9])|([0-9]\.[0-9])|([0-9])/g;
|
||||
const matches = branch.match(regexp);
|
||||
|
||||
return matches ? matches.shift() : null;
|
||||
const versions = 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