diff --git a/README.md b/README.md index ba4bd3b..a944e2d 100644 --- a/README.md +++ b/README.md @@ -60,12 +60,6 @@ Setup-go-faster supports these runner systems: | Windows | X64 | windows/amd64 | | Windows | ARM64 | windows/arm64 | -### What\'s missing? - -Just the `stable` input. I don\'t understand what `stable` adds for -actions/setup-go. If you only want stable builds you can set go-version -accordingly. If there is good use case for `stable`, it can be added. - ### A Note About Go 1.21.0 **Use setup-go-faster@v1.9.1 or later** if you want to install Go 1.21.0. @@ -83,6 +77,10 @@ dot-zero releases. They used to be styled like `go1.N`, but now they are The version of go to install. It can be an exact version or a semver constraint like '1.14.x' or '^1.14.4'. Do not add "go" or "v" to the beginning of the version. +There are two aliases available: 'stable' and 'oldstable'. These aliases will be the newest Go release and the +next most recent. For instance when go1.21.6 is the latest release, 'stable' will resolve to '1.21.x' and +'oldstable' will resolve to '1.20.x'. + Action runners come with some versions of go pre-installed. If any of those versions meet your semver constraint setup-go-faster will use those instead of checking whether a newer go available for download that meets your constraint. You can change this with the `ignore-local` input below. @@ -114,6 +112,8 @@ For those who learn best from examples: | ^1.15.4 | installs a go that is >= 1.15.4 and < 2 | | ~1.15.4 | installs a go that is >= 1.15.4 and < 1.16 | | < 1.15.6 >= 1.15.4 | installs a go that is >= 1.15.4 and < 1.15.6 | +| stable | installs the newest go release | +| oldstable | installs the next most recent go release | | tip | installs gotip from source | diff --git a/action.yml b/action.yml index 53c9447..a5dbd37 100644 --- a/action.yml +++ b/action.yml @@ -7,6 +7,10 @@ inputs: The version of go to install. It can be an exact version or a semver constraint like '1.14.x' or '^1.14.4'. Do not add "go" or "v" to the beginning of the version. + There are two aliases available: 'stable' and 'oldstable'. These aliases will be the newest Go release and the + next most recent. For instance when go1.21.6 is the latest release, 'stable' will resolve to '1.21.x' and + 'oldstable' will resolve to '1.20.x'. + Action runners come with some versions of go pre-installed. If any of those versions meet your semver constraint setup-go-faster will use those instead of checking whether a newer go available for download that meets your constraint. You can change this with the `ignore-local` input below. @@ -38,6 +42,8 @@ inputs: | ^1.15.4 | installs a go that is >= 1.15.4 and < 2 | | ~1.15.4 | installs a go that is >= 1.15.4 and < 1.16 | | < 1.15.6 >= 1.15.4 | installs a go that is >= 1.15.4 and < 1.15.6 | + | stable | installs the newest go release | + | oldstable | installs the next most recent go release | | tip | installs gotip from source | go-version-file: diff --git a/bindown.yml b/bindown.yml index b020c69..4d22e59 100644 --- a/bindown.yml +++ b/bindown.yml @@ -1,9 +1,10 @@ systems: - darwin/amd64 + - darwin/arm64 - linux/amd64 dependencies: action-doc: - template: action-doc#action-doc + template: action-doc vars: version: 0.4.0 octo: @@ -33,12 +34,22 @@ dependencies: required_vars: - ref templates: - action-doc#action-doc: + action-doc: url: https://github.com/WillAbides/action-doc/releases/download/v{{.version}}/action-doc_{{.version}}_{{.os}}_{{.arch}}.tar.gz systems: - darwin/amd64 + - darwin/arm64 - linux/386 - linux/amd64 + overrides: + - matcher: + os: + - darwin + arch: + - arm64 + dependency: + vars: + arch: amd64 required_vars: - version origin#octo: @@ -81,22 +92,41 @@ templates: required_vars: - version origin#shellcheck: - url: https://github.com/koalaman/shellcheck/releases/download/v{{.version}}/shellcheck-v{{.version}}.{{.os}}.{{.arch}}.tar.xz - archive_path: shellcheck-v{{.version}}/shellcheck + homepage: https://www.shellcheck.net + description: ShellCheck, a static analysis tool for shell scripts + url: https://github.com/koalaman/shellcheck/releases/download/v{{.version}}/shellcheck-v{{.version}}.{{.os}}.{{.arch}}{{.urlSuffix}} + archive_path: shellcheck-v{{.version}}/shellcheck{{.archivePathSuffix}} bin: shellcheck + vars: + archivePathSuffix: "" + urlSuffix: .tar.xz overrides: - matcher: os: - windows dependency: url: https://github.com/koalaman/shellcheck/releases/download/v{{.version}}/shellcheck-v{{.version}}.zip - archive_path: shellcheck-v{{.version}}.exe + archive_path: shellcheck.exe + - matcher: + arch: + - arm64 + os: + - darwin + dependency: + substitutions: + arch: + arm64: x86_64 substitutions: arch: amd64: x86_64 + arm: armv6hf + arm64: aarch64 systems: - darwin/amd64 + - darwin/arm64 - linux/amd64 + - linux/arm + - linux/arm64 - windows/amd64 required_vars: - version @@ -138,6 +168,7 @@ url_checksums: https://github.com/koalaman/shellcheck/releases/download/v0.7.1/shellcheck-v0.7.1.linux.x86_64.tar.xz: 64f17152d96d7ec261ad3086ed42d18232fcb65148b44571b564d688269d36c8 https://github.com/kward/shunit2/archive/ebc4baa08f045b7ef0f45c4b7d6f34f08d732f3d.tar.gz: d18b23a0db5deed5b0e10a732ac1f94579ac2781ce9408d62f0e847e3fa6910b https://github.com/mvdan/sh/releases/download/v3.6.0/shfmt_v3.6.0_darwin_amd64: b8c9c025b498e2816b62f0b717f6032e9ab49e725a45b8205f52f66318f17185 + https://github.com/mvdan/sh/releases/download/v3.6.0/shfmt_v3.6.0_darwin_arm64: 633f242246ee0a866c5f5df25cbf61b6af0d5e143555aca32950059cf13d91e0 https://github.com/mvdan/sh/releases/download/v3.6.0/shfmt_v3.6.0_linux_amd64: 5741a02a641de7e56b8da170e71a97e58050d66a3cf485fb268d6a5a8bb74afb https://github.com/octo-cli/octo-cli/releases/download/v0.23.0/octo-cli_0.23.0_Darwin_x86_64.tar.gz: 1388c1ca5838a453055930035c81b231b829ef3b0511cc7765dffdd73b83d355 https://github.com/octo-cli/octo-cli/releases/download/v0.23.0/octo-cli_0.23.0_Linux_x86_64.tar.gz: 7bad6194d91bd9cd86a348dadafd7725b3bb4010afe36294df0740e8c815947a 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..8523023 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 } @@ -59,6 +59,18 @@ test_run_1_21rc4() { do_test_run } +test_run_stable() { + GO_VERSION="stable" \ + WANT_VERSION="1.20.7" \ + do_test_run +} + +test_run_oldstable() { + GO_VERSION="oldstable" \ + WANT_VERSION="1.19.12" \ + do_test_run +} + test_go_mod() { GO_VERSION_FILE="$SHUNIT_TMPDIR"/test_go_mod/go.mod mkdir -p -- "$(dirname -- "$GO_VERSION_FILE")"