From 56f4a516dd6283e366acc7824e69abcf17f88135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sefa=20=C5=9Eent=C3=BCrk?= Date: Fri, 30 Aug 2024 11:05:23 +0200 Subject: [PATCH 1/6] Update action to support with tag_prefix parameter --- action.yml | 6 ++++++ shared.sh | 15 ++++++++++++++- tests/test_version-increment.bats | 21 +++++++++++++++++++++ tests/test_version-lookup.bats | 31 +++++++++++++++++++++++++++++++ version-increment.sh | 9 +++++---- version-lookup.sh | 25 +++++++++++++++++++++++-- 6 files changed, 100 insertions(+), 7 deletions(-) diff --git a/action.yml b/action.yml index 5975dde..4f64fd7 100644 --- a/action.yml +++ b/action.yml @@ -40,6 +40,11 @@ inputs: description: 'Use the GitHub API to discover current tags, which avoids the need for a git checkout, but requires `curl` and `jq`' required: false default: false + tag_prefix: + description: | + Field to prefix the tag with a string (defaults to empty string). This is useful for projects that use a prefix in their tags. E.g. if set to `@org/product` the action will return `@org/product/1.2.3` as version. + required: false + default: false outputs: current-version: @@ -86,6 +91,7 @@ runs: github_token: ${{ github.token }} scheme: ${{ inputs.scheme }} use_api: ${{ inputs.use_api }} + tag_prefix: ${{ inputs.tag_prefix }} - id: version-increment run: "${GITHUB_ACTION_PATH}/version-increment.sh" diff --git a/shared.sh b/shared.sh index 8fe79cc..4f64f5b 100644 --- a/shared.sh +++ b/shared.sh @@ -11,7 +11,11 @@ export LC_ALL=C.UTF-8 pcre_semver='^(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)(?:-(?P(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$' pcre_master_ver='^(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)$' -pcre_allow_vprefix="^v{0,1}${pcre_master_ver:1}" + +# Extended regex to allow arbitrary prefixes before the semver +pcre_allow_prefix='^.*(?P'"${pcre_master_ver:1}"')$' + +pcre_allow_vprefix="^v{0,1}${pcre_allow_prefix:1}" pcre_old_calver='^(?P0|[1-9]\d*)-0{0,1}(?P0|[0-9]\d*)-R(?P0|[1-9]\d*)$' ##==---------------------------------------------------------------------------- @@ -51,6 +55,15 @@ if [[ "${use_api}" == 'true' ]] ; then fi fi +# Check if the tag_prefix is set, and if not, set it to an empty string +tag_prefix="${tag_prefix:-}" + +# Add a trailing @ to tag_prefix if it doesn't already end with one +if [[ -n "$tag_prefix" && "${tag_prefix: -1}" != "@" ]]; then + tag_prefix="${tag_prefix}@" +fi + + ##==---------------------------------------------------------------------------- ## MacOS compatibility diff --git a/tests/test_version-increment.bats b/tests/test_version-increment.bats index 1638a7d..68db626 100644 --- a/tests/test_version-increment.bats +++ b/tests/test_version-increment.bats @@ -409,3 +409,24 @@ function init_repo { [[ "$output" = *"VERSION=1.2.4"* ]] [[ "$output" = *"No conventional commit found"* ]] } + + +@test "increments the patch version by default if no conventional commits found and enabled (conventional commits) (with tag_prefix)" { + init_repo + + export tag_prefix="@org/product" + export current_version="@org/product@1.2.3" + export scheme="conventional_commits" + + echo "some new change" > feat.txt + git add feat.txt + git commit -m "new change" + + run ../../version-increment.sh + + print_run_info + [ "$status" -eq 0 ] && + [[ "$output" = *"VERSION=@org/product@1.2.4"* ]] + [[ "$output" = *"V_VERSION=@org/product@v1.2.4"* ]] + [[ "$output" = *"No conventional commit found"* ]] +} diff --git a/tests/test_version-lookup.bats b/tests/test_version-lookup.bats index 7373e37..57c2932 100644 --- a/tests/test_version-lookup.bats +++ b/tests/test_version-lookup.bats @@ -72,6 +72,37 @@ function init_repo { [[ "$output" = *"CURRENT_V_VERSION=v0.1.2"* ]] } +@test "finds the current normal version with tag_prefix enabled" { + init_repo + + export tag_prefix="@org/product" + + git tag @org/product@0.0.1 + git tag @org/product@0.1.1 + git tag @org/product@0.1.2 + + run version-lookup.sh + + print_run_info + [ "$status" -eq 0 ] && + [[ "$output" = *"CURRENT_VERSION=0.1.2"* ]] +} + +@test "tag_prefix enabled prefixes with a v" { + init_repo + + export tag_prefix="@org/product" + + git tag @org/product@0.1.2 + + run version-lookup.sh + + print_run_info + [ "$status" -eq 0 ] && + [[ "$output" = *"CURRENT_VERSION=0.1.2"* ]] && + [[ "$output" = *"CURRENT_V_VERSION=v0.1.2"* ]] +} + @test "finds the current normal version even if there's a newer pre-release version" { init_repo diff --git a/version-increment.sh b/version-increment.sh index 9fef875..a754abe 100755 --- a/version-increment.sh +++ b/version-increment.sh @@ -15,8 +15,8 @@ fi if [[ -z "${current_version:-}" ]] ; then echo "🛑 Environment variable 'current_version' is unset or empty" 1>&2 input_errors='true' -elif [[ -z "$(echo "${current_version}" | grep_p "${pcre_master_ver}")" ]] ; then - echo "🛑 Environment variable 'current_version' is not a valid normal version (M.m.p)" 1>&2 +elif [[ -z "$(echo "${current_version}" | grep_p "${pcre_allow_prefix}")" ]] ; then + echo "🛑 Environment variable 'current_version' is not a valid normal version (M.m.p) or (prefix@M.m.p)" 1>&2 input_errors='true' fi @@ -108,7 +108,8 @@ elif [[ "${increment}" == 'major' ]] ; then version_array[2]='0' fi -new_version="${version_array[0]}.${version_array[1]}.${version_array[2]}" +new_version="${tag_prefix}${version_array[0]}.${version_array[1]}.${version_array[2]}" +new_v_version="${tag_prefix}v${version_array[0]}.${version_array[1]}.${version_array[2]}" # check we haven't accidentally forgotten to set scheme to calver # TODO: provide an override "I know my version numbers are > 2020, but it's semver!" option @@ -139,7 +140,7 @@ echo "ℹī¸ The new version is ${new_version}" # shellcheck disable=SC2129 echo "VERSION=${new_version}" >> "${GITHUB_OUTPUT}" -echo "V_VERSION=v${new_version}" >> "${GITHUB_OUTPUT}" +echo "V_VERSION=${new_v_version}" >> "${GITHUB_OUTPUT}" echo "MAJOR_VERSION=${version_array[0]}" >> "${GITHUB_OUTPUT}" echo "MINOR_VERSION=${version_array[1]}" >> "${GITHUB_OUTPUT}" echo "PATCH_VERSION=${version_array[2]}" >> "${GITHUB_OUTPUT}" diff --git a/version-lookup.sh b/version-lookup.sh index 1780cc9..a06cd6c 100755 --- a/version-lookup.sh +++ b/version-lookup.sh @@ -23,6 +23,21 @@ fi ##==---------------------------------------------------------------------------- ## Version parsing +# Function to extract the semver part from the tag +extract_semver() { + local tag="$1" + if [[ -n "${tag_prefix:-}" ]]; then + # Escape special characters in tag_prefix + local escaped_prefix + escaped_prefix=$(printf '%s\n' "$tag_prefix" | sed 's/[][\/.^$*]/\\&/g') + + # Use | as the delimiter to avoid conflicts with / + echo "${tag}" | sed "s|^${escaped_prefix}||" + else + echo "${tag}" + fi +} + # detect current version - removing "v" from start of tag if it exists if [[ "${use_api:-}" == 'true' ]] ; then current_version="$( @@ -32,12 +47,18 @@ if [[ "${use_api:-}" == 'true' ]] ; then -H "X-GitHub-Api-Version: 2022-11-28" \ "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/git/matching-refs/tags/" \ | jq -r '.[].ref' | sed 's|refs/tags/||g' \ - | { grep_p "${pcre_allow_vprefix}" || true; } | sed 's/^v//g' | sort -V | tail -n 1 + | { grep_p "${pcre_allow_vprefix}" || true; } \ + | sed 's/^v//g' \ + | while read -r tag; do extract_semver "$tag"; done \ + | sort -V | tail -n 1 )" else current_version="$( git tag -l \ - | { grep_p "${pcre_allow_vprefix}" || true; } | sed 's/^v//g' | sort -V | tail -n 1 + | { grep_p "${pcre_allow_vprefix}" || true; } \ + | sed 's/^v//g' \ + | while read -r tag; do extract_semver "$tag"; done \ + | sort -V | tail -n 1 )" fi From aa4572b10f3a1c73b8571ee5cfd6fbcc839d12dd Mon Sep 17 00:00:00 2001 From: Phil Jay Date: Sat, 31 Aug 2024 13:16:51 +1000 Subject: [PATCH 2/6] Add test to see that versions only with tag_prefix are returned --- tests/test_version-lookup.bats | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test_version-lookup.bats b/tests/test_version-lookup.bats index 57c2932..a614482 100644 --- a/tests/test_version-lookup.bats +++ b/tests/test_version-lookup.bats @@ -116,6 +116,25 @@ function init_repo { [[ "$output" = *"CURRENT_VERSION=1.2.300"* ]] } +@test "finds only prefixed tags when tag_prefix set" { + init_repo + + export tag_prefix="@org/product" + + git tag @org/product@0.1.2 + git tag @org/product@0.1.3-dev.123 + git tag 2.4.5 + git tag 2.4.6-dev.456 + + run version-lookup.sh + + print_run_info + [ "$status" -eq 0 ] && + [[ "$output" = *"CURRENT_VERSION=0.1.2"* ]] && + [[ "$output" = *"CURRENT_V_VERSION=v0.1.2"* ]] +} +} + @test "returns 0.0.0 if no normal version detected" { init_repo From d4496413d63135f90068600e9ff82f65be2226ac Mon Sep 17 00:00:00 2001 From: Phil Jay Date: Sat, 31 Aug 2024 13:49:15 +1000 Subject: [PATCH 3/6] Don't auto-add `@` to prefix; Shift utility function --- shared.sh | 28 ++++++++++++++++++---------- tests/test_version-lookup.bats | 1 - version-increment.sh | 4 ++-- version-lookup.sh | 19 ++----------------- 4 files changed, 22 insertions(+), 30 deletions(-) diff --git a/shared.sh b/shared.sh index 4f64f5b..838fc12 100644 --- a/shared.sh +++ b/shared.sh @@ -11,13 +11,27 @@ export LC_ALL=C.UTF-8 pcre_semver='^(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)(?:-(?P(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$' pcre_master_ver='^(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)$' +pcre_allow_vprefix="^v{0,1}${pcre_master_ver:1}" -# Extended regex to allow arbitrary prefixes before the semver -pcre_allow_prefix='^.*(?P'"${pcre_master_ver:1}"')$' - -pcre_allow_vprefix="^v{0,1}${pcre_allow_prefix:1}" pcre_old_calver='^(?P0|[1-9]\d*)-0{0,1}(?P0|[0-9]\d*)-R(?P0|[1-9]\d*)$' +##==---------------------------------------------------------------------------- +## Utility function for removing tag_prefix if present + +remove_prefix() { + local tag="$1" + if [[ -n "${tag_prefix:-}" ]]; then + # Escape special characters in tag_prefix + local escaped_prefix + escaped_prefix=$(printf '%s\n' "$tag_prefix" | sed 's/[][\/.^$*]/\\&/g') + + # Use | as the delimiter to avoid conflicts with / + echo "${tag}" | sed "s|^${escaped_prefix}||" + else + echo "${tag}" + fi +} + ##==---------------------------------------------------------------------------- ## Conventional commit regexes ## see: https://www.conventionalcommits.org/en/v1.0.0/ @@ -58,12 +72,6 @@ fi # Check if the tag_prefix is set, and if not, set it to an empty string tag_prefix="${tag_prefix:-}" -# Add a trailing @ to tag_prefix if it doesn't already end with one -if [[ -n "$tag_prefix" && "${tag_prefix: -1}" != "@" ]]; then - tag_prefix="${tag_prefix}@" -fi - - ##==---------------------------------------------------------------------------- ## MacOS compatibility diff --git a/tests/test_version-lookup.bats b/tests/test_version-lookup.bats index a614482..d6d5291 100644 --- a/tests/test_version-lookup.bats +++ b/tests/test_version-lookup.bats @@ -133,7 +133,6 @@ function init_repo { [[ "$output" = *"CURRENT_VERSION=0.1.2"* ]] && [[ "$output" = *"CURRENT_V_VERSION=v0.1.2"* ]] } -} @test "returns 0.0.0 if no normal version detected" { init_repo diff --git a/version-increment.sh b/version-increment.sh index a754abe..1915805 100755 --- a/version-increment.sh +++ b/version-increment.sh @@ -15,8 +15,8 @@ fi if [[ -z "${current_version:-}" ]] ; then echo "🛑 Environment variable 'current_version' is unset or empty" 1>&2 input_errors='true' -elif [[ -z "$(echo "${current_version}" | grep_p "${pcre_allow_prefix}")" ]] ; then - echo "🛑 Environment variable 'current_version' is not a valid normal version (M.m.p) or (prefix@M.m.p)" 1>&2 +elif [[ -z "$(echo "${current_version}" | grep_p "${pcre_master_ver}")" ]] ; then + echo "🛑 Environment variable 'current_version' is not a valid normal version (M.m.p)" 1>&2 input_errors='true' fi diff --git a/version-lookup.sh b/version-lookup.sh index a06cd6c..d0e5a94 100755 --- a/version-lookup.sh +++ b/version-lookup.sh @@ -23,21 +23,6 @@ fi ##==---------------------------------------------------------------------------- ## Version parsing -# Function to extract the semver part from the tag -extract_semver() { - local tag="$1" - if [[ -n "${tag_prefix:-}" ]]; then - # Escape special characters in tag_prefix - local escaped_prefix - escaped_prefix=$(printf '%s\n' "$tag_prefix" | sed 's/[][\/.^$*]/\\&/g') - - # Use | as the delimiter to avoid conflicts with / - echo "${tag}" | sed "s|^${escaped_prefix}||" - else - echo "${tag}" - fi -} - # detect current version - removing "v" from start of tag if it exists if [[ "${use_api:-}" == 'true' ]] ; then current_version="$( @@ -49,7 +34,7 @@ if [[ "${use_api:-}" == 'true' ]] ; then | jq -r '.[].ref' | sed 's|refs/tags/||g' \ | { grep_p "${pcre_allow_vprefix}" || true; } \ | sed 's/^v//g' \ - | while read -r tag; do extract_semver "$tag"; done \ + | while read -r tag; do remove_prefix "$tag"; done \ | sort -V | tail -n 1 )" else @@ -57,7 +42,7 @@ else git tag -l \ | { grep_p "${pcre_allow_vprefix}" || true; } \ | sed 's/^v//g' \ - | while read -r tag; do extract_semver "$tag"; done \ + | while read -r tag; do remove_prefix "$tag"; done \ | sort -V | tail -n 1 )" fi From 836a0f07bb5aad5102949a3a98e76227c9f2c1c9 Mon Sep 17 00:00:00 2001 From: Phil Jay Date: Sat, 31 Aug 2024 14:16:34 +1000 Subject: [PATCH 4/6] Fix tests; Pre-filter tags --- shared.sh | 5 ++++- tests/test_version-lookup.bats | 12 ++++++------ version-lookup.sh | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/shared.sh b/shared.sh index 838fc12..d1b605a 100644 --- a/shared.sh +++ b/shared.sh @@ -12,7 +12,6 @@ export LC_ALL=C.UTF-8 pcre_semver='^(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)(?:-(?P(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$' pcre_master_ver='^(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)$' pcre_allow_vprefix="^v{0,1}${pcre_master_ver:1}" - pcre_old_calver='^(?P0|[1-9]\d*)-0{0,1}(?P0|[0-9]\d*)-R(?P0|[1-9]\d*)$' ##==---------------------------------------------------------------------------- @@ -25,6 +24,10 @@ remove_prefix() { local escaped_prefix escaped_prefix=$(printf '%s\n' "$tag_prefix" | sed 's/[][\/.^$*]/\\&/g') + if [[ -z "$(echo "${tag}" | grep "^${tag_prefix}")" ]] ; then + echo "" + return + fi # Use | as the delimiter to avoid conflicts with / echo "${tag}" | sed "s|^${escaped_prefix}||" else diff --git a/tests/test_version-lookup.bats b/tests/test_version-lookup.bats index d6d5291..6c53440 100644 --- a/tests/test_version-lookup.bats +++ b/tests/test_version-lookup.bats @@ -75,7 +75,7 @@ function init_repo { @test "finds the current normal version with tag_prefix enabled" { init_repo - export tag_prefix="@org/product" + export tag_prefix="@org/product@" git tag @org/product@0.0.1 git tag @org/product@0.1.1 @@ -91,9 +91,9 @@ function init_repo { @test "tag_prefix enabled prefixes with a v" { init_repo - export tag_prefix="@org/product" + export tag_prefix="@org/product/" - git tag @org/product@0.1.2 + git tag @org/product/0.1.2 run version-lookup.sh @@ -119,10 +119,10 @@ function init_repo { @test "finds only prefixed tags when tag_prefix set" { init_repo - export tag_prefix="@org/product" + export tag_prefix="my_product-" - git tag @org/product@0.1.2 - git tag @org/product@0.1.3-dev.123 + git tag my_product-0.1.2 + git tag my_product-0.1.3-dev.123 git tag 2.4.5 git tag 2.4.6-dev.456 diff --git a/version-lookup.sh b/version-lookup.sh index d0e5a94..3d9120b 100755 --- a/version-lookup.sh +++ b/version-lookup.sh @@ -32,17 +32,17 @@ if [[ "${use_api:-}" == 'true' ]] ; then -H "X-GitHub-Api-Version: 2022-11-28" \ "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/git/matching-refs/tags/" \ | jq -r '.[].ref' | sed 's|refs/tags/||g' \ + | while read -r tag; do remove_prefix "$tag"; done \ | { grep_p "${pcre_allow_vprefix}" || true; } \ | sed 's/^v//g' \ - | while read -r tag; do remove_prefix "$tag"; done \ | sort -V | tail -n 1 )" else current_version="$( git tag -l \ + | while read -r tag; do remove_prefix "$tag"; done \ | { grep_p "${pcre_allow_vprefix}" || true; } \ | sed 's/^v//g' \ - | while read -r tag; do remove_prefix "$tag"; done \ | sort -V | tail -n 1 )" fi From 5af72f0ae1d12841ddc66968772c06618645eee9 Mon Sep 17 00:00:00 2001 From: Phil Jay Date: Sat, 31 Aug 2024 14:38:32 +1000 Subject: [PATCH 5/6] Introduce new outputs --- .github/workflows/test-and-release.yml | 15 +++++++++++++++ action.yml | 6 ++++++ tests/test_version-increment.bats | 8 ++++---- tests/test_version-lookup.bats | 14 ++++++++++++++ version-increment.sh | 5 ++--- 5 files changed, 41 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test-and-release.yml b/.github/workflows/test-and-release.yml index f46778e..647ca3f 100644 --- a/.github/workflows/test-and-release.yml +++ b/.github/workflows/test-and-release.yml @@ -114,6 +114,21 @@ jobs: [[ "${{ steps.version-via-api.outputs.patch-version }}" == "${{ steps.version-via-git.outputs.patch-version }}" ]] # Don't test the full version or pre-version, since the number of digits is likely to be different (9 via api vs. 7 via git) + - name: Get next version via Git with tag-prefix + uses: ./ + id: version-prefix + with: + scheme: 'semver' + use_api: false + tag_prefix: 'foo/bar@' + + - name: Check that it starts from 0.0.1 (since prefix doesn't exist) + shell: bash + run: | + [[ "${{ steps.version-prefix.outputs.current-version }}" == "0.0.0" ]] + [[ "${{ steps.version-prefix.outputs.version }}" == "0.0.1" ]] + [[ "${{ steps.version-prefix.outputs.prefixed-version }}" == "foo/bar@0.0.1" ]] + release: needs: - test-action-yml diff --git a/action.yml b/action.yml index 4f64fd7..c6c81a6 100644 --- a/action.yml +++ b/action.yml @@ -80,6 +80,12 @@ outputs: patch-v-version: description: 'Patch number of the incremented version, prefixed with a `v` charatcter' value: ${{ steps.version-increment.outputs.PATCH_V_VERSION }} + prefixed-version: + description: 'Incremented version calculated, including a `tag_prefix` if specified' + value: ${{ inputs.tag_prefix}}${{ steps.version-increment.outputs.VERSION }} + prefixed-v-version: + description: 'Incremented version calculated, prefixed with a `v` charatcter, and also including a `tag_prefix` if specified' + value: ${{ inputs.tag_prefix}}${{ steps.version-increment.outputs.V_VERSION }} runs: using: "composite" diff --git a/tests/test_version-increment.bats b/tests/test_version-increment.bats index 68db626..2aa5704 100644 --- a/tests/test_version-increment.bats +++ b/tests/test_version-increment.bats @@ -414,8 +414,8 @@ function init_repo { @test "increments the patch version by default if no conventional commits found and enabled (conventional commits) (with tag_prefix)" { init_repo - export tag_prefix="@org/product" - export current_version="@org/product@1.2.3" + export tag_prefix="@org/product@" + export current_version="1.2.3" export scheme="conventional_commits" echo "some new change" > feat.txt @@ -426,7 +426,7 @@ function init_repo { print_run_info [ "$status" -eq 0 ] && - [[ "$output" = *"VERSION=@org/product@1.2.4"* ]] - [[ "$output" = *"V_VERSION=@org/product@v1.2.4"* ]] + [[ "$output" = *"VERSION=1.2.4"* ]] + [[ "$output" = *"V_VERSION=v1.2.4"* ]] [[ "$output" = *"No conventional commit found"* ]] } diff --git a/tests/test_version-lookup.bats b/tests/test_version-lookup.bats index 6c53440..ebb03f1 100644 --- a/tests/test_version-lookup.bats +++ b/tests/test_version-lookup.bats @@ -156,6 +156,20 @@ function init_repo { [[ "$output" = *"CURRENT_VERSION=0.0.0"* ]] } +@test "returns 0.0.0 if no prefix version detected even if there's a non-prefix release version" { + init_repo + + export tag_prefix="code/" + + git tag 0.1.0 + + run version-lookup.sh + + print_run_info + [ "$status" -eq 0 ] && + [[ "$output" = *"CURRENT_VERSION=0.0.0"* ]] +} + @test "returns a calver if no normal version detected and calver scheme specified" { init_repo diff --git a/version-increment.sh b/version-increment.sh index 1915805..9fef875 100755 --- a/version-increment.sh +++ b/version-increment.sh @@ -108,8 +108,7 @@ elif [[ "${increment}" == 'major' ]] ; then version_array[2]='0' fi -new_version="${tag_prefix}${version_array[0]}.${version_array[1]}.${version_array[2]}" -new_v_version="${tag_prefix}v${version_array[0]}.${version_array[1]}.${version_array[2]}" +new_version="${version_array[0]}.${version_array[1]}.${version_array[2]}" # check we haven't accidentally forgotten to set scheme to calver # TODO: provide an override "I know my version numbers are > 2020, but it's semver!" option @@ -140,7 +139,7 @@ echo "ℹī¸ The new version is ${new_version}" # shellcheck disable=SC2129 echo "VERSION=${new_version}" >> "${GITHUB_OUTPUT}" -echo "V_VERSION=${new_v_version}" >> "${GITHUB_OUTPUT}" +echo "V_VERSION=v${new_version}" >> "${GITHUB_OUTPUT}" echo "MAJOR_VERSION=${version_array[0]}" >> "${GITHUB_OUTPUT}" echo "MINOR_VERSION=${version_array[1]}" >> "${GITHUB_OUTPUT}" echo "PATCH_VERSION=${version_array[2]}" >> "${GITHUB_OUTPUT}" From 0f298121cd86d229cb258aab172d99654aa8e421 Mon Sep 17 00:00:00 2001 From: Phil Jay Date: Sat, 31 Aug 2024 14:44:57 +1000 Subject: [PATCH 6/6] Update README --- README.md | 29 ++++++++++++++++------------- action.yml | 2 +- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 9eeadb7..f434371 100644 --- a/README.md +++ b/README.md @@ -132,22 +132,25 @@ Examples: | increment | The digit to increment, either `major`, `minor` or `patch`, ignored if `scheme` == `calver` | No | `patch` | | release_branch | Specify a non-default branch to use for the release tag (the one without -pre) | No | | | use_api | Use the GitHub API to discover current tags, which avoids the need for a git checkout, but requires `curl` and `jq` | No | `false` | +| tag_prefix | Prefix the tag with a string (defaults to empty string). e.g. if set to `@org/product/` the action will filter by this prefix and return `@org/product/1.2.3` in `prefixed-version` output | No | | ### Outputs 📤 -| name | description | -| :--- | :--- | -| current-version | The current latest version detected from the git repositories tags | -| current-v-version | The current latest version detected from the git repositories tags, prefixed with a `v` character | -| version | The incremented version number (e.g. the next version) | -| v-version | The incremented version number (e.g. the next version), prefixed with a `v` character | -| major-version | Major number of the incremented version | -| minor-version | Minor number of the incremented version | -| patch-version | Patch number of the incremented version | -| pre-release-label | Pre-release label of the incremented version | -| major-v-version | Major number of the incremented version, prefixed with a `v` character | -| minor-v-version | Minor number of the incremented version, prefixed with a `v` character | -| patch-v-version | Patch number of the incremented version, prefixed with a `v` character | +| name | description | +| :--- | :--- | +| current-version | The current latest version detected from the git repositories tags | +| current-v-version | The current latest version detected from the git repositories tags, prefixed with a `v` character | +| version | The incremented version number (e.g. the next version) | +| v-version | The incremented version number (e.g. the next version), prefixed with a `v` character | +| major-version | Major number of the incremented version | +| minor-version | Minor number of the incremented version | +| patch-version | Patch number of the incremented version | +| pre-release-label | Pre-release label of the incremented version | +| major-v-version | Major number of the incremented version, prefixed with a `v` character | +| minor-v-version | Minor number of the incremented version, prefixed with a `v` character | +| patch-v-version | Patch number of the incremented version, prefixed with a `v` character | +| prefixed-version | Incremented version calculated, including a `tag_prefix` if specified | +| prefixed-v-version | Incremented version calculated, prefixed with a `v` charatcter, and also including a `tag_prefix` if specified | ## Contributing 💕 diff --git a/action.yml b/action.yml index c6c81a6..994c024 100644 --- a/action.yml +++ b/action.yml @@ -42,7 +42,7 @@ inputs: default: false tag_prefix: description: | - Field to prefix the tag with a string (defaults to empty string). This is useful for projects that use a prefix in their tags. E.g. if set to `@org/product` the action will return `@org/product/1.2.3` as version. + Prefix the tag with a string (defaults to empty string). e.g. if set to `@org/product/` the action will filter by this prefix and return `@org/product/1.2.3` in `prefixed-version` output required: false default: false