diff --git a/src/head-go-version b/src/head-go-version deleted file mode 100755 index 7767486..0000000 --- a/src/head-go-version +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -set -e -[ -n "$DEBUG" ] && set -x - -CDPATH="" cd -- "$(dirname -- "$(dirname -- "$0")")" - -. src/lib - -debug_out starting head-go-version - -version="$1" - -mock_head_go_version="${mock_head_go_version:-""}" -if [ -n "$mock_head_go_version" ]; then - available_head_versions="${available_head_versions:-""}" - for ver in $available_head_versions; do - if [ "$ver" = "$version" ]; then - exit 0 - fi - done - exit 1 -fi - -. src/lib - -check_url="$(download_go_url "$version")" -curl -IL --fail -s "$check_url" >/dev/null diff --git a/src/lib b/src/lib index c404c08..8d45b83 100755 --- a/src/lib +++ b/src/lib @@ -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 +} diff --git a/src/lib_test.sh b/src/lib_test.sh index 3874211..142b83a 100755 --- a/src/lib_test.sh +++ b/src/lib_test.sh @@ -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 diff --git a/src/resolve-go-version b/src/resolve-go-version index 7898c1b..a5c92dd 100755 --- a/src/resolve-go-version +++ b/src/resolve-go-version @@ -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" @@ -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")" diff --git a/src/resolve-go-version_test.sh b/src/resolve-go-version_test.sh index f35c58a..c1bae75 100755 --- a/src/resolve-go-version_test.sh +++ b/src/resolve-go-version_test.sh @@ -38,23 +38,6 @@ 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]}" @@ -62,8 +45,6 @@ test_version() { 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 @@ -81,7 +62,6 @@ tip;tip done } - test_version_ignore_local_go() { export dl_json="$ex_dl_json" tmpdir="$SHUNIT_TMPDIR/${FUNCNAME[0]}" @@ -89,10 +69,6 @@ test_version_ignore_local_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