Skip to content

Commit a0ff521

Browse files
authored
Merge pull request #32 from WillAbides/oldstable
stable and oldstable aliases
2 parents a63c4c6 + 8676049 commit a0ff521

9 files changed

+132
-26
lines changed

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ Setup-go-faster supports these runner systems:
6060
| Windows | X64 | windows/amd64 |
6161
| Windows | ARM64 | windows/arm64 |
6262

63-
### What\'s missing?
64-
65-
Just the `stable` input. I don\'t understand what `stable` adds for
66-
actions/setup-go. If you only want stable builds you can set go-version
67-
accordingly. If there is good use case for `stable`, it can be added.
68-
6963
### A Note About Go 1.21.0
7064

7165
**Use [email protected] 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
8377
The version of go to install. It can be an exact version or a semver constraint like '1.14.x' or '^1.14.4'.
8478
Do not add "go" or "v" to the beginning of the version.
8579

80+
There are two aliases available: 'stable' and 'oldstable'. These aliases will be the newest Go release and the
81+
next most recent. For instance when go1.21.6 is the latest release, 'stable' will resolve to '1.21.x' and
82+
'oldstable' will resolve to '1.20.x'.
83+
8684
Action runners come with some versions of go pre-installed. If any of those versions meet your semver constraint
8785
setup-go-faster will use those instead of checking whether a newer go available for download that meets your
8886
constraint. You can change this with the `ignore-local` input below.
@@ -114,6 +112,8 @@ For those who learn best from examples:
114112
| ^1.15.4 | installs a go that is >= 1.15.4 and < 2 |
115113
| ~1.15.4 | installs a go that is >= 1.15.4 and < 1.16 |
116114
| < 1.15.6 >= 1.15.4 | installs a go that is >= 1.15.4 and < 1.15.6 |
115+
| stable | installs the newest go release |
116+
| oldstable | installs the next most recent go release |
117117
| tip | installs gotip from source |
118118

119119

action.yml

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ inputs:
77
The version of go to install. It can be an exact version or a semver constraint like '1.14.x' or '^1.14.4'.
88
Do not add "go" or "v" to the beginning of the version.
99
10+
There are two aliases available: 'stable' and 'oldstable'. These aliases will be the newest Go release and the
11+
next most recent. For instance when go1.21.6 is the latest release, 'stable' will resolve to '1.21.x' and
12+
'oldstable' will resolve to '1.20.x'.
13+
1014
Action runners come with some versions of go pre-installed. If any of those versions meet your semver constraint
1115
setup-go-faster will use those instead of checking whether a newer go available for download that meets your
1216
constraint. You can change this with the `ignore-local` input below.
@@ -38,6 +42,8 @@ inputs:
3842
| ^1.15.4 | installs a go that is >= 1.15.4 and < 2 |
3943
| ~1.15.4 | installs a go that is >= 1.15.4 and < 1.16 |
4044
| < 1.15.6 >= 1.15.4 | installs a go that is >= 1.15.4 and < 1.15.6 |
45+
| stable | installs the newest go release |
46+
| oldstable | installs the next most recent go release |
4147
| tip | installs gotip from source |
4248
4349
go-version-file:

bindown.yml

