Skip to content

Commit

Permalink
Simplify go version maintenance (#2977)
Browse files Browse the repository at this point in the history
  • Loading branch information
marun authored May 3, 2024
1 parent bc4d747 commit 1b2f3d9
Show file tree
Hide file tree
Showing 24 changed files with 141 additions and 166 deletions.
16 changes: 16 additions & 0 deletions .github/actions/set-go-version-in-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This action sets GO_VERSION from the project's go.mod.
#
# Must be run after actions/checkout to ensure go.mod is available to
# source the project's go version from.

name: 'Set GO_VERSION env var from go.mod'
description: 'Read the go version from go.mod and add it as env var GO_VERSION in the github env'

runs:
using: composite
steps:
- name: Set the project Go version in the environment
# A script works across different platforms but attempting to replicate the script directly in
# the run statement runs into platform-specific path handling issues.
run: .github/actions/set-go-version-in-env/go_version_env.sh >> $GITHUB_ENV
shell: bash
14 changes: 14 additions & 0 deletions .github/actions/set-go-version-in-env/go_version_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -euo pipefail

# Prints the go version defined in the repo's go.mod. This is useful
# for configuring the correct version of go to install in CI.
#
# `go list -m -f '{{.GoVersion}}'` should be preferred outside of CI
# when go is already installed.

# 3 directories above this script
AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd ../../.. && pwd )

echo GO_VERSION="~$(sed -n -e 's/^go //p' "${AVALANCHE_PATH}"/go.mod)"
24 changes: 24 additions & 0 deletions .github/actions/setup-go-for-project-v3/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This action targets setup-go@v3 to support workers with old NodeJS
# incompabible with newer versions of setup-go.
#
# Since github actions do not support dynamically configuring the
# versions in a uses statement (e.g. `actions/setup-go@${{ var }}`) it
# is necessary to define an action per version rather than one action
# that can be parameterized.
#
# Must be run after actions/checkout to ensure go.mod is available to
# source the project's go version from.

name: 'Install Go toolchain with project defaults'
description: 'Install a go toolchain with project defaults'

runs:
using: composite
steps:
- name: Set the project Go version in the environment
uses: ./.github/actions/set-go-version-in-env
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '${{ env.GO_VERSION }}'
check-latest: true
25 changes: 25 additions & 0 deletions .github/actions/setup-go-for-project/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This action targets the project default version of setup-go. For
# workers with old NodeJS incompabible with newer versions of
# setup-go, try setup-go-for-project-v3.
#
# Since github actions do not support dynamically configuring the
# versions in a uses statement (e.g. `actions/setup-go@${{ var }}`) it
# is necessary to define an action per version rather than one action
# that can be parameterized.
#
# Must be run after actions/checkout to ensure go.mod is available to
# source the project's go version from.

name: 'Install Go toolchain with project defaults'
description: 'Install a go toolchain with project defaults'

runs:
using: composite
steps:
- name: Set the project Go version in the environment
uses: ./.github/actions/set-go-version-in-env
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '${{ env.GO_VERSION }}'
check-latest: true
13 changes: 2 additions & 11 deletions .github/workflows/build-linux-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,14 @@ on:
tags:
- "*"

env:
go_version: '~1.21.9'

jobs:
build-x86_64-binaries-tarball:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: ${{ env.go_version }}
check-latest: true
- uses: ./.github/actions/setup-go-for-project

- run: go version

Expand Down Expand Up @@ -82,10 +76,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v3
with:
go-version: ${{ env.go_version }}
check-latest: true
- uses: ./.github/actions/setup-go-for-project-v3

- run: go version

Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/build-macos-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ jobs:
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '~1.21.9'
check-latest: true
- uses: ./.github/actions/setup-go-for-project
- run: go version

# Runs a single command using the runners shell
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/build-public-ami.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '~1.21.9'
check-latest: true
- uses: ./.github/actions/setup-go-for-project
- run: go version

- name: Install aws cli
Expand Down Expand Up @@ -62,7 +59,7 @@ jobs:
id: setup
with:
version: ${{ env.PACKER_VERSION }}

- name: Run `packer init`
id: init
run: "packer init ./.github/packer/ubuntu-jammy-x86_64-public-ami.pkr.hcl"
Expand Down
13 changes: 2 additions & 11 deletions .github/workflows/build-ubuntu-amd64-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,13 @@ on:
tags:
- "*"

env:
go_version: '~1.21.9'

jobs:
build-jammy-amd64-package:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.go_version }}
check-latest: true
- uses: ./.github/actions/setup-go-for-project
- run: go version

- name: Build the avalanchego binaries
Expand Down Expand Up @@ -79,10 +73,7 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.go_version }}
check-latest: true
- uses: ./.github/actions/setup-go-for-project
- run: go version

- name: Build the avalanchego binaries
Expand Down
13 changes: 2 additions & 11 deletions .github/workflows/build-ubuntu-arm64-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,13 @@ on:
tags:
- "*"

