Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support more runners #30

Merged
merged 1 commit into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ Look at those outputs. If you want to use GOPATH or GOMODCACHE as input in some
other step, you can just grab it from setup-go-faster\'s output instead of
having to add another step just to set an environment variable.

### Supported Systems

Setup-go-faster supports these runner systems:

| RUNNER_OS | RUNNER_ARCH | go system |
|-----------|-------------|---------------|
| Linux | X86 | linux/386 |
| Linux | X64 | linux/amd64 |
| Linux | ARM64 | linux/arm64 |
| MacOS | X64 | darwin/amd64 |
| MacOS | ARM64 | darwin/arm64 |
| Windows | X86 | windows/386 |
| Windows | X64 | windows/amd64 |
| Windows | ARM64 | windows/arm64 |

### What\'s missing?

Just the `stable` input. I don\'t understand what `stable` adds for
Expand Down
93 changes: 79 additions & 14 deletions src/lib
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ set -e

CDPATH="" cd -- "$(dirname -- "$0")/.."

supported_system() {
grep -q "'$1'" <<< "
'linux/386'
'linux/amd64'
'linux/arm64'
'darwin/amd64'
'darwin/arm64'
'windows/386'
'windows/amd64'
'windows/arm64'
"
}

goos() {
case "$RUNNER_OS" in
macOS)
Expand All @@ -21,6 +34,55 @@ goos() {
esac
}

# get the arch from uname in case RUNNER_ARCH is not set
# copied from https://github.com/client9/shlib
uname_arch() {
arch=$(uname -m)
case $arch in
x86_64) arch="amd64" ;;
x86) arch="386" ;;
i686) arch="386" ;;
i386) arch="386" ;;
aarch64) arch="arm64" ;;
armv5*) arch="armv5" ;;
armv6*) arch="armv6" ;;
armv7*) arch="armv7" ;;
esac
echo ${arch}
}

# Get the arch to download. Use RUNNER_ARCH first, then uname if not set.
goarch() {
case "$RUNNER_ARCH" in
X86)
echo "386"
;;
X64)
echo "amd64"
;;
ARM64)
echo "arm64"
;;
*)
uname_arch
;;
esac
}

go_system() {
echo "$(goos)/$(goarch)"
}

# returns the os part of os/arch
system_os() {
echo "${1%%/*}"
}

# returns the arch part of os/arch
system_arch() {
echo "${1##*/}"
}