+36-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
systems:
22
- darwin/amd64
3+
- darwin/arm64
34
- linux/amd64
45
dependencies:
56
action-doc:
6-
template: action-doc#action-doc
7+
template: action-doc
78
vars:
89
version: 0.4.0
910
octo:
@@ -33,12 +34,22 @@ dependencies:
3334
required_vars:
3435
- ref
3536
templates:
36-
action-doc#action-doc:
37+
action-doc:
3738
url: https://github.com/WillAbides/action-doc/releases/download/v{{.version}}/action-doc_{{.version}}_{{.os}}_{{.arch}}.tar.gz
3839
systems:
3940
- darwin/amd64
41+
- darwin/arm64
4042
- linux/386
4143
- linux/amd64
44+
overrides:
45+
- matcher:
46+
os:
47+
- darwin
48+
arch:
49+
- arm64
50+
dependency:
51+
vars:
52+
arch: amd64
4253
required_vars:
4354
- version
4455
origin#octo:
@@ -81,22 +92,41 @@ templates:
8192
required_vars:
8293
- version
8394
origin#shellcheck:
84-
url: https://github.com/koalaman/shellcheck/releases/download/v{{.version}}/shellcheck-v{{.version}}.{{.os}}.{{.arch}}.tar.xz
85-
archive_path: shellcheck-v{{.version}}/shellcheck
95+
homepage: https://www.shellcheck.net
96+
description: ShellCheck, a static analysis tool for shell scripts
97+
url: https://github.com/koalaman/shellcheck/releases/download/v{{.version}}/shellcheck-v{{.version}}.{{.os}}.{{.arch}}{{.urlSuffix}}
98+
archive_path: shellcheck-v{{.version}}/shellcheck{{.archivePathSuffix}}
8699
bin: shellcheck
100+
vars:
101+
archivePathSuffix: ""
102+
urlSuffix: .tar.xz
87103
overrides:
88104
- matcher:
89105
os:
90106
- windows
91107
dependency:
92108
url: https://github.com/koalaman/shellcheck/releases/download/v{{.version}}/shellcheck-v{{.version}}.zip
93-
archive_path: shellcheck-v{{.version}}.exe
109+
archive_path: shellcheck.exe
110+
- matcher:
111+
arch:
112+
- arm64
113+
os:
114+
- darwin
115+
dependency:
116+
substitutions:
117+
arch:
118+
arm64: x86_64
94119
substitutions:
95120
arch:
96121
amd64: x86_64
122+
arm: armv6hf
123+
arm64: aarch64
97124
systems:
98125
- darwin/amd64
126+
- darwin/arm64
99127
- linux/amd64
128+
- linux/arm
129+
- linux/arm64
100130
- windows/amd64
101131
required_vars:
102132
- version
@@ -138,6 +168,7 @@ url_checksums:
138168
https://github.com/koalaman/shellcheck/releases/download/v0.7.1/shellcheck-v0.7.1.linux.x86_64.tar.xz: 64f17152d96d7ec261ad3086ed42d18232fcb65148b44571b564d688269d36c8
139169
https://github.com/kward/shunit2/archive/ebc4baa08f045b7ef0f45c4b7d6f34f08d732f3d.tar.gz: d18b23a0db5deed5b0e10a732ac1f94579ac2781ce9408d62f0e847e3fa6910b
140170
https://github.com/mvdan/sh/releases/download/v3.6.0/shfmt_v3.6.0_darwin_amd64: b8c9c025b498e2816b62f0b717f6032e9ab49e725a45b8205f52f66318f17185
171+
https://github.com/mvdan/sh/releases/download/v3.6.0/shfmt_v3.6.0_darwin_arm64: 633f242246ee0a866c5f5df25cbf61b6af0d5e143555aca32950059cf13d91e0
141172
https://github.com/mvdan/sh/releases/download/v3.6.0/shfmt_v3.6.0_linux_amd64: 5741a02a641de7e56b8da170e71a97e58050d66a3cf485fb268d6a5a8bb74afb
142173
https://github.com/octo-cli/octo-cli/releases/download/v0.23.0/octo-cli_0.23.0_Darwin_x86_64.tar.gz: 1388c1ca5838a453055930035c81b231b829ef3b0511cc7765dffdd73b83d355
143174
https://github.com/octo-cli/octo-cli/releases/download/v0.23.0/octo-cli_0.23.0_Linux_x86_64.tar.gz: 7bad6194d91bd9cd86a348dadafd7725b3bb4010afe36294df0740e8c815947a

src/install-go

+6-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ if [ -d "$target_dir" ]; then
3030
fi
3131
fi
3232

