Skip to content

Commit

Permalink
Merge pull request #2 from WillAbides/exacting
Browse files Browse the repository at this point in the history
skip constraint checks for exact versions
  • Loading branch information
WillAbides authored Jan 25, 2021
2 parents e68160f + 6d9dd04 commit 31f85c6
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 67 deletions.
28 changes: 0 additions & 28 deletions src/head-go-version

This file was deleted.

5 changes: 5 additions & 0 deletions src/lib
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,8 @@ exe_name() {
[ "$(goos)" = "windows" ] && suffix=".exe"
echo "$1$suffix"
}

is_precise_version() {
[[ $1 =~ ^[0-9]+(.[0-9]+(.[0-9]+)?)?([A-Za-z0-9]+)?$ ]] && return
return 1
}
29 changes: 29 additions & 0 deletions src/lib_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,33 @@ test_download_go_url() {
"$(RUNNER_OS=Windows download_go_url "1.15.5")"
}

test_is_precise_version() {
versions='
1
1.15
1.15.1
1.1.1
9999.9999.9999
1.15beta1
'

for v in $versions; do
is_precise_version "$v"
assertTrue "$v" $?
done

not_versions='
*
1.x
1.15.x
^ 1.15.1
'

echo "$not_versions" | while IFS= read -r v; do
is_precise_version "$v"
assertFalse "$v" $?
done

}

. ./third_party/shunit2/shunit2
20 changes: 5 additions & 15 deletions src/resolve-go-version
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ debug_out starting resolve-go-version
GO_VERSION_CONSTRAINT="$1"
GO_TOOL_CACHE="$2"

if is_precise_version "$GO_VERSION_CONSTRAINT"; then
echo "$GO_VERSION_CONSTRAINT"
exit
fi

# special case for gotip
if [ "$GO_VERSION_CONSTRAINT" = "gotip" ] || [ "$GO_VERSION_CONSTRAINT" = "tip" ]; then
echo "tip"
Expand All @@ -39,21 +44,6 @@ if [ -z "$IGNORE_LOCAL_GO" ]; then
done
fi

head_go_version="${head_go_version:-"./src/head-go-version"}"

# if the exact version is available to download, use it
if "$head_go_version" "$GO_VERSION_CONSTRAINT" ; then
echo "$GO_VERSION_CONSTRAINT"
exit
fi

## if the exact version is available to download, use it
#check_url="$(download_go_url "$GO_VERSION_CONSTRAINT")"
#if curl -IL --fail -s "$check_url" >/dev/null; then
# echo "$GO_VERSION_CONSTRAINT"
# exit
#fi

if [ -z "$IGNORE_LOCAL_GO" ]; then
set +e
local_matches="$(echo "$local_versions" | "$action_dir/third_party/sh-semver/semver.sh" -r "$GO_VERSION_CONSTRAINT")"
Expand Down
24 changes: 0 additions & 24 deletions src/resolve-go-version_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,13 @@ oneTimeSetUp() {
done
}

available_head_versions=''

mock_version_available_to_dl() {
v="$1"
for ver in $available_head_versions ; do
if [ "$ver" = "$v" ]; then
return 0
fi
done
return 1
}

mock_head_versions() {
export available_head_versions="$1"
export mock_head_go_version="1"
}

test_version() {
export dl_json="$ex_dl_json"
tmpdir="$SHUNIT_TMPDIR/${FUNCNAME[0]}"
toolcache="$tmpdir/go"
mkdir -p "$toolcache"
touch "$toolcache/1.14.2"
touch "$toolcache/1.15.6"
mock_head_versions '1.15
1.15beta1'

tests='*;1.15.6
1.15;1.15
Expand All @@ -81,18 +62,13 @@ tip;tip
done
}


test_version_ignore_local_go() {
export dl_json="$ex_dl_json"
tmpdir="$SHUNIT_TMPDIR/${FUNCNAME[0]}"
toolcache="$tmpdir/go"
mkdir -p "$toolcache"
touch "$toolcache/1.14.2"
touch "$toolcache/1.15.6"
mock_head_versions '1.15
1.15beta1'

export version_available_to_dl_func="mock_version_available_to_dl"

tests='*;1.15.7
1.15;1.15
Expand Down

0 comments on commit 31f85c6

Please sign in to comment.