From 0fd08db73701211a7ad1b46fca5e709a8fa441b9 Mon Sep 17 00:00:00 2001 From: Petro Kurbatskyi <67897517+ibexa-yuna@users.noreply.github.com> Date: Fri, 1 Oct 2021 10:46:36 +0200 Subject: [PATCH] Fix for Alpha version logic (#1) * [NO JIRA] Allow working with Alpha releases --- .github/workflows/integration.yml | 7 +++++++ action.yml | 6 +++++- main.py | 12 ++++++++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 402ef64..8d2ab03 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -21,6 +21,12 @@ jobs: with: currentTag: "v2.2.4" + - id: alphatest1 + uses: ibexa/version-logic-action@master + with: + currentTag: "v4.0.0-alpha1" + prevFullTag: "v3.3.9" + - id: betatest1 uses: ibexa/version-logic-action@master with: @@ -47,6 +53,7 @@ jobs: test "${{ steps.majortest.outputs.previousTag }}" == "v1.0.0" test "${{ steps.minortest.outputs.previousTag }}" == "v2.2.0" test "${{ steps.patchtest.outputs.previousTag }}" == "v2.2.3" + test "${{ steps.alphatest1.outputs.previousTag }}" == "v3.3.0" test "${{ steps.betatest1.outputs.previousTag }}" == "v2.2.3" test "${{ steps.betatest2.outputs.previousTag }}" == "v2.2.4-beta1" test "${{ steps.rctest1.outputs.previousTag }}" == "v2.2.4-beta1" diff --git a/action.yml b/action.yml index eab2201..ffcca59 100644 --- a/action.yml +++ b/action.yml @@ -3,11 +3,15 @@ description: "Uses Ibexa-specific rules to output previous tag for comparing" author: "Petro Kurbatskyi" inputs: currentTag: + required: true description: "Current tag" default: "v1.0.0" + prevFullTag: + required: false + description: "Previous full release tag" outputs: previousTag: description: "Output from the action" runs: using: "docker" - image: "docker://ghcr.io/ibexa/version-logic-action:v1.1.0" + image: "docker://ghcr.io/ibexa/version-logic-action:v1.2.0" diff --git a/main.py b/main.py index 51a586b..43dab30 100644 --- a/main.py +++ b/main.py @@ -7,15 +7,23 @@ def main(): # cut initial v from input current_tag = os.environ["INPUT_CURRENTTAG"][1:] + # optional parameter + previous_full_tag = os.environ.get("INPUT_PREVFULLTAG") major, minor, patch, prerelease, _ = semver.VersionInfo.parse(current_tag) + if previous_full_tag: + pft_ver = list(semver.VersionInfo.parse(previous_full_tag[1:])) + else: + pft_ver = list(semver.VersionInfo.parse(current_tag)) + pft_ver[1] -= 1 + pft_ver[2] = 0 if prerelease: type, number = re.match('(?Palpha|beta|rc)(?P\d+)', prerelease).groups(['type', 'number']) - if type == 'beta' and number == '1': + if type in ['alpha', 'beta'] and number == '1': # compare 3.3.0-beta1 with 3.2.0 # but if it's patch compare with last released patch if not patch: - previous_tag = semver.format_version(major, minor - 1, 0) + previous_tag = semver.format_version(pft_ver[0], pft_ver[1], 0) else: previous_tag = semver.format_version(major, minor, patch - 1) elif type == 'rc' and number == '1':