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

Add alternate way to install gotip #5618

Merged
merged 12 commits into from
Jun 15, 2024
62 changes: 53 additions & 9 deletions .github/actions/setup-go-tip/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ description: 'Install Go Tip toolchain'
runs:
using: "composite"
steps:
- name: Install Go Tip
- name: Download Go Tip
id: download
shell: bash
run: |
echo Download Go Tip
set -euo pipefail
tip=$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}')
echo "Go Tip version: ${tip}"
retries=10
wait_time=30
retries=3
wait_time=10
success=false
for ((i=1; i<=retries; i++)); do
url="https://storage.googleapis.com/go-build-snap/go/linux-amd64/${tip}.tar.gz"
Expand All @@ -22,20 +24,62 @@ runs:
echo "Failed to download. Retrying in $wait_time seconds..."
sleep $wait_time
done
echo "success=${success}" >> $GITHUB_OUTPUT

if [[ "$success" == false ]]; then
echo "Failed to download Go Tip after $retries attempts"
exit 1
fi
- name: Unpack gotip bundle
if: steps.download.outputs.success == 'true'
shell: bash
run: |
echo Unpack gotip bundle
set -euo pipefail
echo "Downloaded bundle:"
ls -lah gotip.tar.gz
export GOROOT="$HOME/sdk/gotip"
export GOPATH="$HOME/go"
mkdir -p $GOROOT
tar -C $GOROOT -xzf gotip.tar.gz
export PATH="$GOROOT/bin/:$GOPATH/bin:$PATH"
echo "GOROOT=$GOROOT" >> $GITHUB_ENV

# If download failed, we will try to build tip from source.
# This requires Go toolchain, so install it first.
- name: Install Go toolchain
if: steps.download.outputs.success == 'false'
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: 1.22.x

- name: Build Go Tip from source
if: steps.download.outputs.success == 'false'
shell: bash
run: |
echo Build Go Tip from source
set -euo pipefail
go install golang.org/dl/gotip@latest
gotip download
export GOROOT="$(gotip env GOROOT)"
echo "GOROOT=$GOROOT" >> $GITHUB_ENV
# for some reason even though we put gotip at the front of PATH later,
# the go binary installed in previous step still takes precedence. So remove it.
rm -f $(which go)

EraKin575 marked this conversation as resolved.
Show resolved Hide resolved
- name: Setup Go environment
shell: bash
run: |
echo Setup Go environment
set -euo pipefail
$GOROOT/bin/go version
GOPATH="$HOME/gotip"
PATH="$GOROOT/bin:$GOPATH/bin:$PATH"
echo "GOPATH=$GOPATH" >> $GITHUB_ENV
echo "PATH=$PATH" >> $GITHUB_ENV

- name: Check Go Version
shell: bash
run: |
echo Check Go Version
set -euo pipefail
echo "GOPATH=$GOPATH"
echo "GOROOT=$GOROOT"
echo "which go:"
which -a go
echo "Active Go version:"
go version