Skip to content

Commit

Permalink
stable and oldstable aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAbides committed Jan 15, 2024
1 parent a63c4c6 commit 93e4f70
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 15 deletions.
7 changes: 6 additions & 1 deletion src/install-go
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
48 changes: 41 additions & 7 deletions src/lib
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand All @@ -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)"
Expand All @@ -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")"
Expand Down Expand Up @@ -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
}
10 changes: 10 additions & 0 deletions src/lib_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
8 changes: 5 additions & 3 deletions src/lib_test_long.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
}

Expand Down
8 changes: 7 additions & 1 deletion src/run
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/run_test_long.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 93e4f70

Please sign in to comment.