env:
go_version: '~1.21.9'

jobs:
build-jammy-arm64-package:
runs-on: [self-hosted, linux, ARM64, jammy]

steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v3
with:
go-version: ${{ env.go_version }}
check-latest: true
- uses: ./.github/actions/setup-go-for-project-v3
- run: go version

- name: Build the avalanchego binaries
Expand Down Expand Up @@ -79,10 +73,7 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v3
with:
go-version: ${{ env.go_version }}
check-latest: true
- uses: ./.github/actions/setup-go-for-project-v3
- run: go version

- name: Build the avalanchego binaries
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/build-win-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: '~1.21.9'
check-latest: true
- uses: ./.github/actions/setup-go-for-project

- run: go version

Expand Down
50 changes: 12 additions & 38 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ concurrency:
cancel-in-progress: true

env:
go_version: '~1.21.9'
grafana_url: https://grafana-experimental.avax-dev.network/d/kBQpRdWnk/avalanche-main-dashboard?orgId=1&refresh=10s&var-filter=is_ephemeral_node%7C%3D%7Cfalse&var-filter=gh_repo%7C%3D%7Cava-labs%2Favalanchego&var-filter=gh_run_id%7C%3D%7C${{ github.run_id }}&var-filter=gh_run_attempt%7C%3D%7C${{ github.run_attempt }}

jobs:
Expand All @@ -32,10 +31,7 @@ jobs:
os: [macos-12, ubuntu-20.04, ubuntu-22.04, windows-2022, [self-hosted, linux, ARM64, focal], [self-hosted, linux, ARM64, jammy]]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v3
with:
go-version: ${{ env.go_version }}
check-latest: true
- uses: ./.github/actions/setup-go-for-project-v3
- name: Set timeout on Windows # Windows UT run slower and need a longer timeout
shell: bash
if: matrix.os == 'windows-2022'
Expand All @@ -49,21 +45,15 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.go_version }}
check-latest: true
- uses: ./.github/actions/setup-go-for-project
- name: fuzz_test
shell: bash
run: ./scripts/build_fuzz.sh 10 # Run each fuzz test 10 seconds
e2e:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.go_version }}
check-latest: true
- uses: ./.github/actions/setup-go-for-project
- name: Build AvalancheGo Binary
shell: bash
run: ./scripts/build.sh -r
Expand Down Expand Up @@ -114,10 +104,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.go_version }}
check-latest: true
- uses: ./.github/actions/setup-go-for-project
- name: Build AvalancheGo Binary
shell: bash
run: ./scripts/build.sh -r
Expand Down Expand Up @@ -167,10 +154,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.go_version }}
check-latest: true
- uses: ./.github/actions/setup-go-for-project
- name: Build AvalancheGo Binary
shell: bash
run: ./scripts/build.sh
Expand Down Expand Up @@ -220,10 +204,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.go_version }}
check-latest: true
- uses: ./.github/actions/setup-go-for-project
- name: Run static analysis tests
shell: bash
run: scripts/lint.sh
Expand All @@ -246,10 +227,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.go_version }}
check-latest: true
- uses: ./.github/actions/setup-go-for-project
- uses: bufbuild/buf-setup-action@v1.31.0
- shell: bash
run: scripts/protobuf_codegen.sh
Expand All @@ -260,10 +238,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.go_version }}
check-latest: true
- uses: ./.github/actions/setup-go-for-project
- shell: bash
run: scripts/mock.gen.sh
- shell: bash
Expand All @@ -273,10 +248,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.go_version }}
check-latest: true
- uses: ./.github/actions/setup-go-for-project
- shell: bash
run: go mod tidy
- shell: bash
Expand All @@ -297,7 +269,9 @@ jobs:
runs-on: ubuntu-latest
name: govulncheck
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/set-go-version-in-env
- id: govulncheck
uses: golang/govulncheck-action@v1
with:
go-version-input: ${{ env.go_version }}
go-version-input: ${{ env.GO_VERSION }}
5 changes: 1 addition & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup Golang
uses: actions/setup-go@v5
with:
go-version: '~1.21.9'
check-latest: true
uses: ./.github/actions/setup-go-for-project

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/fuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ jobs:
with:
ref: 'dev'
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '~1.21.9'
check-latest: true
uses: ./.github/actions/setup-go-for-project
- name: Run fuzz tests
shell: bash
run: ./scripts/build_fuzz.sh 180 # Run each fuzz test 180 seconds
5 changes: 1 addition & 4 deletions .github/workflows/fuzz_merkledb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ jobs:
with:
ref: 'dev'
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '~1.21.9'
check-latest: true
uses: ./.github/actions/setup-go-for-project
- name: Run merkledb fuzz tests
shell: bash
run: ./scripts/build_fuzz.sh 900 ./x/merkledb # Run each merkledb fuzz tests 15 minutes
Loading

0 comments on commit 1b2f3d9

Please sign in to comment.