From 9119742e84ead782e8492183949aba491ae9ec1f Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 1 May 2022 12:17:21 -0700 Subject: [PATCH 01/16] Add override parameter (and report latest tag to be empty of none was found) --- action.yml | 23 ++++++++++++++--------- greatest-semver-tag.sh | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/action.yml b/action.yml index a5ac06b..a03f902 100644 --- a/action.yml +++ b/action.yml @@ -14,6 +14,10 @@ inputs: type: string description: Requested version increment in bump output required: false + override: + type: string + description: Manually specified current version + required: false planned: type: string description: Version to compare against current @@ -91,18 +95,19 @@ runs: - name: Find the greatest semver tag id: find working-directory: ${{ inputs.path }} - run: > - tag="$(greatest-semver-tag)"; - if [[ tag = "0.0.0" ]]; then - echo "::set-output name=tag::$(greatest-semver-tag)" - else - echo "::set-output name=tag::$(greatest-semver-tag)" - fi + run: | + echo "::set-output name=tag::$(greatest-semver-tag)" shell: bash - name: Set current version based on stripped tag id: cur - run: | - echo "::set-output name=ver::$(echo "${{ steps.find.outputs.tag }}" | sed 's/^[^0-9]*//')" + run: > + if [[ "${{ input.override }}" != "" ]]; then + echo "::set-output name=ver::${{ input.override }}" + else if [[ "${{ steps.find.outputs.tag }}" = "" ]]; then + echo "::set-output name=ver::0.0.0" + else + echo "::set-output name=ver::$(echo "${{ steps.find.outputs.tag }}" | sed 's/^[^0-9]*//')" + fi shell: bash - name: Determine the prefix and set it id: prefix diff --git a/greatest-semver-tag.sh b/greatest-semver-tag.sh index 7b4e2aa..5ec993f 100755 --- a/greatest-semver-tag.sh +++ b/greatest-semver-tag.sh @@ -1,5 +1,5 @@ #!/bin/bash -latest="0.0.0" +latest="" while IFS= read -r line; do if [[ $(semver compare ${line} ${latest} 2> /dev/null) = '1' ]]; then latest=${line} From cd09017f50bd1059eae24be835f96f5fc2a24f97 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 1 May 2022 12:18:12 -0700 Subject: [PATCH 02/16] Fix typo --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index a03f902..bc9aff0 100644 --- a/action.yml +++ b/action.yml @@ -101,8 +101,8 @@ runs: - name: Set current version based on stripped tag id: cur run: > - if [[ "${{ input.override }}" != "" ]]; then - echo "::set-output name=ver::${{ input.override }}" + if [[ "${{ inputs.override }}" != "" ]]; then + echo "::set-output name=ver::${{ inputs.override }}" else if [[ "${{ steps.find.outputs.tag }}" = "" ]]; then echo "::set-output name=ver::0.0.0" else From 4f69191779d4367ad3f4e7cbab9902fa25799c6f Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 1 May 2022 12:23:45 -0700 Subject: [PATCH 03/16] Fix another typo --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index bc9aff0..56f0ea3 100644 --- a/action.yml +++ b/action.yml @@ -103,7 +103,7 @@ runs: run: > if [[ "${{ inputs.override }}" != "" ]]; then echo "::set-output name=ver::${{ inputs.override }}" - else if [[ "${{ steps.find.outputs.tag }}" = "" ]]; then + elif [[ "${{ steps.find.outputs.tag }}" = "" ]]; then echo "::set-output name=ver::0.0.0" else echo "::set-output name=ver::$(echo "${{ steps.find.outputs.tag }}" | sed 's/^[^0-9]*//')" From d320662f96b988e041f643d5bd824b03072e7aed Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 1 May 2022 12:29:00 -0700 Subject: [PATCH 04/16] Add test --- .github/workflows/ci.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 04ececf..2b795c1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,12 @@ jobs: bump: major planned: 1000000000.0.0 id: billionth + - name: Run local action with override=1.2.3 + uses: ./ + with: + bump: minor + override: 1.2.3 + id: override - name: Run local action with build=foo uses: ./ with: @@ -56,9 +62,12 @@ jobs: - name: Ensure 1000000000.0.0 is greater than whatever the current version is run: | [[ "${{ steps.billionth.outputs.planned-is-valid }}" = "true" ]] || exit 1 - - name: Check major bump + - name: Check major bump on billionth run: | [[ "${{ steps.billionth.outputs.bump }}" = "${{ steps.billionth.outputs.next-major }}" ]] || exit 1 + - name: Check minor bump on override + run: | + [[ "${{ steps.override.outputs.bump }}" = "1.3.3" ]] || exit 1 - name: Ensure next-build of foo-build is foo run: | [[ "$(semver get build ${{ steps.foo-build.outputs.next-build }})" = "foo" ]] || exit 1 \ No newline at end of file From ebab81070e982ace6241e49121de638e2853e44e Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 1 May 2022 12:31:57 -0700 Subject: [PATCH 05/16] Fix test --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2b795c1..bc780b8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,7 +67,7 @@ jobs: [[ "${{ steps.billionth.outputs.bump }}" = "${{ steps.billionth.outputs.next-major }}" ]] || exit 1 - name: Check minor bump on override run: | - [[ "${{ steps.override.outputs.bump }}" = "1.3.3" ]] || exit 1 + [[ "${{ steps.override.outputs.bump }}" = "1.3.0" ]] || exit 1 - name: Ensure next-build of foo-build is foo run: | [[ "$(semver get build ${{ steps.foo-build.outputs.next-build }})" = "foo" ]] || exit 1 \ No newline at end of file From f4f964a3ff4ff91204cb0a444339ef060c68b7e0 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 1 May 2022 12:40:41 -0700 Subject: [PATCH 06/16] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 03238e6..504c2b9 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ Note that the `tag` output is "as-is", including any prefix the semver might hav * `repo` If specified, this repository is checked out by the action. By default, no checkout occurs. * `path` Location to find the repository checkout. By default, this is `$github.workspace`. * `bump` If specified, the `bump` output will reflect the given version increment with respect to `current`. +* `override` If specified, the `current` output will be set equal to `override`, and all other outputs are computed with respect to it (instead of using the greatest tag found in the repository). A given `override` must be a valid semantic version number. * `planned` If this is a valid semver greater than the `current` output, the `valid-planned` output is `true`. * `build` If specified, the `next-build` output will be generated featuring this string (and remain empty otherwise). * `prerelease` If specified, the `next-prerelease` output will be generated featuring this string (and remain empty otherwise). From 007a2acca72262bac5ccf05c4e4e7e10677ad60e Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 1 May 2022 12:47:26 -0700 Subject: [PATCH 07/16] Adjustments --- action.yml | 1 + greatest-semver-tag.sh | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 56f0ea3..50c61a7 100644 --- a/action.yml +++ b/action.yml @@ -102,6 +102,7 @@ runs: id: cur run: > if [[ "${{ inputs.override }}" != "" ]]; then + [[ semver compare ${{ inputs.override }} 0.0.0 ]] = "1" || exit 1 echo "::set-output name=ver::${{ inputs.override }}" elif [[ "${{ steps.find.outputs.tag }}" = "" ]]; then echo "::set-output name=ver::0.0.0" diff --git a/greatest-semver-tag.sh b/greatest-semver-tag.sh index 5ec993f..50b8ee0 100755 --- a/greatest-semver-tag.sh +++ b/greatest-semver-tag.sh @@ -1,9 +1,13 @@ #!/bin/bash -latest="" +latest="0.0.0" while IFS= read -r line; do if [[ $(semver compare ${line} ${latest} 2> /dev/null) = '1' ]]; then latest=${line} fi #echo "... $line ..." done <<< "$(git tag)" -echo $latest +if [[ ${latest} != "0.0.0" ]]; then + echo ${latest} +else + echo "" +fi From 691104d1b3619e52504f3050572a8ca3e27d17d9 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 1 May 2022 12:49:01 -0700 Subject: [PATCH 08/16] Semicolon --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 50c61a7..252a5a5 100644 --- a/action.yml +++ b/action.yml @@ -102,7 +102,7 @@ runs: id: cur run: > if [[ "${{ inputs.override }}" != "" ]]; then - [[ semver compare ${{ inputs.override }} 0.0.0 ]] = "1" || exit 1 + [[ semver compare ${{ inputs.override }} 0.0.0 ]] = "1" || exit 1; echo "::set-output name=ver::${{ inputs.override }}" elif [[ "${{ steps.find.outputs.tag }}" = "" ]]; then echo "::set-output name=ver::0.0.0" From 70e75d72993cd3b900280435ea5e6199beb05197 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 1 May 2022 12:51:10 -0700 Subject: [PATCH 09/16] Adjustments --- action.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 252a5a5..8a2e32b 100644 --- a/action.yml +++ b/action.yml @@ -102,7 +102,9 @@ runs: id: cur run: > if [[ "${{ inputs.override }}" != "" ]]; then - [[ semver compare ${{ inputs.override }} 0.0.0 ]] = "1" || exit 1; + if [[ semver compare ${{ inputs.override }} 0.0.0 ]] != "1" ]]; then + echo "Invalid override."; exit 1 + fi echo "::set-output name=ver::${{ inputs.override }}" elif [[ "${{ steps.find.outputs.tag }}" = "" ]]; then echo "::set-output name=ver::0.0.0" From f19638014c14af37b97fb8755c943027abf14db8 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 1 May 2022 12:53:28 -0700 Subject: [PATCH 10/16] Syntax --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 8a2e32b..671e018 100644 --- a/action.yml +++ b/action.yml @@ -102,7 +102,7 @@ runs: id: cur run: > if [[ "${{ inputs.override }}" != "" ]]; then - if [[ semver compare ${{ inputs.override }} 0.0.0 ]] != "1" ]]; then + if [[ $(semver compare ${{ inputs.override }} 0.0.0) != "1" ]]; then echo "Invalid override."; exit 1 fi echo "::set-output name=ver::${{ inputs.override }}" From e8c773c3fd09d26a71df4878961960c11386f523 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 1 May 2022 12:58:11 -0700 Subject: [PATCH 11/16] Handle corner case --- action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 671e018..db51134 100644 --- a/action.yml +++ b/action.yml @@ -103,7 +103,8 @@ runs: run: > if [[ "${{ inputs.override }}" != "" ]]; then if [[ $(semver compare ${{ inputs.override }} 0.0.0) != "1" ]]; then - echo "Invalid override."; exit 1 + if [[ ${{ inputs.override }} != 0.0.0 ]]; then + echo "Invalid override."; exit 1 fi echo "::set-output name=ver::${{ inputs.override }}" elif [[ "${{ steps.find.outputs.tag }}" = "" ]]; then From f46c2cbb38fdbab2f0f6fa61acf58cd348d84713 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 1 May 2022 13:00:22 -0700 Subject: [PATCH 12/16] Add quotes --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index db51134..b38fb62 100644 --- a/action.yml +++ b/action.yml @@ -103,7 +103,7 @@ runs: run: > if [[ "${{ inputs.override }}" != "" ]]; then if [[ $(semver compare ${{ inputs.override }} 0.0.0) != "1" ]]; then - if [[ ${{ inputs.override }} != 0.0.0 ]]; then + if [[ "${{ inputs.override }}" != "0.0.0" ]]; then echo "Invalid override."; exit 1 fi echo "::set-output name=ver::${{ inputs.override }}" From 83d73f0bcee59bbf34e46c33def6e60ea880e4ea Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 1 May 2022 13:04:46 -0700 Subject: [PATCH 13/16] Missing fi --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index b38fb62..fa93d48 100644 --- a/action.yml +++ b/action.yml @@ -105,6 +105,7 @@ runs: if [[ $(semver compare ${{ inputs.override }} 0.0.0) != "1" ]]; then if [[ "${{ inputs.override }}" != "0.0.0" ]]; then echo "Invalid override."; exit 1 + fi fi echo "::set-output name=ver::${{ inputs.override }}" elif [[ "${{ steps.find.outputs.tag }}" = "" ]]; then From 9a19695585ffde559bfefa25713a75890381213e Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 1 May 2022 13:43:34 -0700 Subject: [PATCH 14/16] Minor changes to deal with override --- action.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index fa93d48..b08cee8 100644 --- a/action.yml +++ b/action.yml @@ -117,9 +117,15 @@ runs: - name: Determine the prefix and set it id: prefix run: > - tag="${{ steps.find.outputs.tag }}"; ver="${{ steps.cur.outputs.ver }}"; - echo "::set-output name=str::$(echo ${tag%"$ver"})" + if [[ "${{ inputs.override }}" != "" ]]; then + tag="${{ inputs.override }}" + elif [[ "${{ steps.find.outputs.tag }}" != "" ]]; then + tag="${{ steps.find.outputs.tag }}"; + fi + if [[ $tag != "" ]]; then + echo "::set-output name=str::$(echo ${tag%"$ver"})" + fi shell: bash - name: Test if planned input is greater than current id: test From bf65a753574dbbd515964af8a445e16e5ce1a4f2 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 1 May 2022 13:47:03 -0700 Subject: [PATCH 15/16] Fix --- action.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index b08cee8..dd11e1f 100644 --- a/action.yml +++ b/action.yml @@ -119,12 +119,9 @@ runs: run: > ver="${{ steps.cur.outputs.ver }}"; if [[ "${{ inputs.override }}" != "" ]]; then - tag="${{ inputs.override }}" + echo "::set-output name=str::$(echo ${${{ inputs.override }}%"$ver"})" elif [[ "${{ steps.find.outputs.tag }}" != "" ]]; then - tag="${{ steps.find.outputs.tag }}"; - fi - if [[ $tag != "" ]]; then - echo "::set-output name=str::$(echo ${tag%"$ver"})" + echo "::set-output name=str::$(echo ${${{ steps.find.outputs.tag }}%"$ver"})" fi shell: bash - name: Test if planned input is greater than current From d080a0cfdcc40dea2acf00534ed15ba6cc556bd8 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 1 May 2022 13:50:08 -0700 Subject: [PATCH 16/16] Add newline --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bc780b8..d9ae940 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,4 +70,4 @@ jobs: [[ "${{ steps.override.outputs.bump }}" = "1.3.0" ]] || exit 1 - name: Ensure next-build of foo-build is foo run: | - [[ "$(semver get build ${{ steps.foo-build.outputs.next-build }})" = "foo" ]] || exit 1 \ No newline at end of file + [[ "$(semver get build ${{ steps.foo-build.outputs.next-build }})" = "foo" ]] || exit 1