diff --git a/.github/actions/setup-go-tip/action.yml b/.github/actions/setup-go-tip/action.yml index 192fb4ac717..f67ac6a58b7 100644 --- a/.github/actions/setup-go-tip/action.yml +++ b/.github/actions/setup-go-tip/action.yml @@ -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" @@ -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) + + - 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