From ff658707249dfedc7121cdc765729072292f8820 Mon Sep 17 00:00:00 2001 From: koeneijkemans Date: Sun, 5 Jul 2020 09:50:20 +0200 Subject: [PATCH] Add Major/Minor/Patch versions --- .github/workflows/main.yml | 2 +- index.js | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a29f868..4c22849 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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}}" diff --git a/index.js b/index.js index 12be7bf..4807432 100644 --- a/index.js +++ b/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) { @@ -35,6 +37,24 @@ async function getBranchName() { function extractVersion(branch) { const regexp = /([0-9]\.[0-9]\.[0-9])|([0-9]\.[0-9])|([0-9])/g; 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 } \ No newline at end of file