From 93e4f707f50f8a8ae168a7525c7f8fa2d101dbc9 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Mon, 15 Jan 2024 15:26:43 -0600 Subject: [PATCH] stable and oldstable aliases --- src/install-go | 7 ++++++- src/lib | 48 +++++++++++++++++++++++++++++++++++++------- src/lib_test.sh | 10 +++++++++ src/lib_test_long.sh | 8 +++++--- src/run | 8 +++++++- src/run_test_long.sh | 6 +++--- 6 files changed, 72 insertions(+), 15 deletions(-) diff --git a/src/install-go b/src/install-go index 7e6db22..b796697 100755 --- a/src/install-go +++ b/src/install-go @@ -30,7 +30,12 @@ if [ -d "$target_dir" ]; then fi fi -[ -n "$skip_install" ] || install_go "$install_go_version" "$target_dir" +if [ -z "$skip_install" ]; then + tmp_dir="$(tmpdir_name tmp)" + trap 'rm -rf -- "$tmp_dir"' EXIT + mkdir -p -- "$tmp_dir" + install_go "$install_go_version" "$target_dir" "$tmp_dir" +fi GITHUB_ENV="${GITHUB_ENV:-/dev/null}" GITHUB_PATH="${GITHUB_PATH:-/dev/null}" diff --git a/src/lib b/src/lib index aa2c38b..b862cbf 100755 --- a/src/lib +++ b/src/lib @@ -111,14 +111,11 @@ version_archive_name() { echo "$version.$(system_os "$system")-$(system_arch "$system")$extension" } -init_tmpdir() { +tmpdir_name() { + local dir_name="${1:-"tmp"}" local tmpdir="$RUNNER_WORKSPACE" tmpdir="${tmpdir:-"$TMPDIR"}" - tmpdir="$tmpdir/setup-go-faster/tmp" - mkdir -p "$tmpdir" - rm -rf "$tmpdir" - mkdir -p "$tmpdir" - trap 'rm -rf "$tmpdir"' EXIT + tmpdir="$tmpdir/setup-go-faster/$dir_name" echo "$tmpdir" } @@ -132,6 +129,7 @@ download_go_url() { install_go() { local go_version="${1#go}" local target_dir="$2" + local tmpdir="$3" debug_out "installing go $go_version to $target_dir" local system system="$(go_system)" @@ -141,7 +139,6 @@ install_go() { fi rm -rf "$target_dir" mkdir -p "$(dirname "$target_dir")" - tmpdir="$(init_tmpdir)" cd "$tmpdir" archive_name="$(version_archive_name go"$go_version" "$system")" @@ -261,3 +258,40 @@ select_go_version_from_file() { normalize_go_version "$found_version" } + +get_known_versions() { + local versions_url="$1" + local tmp_dir="$2" + local file="$tmp_dir/versions.txt" + if [ -f "$file" ]; then + cat "$file" + return + fi + curl --retry 4 -s --fail -o "$file" "$versions_url" + cat "$file" +} + +get_stable_minor_version() { + local versions_url="$1" + local tmp_dir="$2" + local versions + get_known_versions "$versions_url" "$tmp_dir" | grep -E '^go1\.[0-9]+(\.[0-9]+)?$' | head -1 | awk -F. '{print $2}' +} + +resolve_constraint_alias() { + local constraint="$1" + local versions_url="$2" + local tmp_dir="$3" + case "$constraint" in + stable) + echo "1.$(get_stable_minor_version "$versions_url" "$tmp_dir").x" + ;; + oldstable) + minor_version="$(get_stable_minor_version "$versions_url" "$tmp_dir")" + echo "1.$((minor_version - 1)).x" + ;; + *) + echo "$constraint" + ;; + esac +} diff --git a/src/lib_test.sh b/src/lib_test.sh index 36d133f..d998a73 100755 --- a/src/lib_test.sh +++ b/src/lib_test.sh @@ -8,6 +8,10 @@ setUp() { . src/lib } +# Nothing special about this one. It just happens to be HEAD of main when writing this. +# Most recent version is go1.21rc4 +STABLE_VERSIONS_URL="https://raw.githubusercontent.com/WillAbides/goreleases/077db58ac86a8a2fb63c90817090e132eded0f3d/versions.txt" + test_homedir() { ( export USERPROFILE="windows home" @@ -166,4 +170,10 @@ test_supported_system() { } +test_resolve_constraint_alias() { + assertEquals "1.20.x" "$(resolve_constraint_alias "stable" "$STABLE_VERSIONS_URL" "$SHUNIT_TMPDIR")" + assertEquals "1.19.x" "$(resolve_constraint_alias "oldstable" "$STABLE_VERSIONS_URL" "$SHUNIT_TMPDIR")" + assertEquals "xxx" "$(resolve_constraint_alias "xxx" "$STABLE_VERSIONS_URL" "$SHUNIT_TMPDIR")" +} + . ./external/shunit2 diff --git a/src/lib_test_long.sh b/src/lib_test_long.sh index 75f3426..17b9b0d 100755 --- a/src/lib_test_long.sh +++ b/src/lib_test_long.sh @@ -14,10 +14,12 @@ test_install_go() { RUNNER_TEMP="${RUNNER_TEMP:-"$tmpspace/runner_temp"}" export RUNNER_TEMP target="$tmpspace/go_target" - version="1.15.4" - install_go "$version" "$target" + version="1.16.4" + inst_tmp="$tmpspace/inst_tmp" + mkdir -p "$inst_tmp" + install_go "$version" "$target" "$inst_tmp" got_version="$("$target/bin/go" version)" - assertEquals "go version go1.15.4 $(go_system)" "$got_version" + assertEquals "go version go1.16.4 $(go_system)" "$got_version" ) } diff --git a/src/run b/src/run index d0b4b34..0b417b5 100755 --- a/src/run +++ b/src/run @@ -27,6 +27,10 @@ VERSIONS_URL="${VERSIONS_URL:-https://raw.githubusercontent.com/WillAbides/gorel debug_out starting run +tmp_dir="$(tmpdir_name runtmp)" +trap 'rm -rf -- "$tmp_dir"' EXIT +mkdir -p -- "$tmp_dir" + export INSTALL_GO_TIP # shellcheck disable=2153 # false positive about GO_VERSION being a misspelling of go_version @@ -47,6 +51,8 @@ if [ "$constraint" = "tip" ] || [ "$constraint" = "gotip" ]; then INSTALL_GO_TIP=1 fi +constraint="$(resolve_constraint_alias "$constraint" "$VERSIONS_URL" "$tmp_dir")" + if [ -z "$constraint" ]; then constraint=">=$(select_go_version_from_file "$GITHUB_WORKSPACE/$GO_VERSION_FILE")" fi @@ -75,7 +81,7 @@ if [ -z "$lv" ]; then fi if [ -z "$lv" ]; then - known_versions="$(curl --retry 4 -s --fail "$VERSIONS_URL")" + known_versions="$(get_known_versions "$VERSIONS_URL" "$tmp_dir")" lv="$(select_remote_version "$constraint" "$known_versions")" target_dir="$install_parent/${lv#go}/x64" fi diff --git a/src/run_test_long.sh b/src/run_test_long.sh index 5c7a0c3..5370546 100755 --- a/src/run_test_long.sh +++ b/src/run_test_long.sh @@ -35,9 +35,9 @@ do_test_run() { assertContains "$(grep '^GOROOT=' "$GITHUB_OUTPUT")" "$WANT_GOROOT" } -test_run_1_15_x() { - GO_VERSION="1.15.x" \ - WANT_VERSION="1.15.15" \ +test_run_1_16_x() { + GO_VERSION="1.16.x" \ + WANT_VERSION="1.16.15" \ do_test_run }