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