Skip to content
79 changes: 49 additions & 30 deletions .github/actions/setup-go-tip/action.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,70 @@
# Inspired by https://github.com/actions/setup-go/issues/21#issuecomment-997208686
name: 'Install Go Tip'
description: 'Install Go Tip toolchain'
inputs:
gh_token:
description: 'The GitHub Token'
required: true
runs:
using: "composite"
steps:
- 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=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"
if curl -fsSL -o gotip.tar.gz "$url"; then
success=true
break
fi
echo "Failed to download. Retrying in $wait_time seconds..."
sleep $wait_time
done
echo "success=${success}" >> $GITHUB_OUTPUT
# - name: Download Go Tip
# id: download
# shell: bash
# run: |
# set -euo pipefail
# tip=$(git ls-remote https://github.com/golang/go.git refs/heads/master | awk '{print $1;}')
# echo "Go Tip version: ${tip}"
# 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"
# if curl -fsSL -o gotip.tar.gz "$url"; then
# success=true
# break
# fi
# echo "Failed to download. Retrying in $wait_time seconds..."
# sleep $wait_time
# done
# echo "success=${success}" >> $GITHUB_OUTPUT

- name: Unpack gotip bundle
if: steps.download.outputs.success == 'true'
# - 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"
# mkdir -p $GOROOT
# tar -C $GOROOT -xzf gotip.tar.gz
# echo "GOROOT=$GOROOT" >> $GITHUB_ENV

- name: Download pre-built Go tip from grafana/gotip repo
id: download
shell: bash
run: |
echo Unpack gotip bundle
set -euo pipefail
echo "Downloaded bundle:"
ls -lah gotip.tar.gz
gh release download ubuntu-latest --repo grafana/gotip --pattern 'go*.zip'
unzip go.zip -d $HOME/sdk
export GOROOT="$HOME/sdk/gotip"
mkdir -p $GOROOT
tar -C $GOROOT -xzf gotip.tar.gz
echo "GOROOT=$GOROOT" >> $GITHUB_ENV
# echo "GOPATH=$HOME/go" >> "$GITHUB_ENV"
# echo "$HOME/go/bin" >> "$GITHUB_PATH"
# echo "$HOME/sdk/gotip/bin" >> "$GITHUB_PATH"
echo "success=${success}" >> $GITHUB_OUTPUT
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The success variable is referenced in echo "success=${success}" >> $GITHUB_OUTPUT but isn't defined anywhere in this implementation. This will cause the script to output an empty or undefined value. Consider adding logic to set this variable based on the outcome of the download and unzip operations, such as:

success=false
if gh release download ubuntu-latest --repo grafana/gotip --pattern 'go*.zip' && 
   unzip go.zip -d $HOME/sdk; then
  success=true
fi

This ensures the downstream conditional steps have accurate information about whether the download succeeded.

Suggested change
echo "success=${success}" >> $GITHUB_OUTPUT
success=false
if gh release download ubuntu-latest --repo grafana/gotip --pattern 'go*.zip' && unzip go.zip -d $HOME/sdk; then
success=true
fi
echo "success=${success}" >> $GITHUB_OUTPUT

Spotted by Diamond

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

env:
GH_TOKEN: ${{ inputs.gh_token }}

# If download failed, we will try to build tip from source.
# This requires Go toolchain, so install it first.
- name: Determine latest Go version
if: steps.download.outputs.success == 'false'
id: get_go_version
shell: bash
run: |
LATEST_GO_VERSION=$(curl -s "https://go.dev/VERSION?m=text")
LATEST_GO_VERSION=$(curl -s "https://go.dev/VERSION?m=text" | grep go1 | sed 's/^go//g')
echo "LATEST_GO_VERSION=$LATEST_GO_VERSION" >> $GITHUB_OUTPUT

- name: Install Go toolchain
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/ci-unit-tests-go-tip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ on:
push:
branches: [main]

# We normally don't want this workflow to run on PRs, only on main branch.
# But to allow testing of this workflow itself, add `run-all-workflows` label.
pull_request:
branches: [main]

permissions:
contents: read

jobs:
unit-tests-go-tip:
if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-all-workflows')
permissions:
checks: write
runs-on: ubuntu-latest
Expand All @@ -23,6 +29,8 @@ jobs:

- name: Install Go Tip
uses: ./.github/actions/setup-go-tip
with:
gh_token: ${{ secrets.GITHUB_TOKEN }}

- name: Install test deps
# even though the same target runs from test-ci, running it separately makes for cleaner log in GH workflow
Expand Down
Loading