33-
[ -n "$skip_install" ] || install_go "$install_go_version" "$target_dir"
33+
if [ -z "$skip_install" ]; then
34+
tmp_dir="$(tmpdir_name tmp)"
35+
trap 'rm -rf -- "$tmp_dir"' EXIT
36+
mkdir -p -- "$tmp_dir"
37+
install_go "$install_go_version" "$target_dir" "$tmp_dir"
38+
fi
3439

3540
GITHUB_ENV="${GITHUB_ENV:-/dev/null}"
3641
GITHUB_PATH="${GITHUB_PATH:-/dev/null}"

src/lib

+41-7
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,11 @@ version_archive_name() {
111111
echo "$version.$(system_os "$system")-$(system_arch "$system")$extension"
112112
}
113113

114-
init_tmpdir() {
114+
tmpdir_name() {
115+
local dir_name="${1:-"tmp"}"
115116
local tmpdir="$RUNNER_WORKSPACE"
116117
tmpdir="${tmpdir:-"$TMPDIR"}"
117-
tmpdir="$tmpdir/setup-go-faster/tmp"
118-
mkdir -p "$tmpdir"
119-
rm -rf "$tmpdir"
120-
mkdir -p "$tmpdir"
121-
trap 'rm -rf "$tmpdir"' EXIT
118+
tmpdir="$tmpdir/setup-go-faster/$dir_name"
122119
echo "$tmpdir"
123120
}
124121

@@ -132,6 +129,7 @@ download_go_url() {
132129
install_go() {
133130
local go_version="${1#go}"
134131
local target_dir="$2"
132+
local tmpdir="$3"
135133
debug_out "installing go $go_version to $target_dir"
136134
local system
137135
system="$(go_system)"
@@ -141,7 +139,6 @@ install_go() {
141139
fi
142140
rm -rf "$target_dir"
143141
mkdir -p "$(dirname "$target_dir")"
144-
tmpdir="$(init_tmpdir)"
145142
cd "$tmpdir"
146143

147144
archive_name="$(version_archive_name go"$go_version" "$system")"
@@ -261,3 +258,40 @@ select_go_version_from_file() {
261258

262259
normalize_go_version "$found_version"
263260
}
261+
262+
get_known_versions() {
263+
local versions_url="$1"
264+
local tmp_dir="$2"
265+
local file="$tmp_dir/versions.txt"
266+
if [ -f "$file" ]; then
267+
cat "$file"
268+
return
269+
fi
270+
curl --retry 4 -s --fail -o "$file" "$versions_url"
271+
cat "$file"
272+
}
273+
274+
get_stable_minor_version() {
275+
local versions_url="$1"
276+
local tmp_dir="$2"
277+
local versions
278+
get_known_versions "$versions_url" "$tmp_dir" | grep -E '^go1\.[0-9]+(\.[0-9]+)?$' | head -1 | awk -F. '{print $2}'
279+
}
280+
281+
resolve_constraint_alias() {
282+
local constraint="$1"
283+
local versions_url="$2"
284+
local tmp_dir="$3"
285+
case "$constraint" in
286+
stable)
287+
echo "1.$(get_stable_minor_version "$versions_url" "$tmp_dir").x"
288+
;;
289+
oldstable)
290+
minor_version="$(get_stable_minor_version "$versions_url" "$tmp_dir")"
291+
echo "1.$((minor_version - 1)).x"
292+
;;
293+
*)
294+
echo "$constraint"
295+
;;
296+
esac
297+
}

src/lib_test.sh

+10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ setUp() {
88
. src/lib
99
}
1010

11+
# Nothing special about this one. It just happens to be HEAD of main when writing this.
12+
# Most recent version is go1.21rc4
13+
STABLE_VERSIONS_URL="https://raw.githubusercontent.com/WillAbides/goreleases/077db58ac86a8a2fb63c90817090e132eded0f3d/versions.txt"
14+
1115
test_homedir() {
1216
(
1317
export USERPROFILE="windows home"
@@ -166,4 +170,10 @@ test_supported_system() {
166170

167171
}
168172

173+
test_resolve_constraint_alias() {
174+
assertEquals "1.20.x" "$(resolve_constraint_alias "stable" "$STABLE_VERSIONS_URL" "$SHUNIT_TMPDIR")"
175+
assertEquals "1.19.x" "$(resolve_constraint_alias "oldstable" "$STABLE_VERSIONS_URL" "$SHUNIT_TMPDIR")"
176+
assertEquals "xxx" "$(resolve_constraint_alias "xxx" "$STABLE_VERSIONS_URL" "$SHUNIT_TMPDIR")"
177+
}
178+
169179
. ./external/shunit2

src/lib_test_long.sh

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ test_install_go() {
1414
RUNNER_TEMP="${RUNNER_TEMP:-"$tmpspace/runner_temp"}"
1515
export RUNNER_TEMP
1616
target="$tmpspace/go_target"
17-
version="1.15.4"
18-
install_go "$version" "$target"
17+
version="1.16.4"
18+
inst_tmp="$tmpspace/inst_tmp"
19+
mkdir -p "$inst_tmp"
20+
install_go "$version" "$target" "$inst_tmp"
1921
got_version="$("$target/bin/go" version)"
20-
assertEquals "go version go1.15.4 $(go_system)" "$got_version"
22+
assertEquals "go version go1.16.4 $(go_system)" "$got_version"
2123
)
2224
}
2325

src/run

+7-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ VERSIONS_URL="${VERSIONS_URL:-https://raw.githubusercontent.com/WillAbides/gorel
2727

2828
debug_out starting run
2929

30+
tmp_dir="$(tmpdir_name runtmp)"
31+
trap 'rm -rf -- "$tmp_dir"' EXIT
32+
mkdir -p -- "$tmp_dir"
33+
3034
export INSTALL_GO_TIP
3135

3236
# shellcheck disable=2153 # false positive about GO_VERSION being a misspelling of go_version
@@ -47,6 +51,8 @@ if [ "$constraint" = "tip" ] || [ "$constraint" = "gotip" ]; then
4751
INSTALL_GO_TIP=1
4852
fi
4953

54+
constraint="$(resolve_constraint_alias "$constraint" "$VERSIONS_URL" "$tmp_dir")"
55+
5056
if [ -z "$constraint" ]; then
5157
constraint=">=$(select_go_version_from_file "$GITHUB_WORKSPACE/$GO_VERSION_FILE")"
5258
fi
@@ -75,7 +81,7 @@ if [ -z "$lv" ]; then
7581
fi
7682

7783
if [ -z "$lv" ]; then
78-
known_versions="$(curl --retry 4 -s --fail "$VERSIONS_URL")"
84+
known_versions="$(get_known_versions "$VERSIONS_URL" "$tmp_dir")"
7985
lv="$(select_remote_version "$constraint" "$known_versions")"
8086
target_dir="$install_parent/${lv#go}/x64"
8187
fi

src/run_test_long.sh

+15-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ do_test_run() {
3535
assertContains "$(grep '^GOROOT=' "$GITHUB_OUTPUT")" "$WANT_GOROOT"
3636
}
3737

38-
test_run_1_15_x() {
39-
GO_VERSION="1.15.x" \
40-
WANT_VERSION="1.15.15" \
38+
test_run_1_16_x() {
39+
GO_VERSION="1.16.x" \
40+
WANT_VERSION="1.16.15" \
4141
do_test_run
4242
}
4343

@@ -59,6 +59,18 @@ test_run_1_21rc4() {
5959
do_test_run
6060
}
6161

62+
test_run_stable() {
63+
GO_VERSION="stable" \
64+
WANT_VERSION="1.20.7" \
65+
do_test_run
66+
}
67+
68+
test_run_oldstable() {
69+
GO_VERSION="oldstable" \
70+
WANT_VERSION="1.19.12" \
71+
do_test_run
72+
}
73+
6274
test_go_mod() {
6375
GO_VERSION_FILE="$SHUNIT_TMPDIR"/test_go_mod/go.mod
6476
mkdir -p -- "$(dirname -- "$GO_VERSION_FILE")"

0 commit comments

Comments
 (0)