Skip to content

Commit

Permalink
Fix tests; Pre-filter tags
Browse files Browse the repository at this point in the history
  • Loading branch information
ps-jay committed Aug 31, 2024
1 parent d449641 commit 836a0f0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
5 changes: 4 additions & 1 deletion shared.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export LC_ALL=C.UTF-8
pcre_semver='^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?: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<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$'
pcre_master_ver='^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)$'
pcre_allow_vprefix="^v{0,1}${pcre_master_ver:1}"

pcre_old_calver='^(?P<major>0|[1-9]\d*)-0{0,1}(?P<minor>0|[0-9]\d*)-R(?P<patch>0|[1-9]\d*)$'

##==----------------------------------------------------------------------------
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions tests/test_version-lookup.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
git tag @org/[email protected]
Expand All @@ -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

Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions version-lookup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 836a0f0

Please sign in to comment.