Files

28 lines
1.1 KiB
YAML

name: better-setup-go
description: Install a pinned Go toolchain from the official static tarball — musl-safe, no manifest fetches, Forgejo/act runner safe.
inputs:
go-version:
description: Exact Go version to install (e.g. 1.27.0).
required: true
runs:
using: composite
steps:
- shell: bash
run: |
set -euo pipefail
v="${{ inputs.go-version }}"
case "$(uname -m)" in
x86_64|amd64) arch=amd64 ;;
aarch64|arm64) arch=arm64 ;;
*) echo "better-setup-go: unsupported arch $(uname -m)" >&2; exit 1 ;;
esac
rm -rf /usr/local/go # a base-image GOROOT under the same path corrupts on overlay
# download-to-file with retries: a piped stream that truncates mid-archive leaves a
# half-extracted GOROOT that fails far away from its cause
curl --retry 3 --retry-delay 2 -fsSL -o /tmp/go.tgz "https://go.dev/dl/go${v}.linux-${arch}.tar.gz"
tar -xzf /tmp/go.tgz -C /usr/local
rm -f /tmp/go.tgz
ln -sf /usr/local/go/bin/go /usr/local/bin/go
ln -sf /usr/local/go/bin/gofmt /usr/local/bin/gofmt
go version