debug_out() {
if [ -n "$DEBUG" ]; then
echo "$@" >&2
Expand All @@ -39,17 +101,14 @@ sdk_dir() {
echo "$(homedir)/sdk"
}

extension() {
if [ "$(goos)" = "windows" ]; then
echo ".zip"
else
echo ".tar.gz"
fi
}

version_archive_name() {
local version="$1"
echo "$version.$(goos)-amd64$(extension)"
local system="$2"
local extension=".tar.gz"
if [ "$(system_os "$system")" = "windows" ]; then
extension=".zip"
fi
echo "$version.$(system_os "$system")-$(system_arch "$system")$extension"
}

init_tmpdir() {
Expand All @@ -65,26 +124,32 @@ init_tmpdir() {

download_go_url() {
local go_version="$1"
archive_name="$(version_archive_name go"$go_version")"
local system="$2"
archive_name="$(version_archive_name go"$go_version" "$system")"
echo "https://storage.googleapis.com/golang/$archive_name"
}

install_go() {
local go_version="${1#go}"
local target_dir="$2"
debug_out "installing go $go_version to $target_dir"
local system
system="$(go_system)"
if ! supported_system "$system"; then
echo "::error ::Unsupported system: $system"
return 1
fi
rm -rf "$target_dir"
mkdir -p "$(dirname "$target_dir")"
tmpdir="$(init_tmpdir)"
cd "$tmpdir"

archive_name="$(version_archive_name go"$go_version")"
archive_name="$(version_archive_name go"$go_version" "$system")"

# 4 retries is 15 seconds of waiting
curl -s --retry 4 --fail -O "$(download_go_url "$go_version")"
curl -s --retry 4 --fail -O "$(download_go_url "$go_version" "$system")"

pwd
if [ "$(extension)" = ".zip" ]; then
if [ "${archive_name: -4}" == ".zip" ]; then
7z x "$archive_name"
else
tar -xzf "$archive_name"
Expand Down
45 changes: 34 additions & 11 deletions src/lib_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@ test_homedir() {
}

test_download_go_url() {
assertEquals \
"https://storage.googleapis.com/golang/go1.15.5.linux-amd64.tar.gz" \
"$(RUNNER_OS=Linux download_go_url "1.15.5")"

assertEquals \
"https://storage.googleapis.com/golang/go1.15.5.darwin-amd64.tar.gz" \
"$(RUNNER_OS=macOS download_go_url "1.15.5")"

assertEquals \
"https://storage.googleapis.com/golang/go1.15.5.windows-amd64.zip" \
"$(RUNNER_OS=Windows download_go_url "1.15.5")"
run_test() {
local system="$1"
local go_version="$2"
local want_url="$3"
got_url="$(download_go_url "$go_version" "$system")"
assertEquals "$want_url" "$got_url"
}

run_test linux/amd64 1.15.5 "https://storage.googleapis.com/golang/go1.15.5.linux-amd64.tar.gz"
run_test linux/386 1.15.5 "https://storage.googleapis.com/golang/go1.15.5.linux-386.tar.gz"
run_test linux/arm64 1.15.5 "https://storage.googleapis.com/golang/go1.15.5.linux-arm64.tar.gz"
run_test darwin/amd64 1.15.5 "https://storage.googleapis.com/golang/go1.15.5.darwin-amd64.tar.gz"
run_test darwin/arm64 1.15.5 "https://storage.googleapis.com/golang/go1.15.5.darwin-arm64.tar.gz"
run_test windows/amd64 1.15.5 "https://storage.googleapis.com/golang/go1.15.5.windows-amd64.zip"
run_test windows/386 1.15.5 "https://storage.googleapis.com/golang/go1.15.5.windows-386.zip"
run_test windows/arm64 1.15.5 "https://storage.googleapis.com/golang/go1.15.5.windows-arm64.zip"
}

test_is_precise_version() {
Expand Down Expand Up @@ -143,4 +148,22 @@ x;go1.15.7'
done
}

test_supported_system() {
assertTrue "linux/amd64" 'supported_system "linux/amd64"'
assertTrue "linux/386" 'supported_system "linux/386"'
assertTrue "linux/arm64" 'supported_system "linux/arm64"'
assertTrue "darwin/amd64" 'supported_system "darwin/amd64"'
assertTrue "darwin/arm64" 'supported_system "darwin/arm64"'
assertTrue "windows/amd64" 'supported_system "windows/amd64"'
assertTrue "windows/386" 'supported_system "windows/386"'
assertTrue "windows/arm64" 'supported_system "windows/arm64"'

assertFalse "linux/arm" 'supported_system "linux/arm"'
assertFalse "darwin/386" 'supported_system "darwin/386"'
assertFalse "asdf" 'supported_system "asdf"'
assertFalse "" 'supported_system ""'
assertFalse " " 'supported_system " "'

}

. ./external/shunit2
2 changes: 1 addition & 1 deletion src/lib_test_long.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test_install_go() {
version="1.15.4"
install_go "$version" "$target"
got_version="$("$target/bin/go" version)"
assertEquals "go version go1.15.4 $(goos)/amd64" "$got_version"
assertEquals "go version go1.15.4 $(go_system)" "$got_version"
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/semver-select
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ download() {
skip_download && return
mkdir -p "$(dirname "$bin_path")"
url="https://github.com/WillAbides/semver-select/releases/download/v"
url+="$target_version/semver-select_${target_version}_$(goos)_amd64"
url+="$target_version/semver-select_${target_version}_$(goos)_$(goarch)"
[ "$(goos)" = "windows" ] && url+=".exe"
curl -s --fail -o "$bin_path" --retry 4 -L "$url"
chmod +x "$bin_path"
Expand Down