DEV Community

Viacheslav Poturaev
Viacheslav Poturaev

Posted on

GitHub Actions with unstable Go

Upcoming Go 1.18 release brings very interesting new features (including generics and fuzz testing). Libraries can get prepared for the release by supporting and exploring new features in advance, this also helps gaining preliminary experience.

Standard GitHub Action actions/setup-go allows using pre-releases with stable: false flag.

Example:

jobs:
  test:
    strategy:
      matrix:
        go-version: [ 1.16.x, 1.17.x, 1.18.0-rc1 ]
    runs-on: ubuntu-latest
    steps:
      - name: Install Go
        uses: actions/setup-go@v2
        with:
          stable: false
          go-version: ${{ matrix.go-version }}
Enter fullscreen mode Exit fullscreen mode

In some cases you may want to run tests against gotip which is a head of development tree. Standard action does not support gotip, but it is easy to install it manually from build snapshots.

jobs:
  test:
    strategy:
      matrix:
        go-version: [ 1.16.x, 1.17.x, 1.18.0-rc1, tip ]
    runs-on: ubuntu-latest
    steps:
      - name: Install Go
        if: matrix.go-version != 'tip'
        uses: actions/setup-go@v2
        with:
          stable: false
          go-version: ${{ matrix.go-version }}
      - name: Install Go tip
        if: matrix.go-version == 'tip'
        run: |
          curl -sL https://storage.googleapis.com/go-build-snap/go/linux-amd64/$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}').tar.gz -o gotip.tar.gz
          ls -lah gotip.tar.gz
          mkdir -p ~/sdk/gotip
          tar -C ~/sdk/gotip -xzf gotip.tar.gz
          ~/sdk/gotip/bin/go version
          echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV
Enter fullscreen mode Exit fullscreen mode

The Install Go tip step here would download pre-built Go for a latest commit in master. There is a caveat though, for a very recent commit the build might be not finished by the time of download and this may result in CI failure. It does not happen very often and retry usually helps.

Top comments (0)