DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 970,177 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
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.

Latest comments (0)

πŸ‘‹ Hey, my name is Noah and I’m the one who set up this ad. My job is to get you to join DEV, so if you fancy doing me a favor, I’d love for you to create an account.

If you found DEV from searching around, here are a couple of our most popular articles on DEV: