Skip to content

Commit

Permalink
Simplify go version maintenance
Browse files Browse the repository at this point in the history
Now that the minimum go version is defined in go.mod, source the
version from there for everywhere that needs it rather than
hard-coding. This is intended to simplify version changes.
  • Loading branch information
marun committed May 1, 2024
1 parent f8d7b29 commit 2339866
Show file tree
Hide file tree
Showing 22 changed files with 106 additions and 108 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/build-linux-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ on:
tags:
- "*"

env:
go_version: '~1.21.9'

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

steps:
- uses: actions/checkout@v4

- run: .github/workflows/go_version_env.sh >> $GITHUB_ENV

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

- run: go version
Expand Down Expand Up @@ -82,9 +81,11 @@ jobs:
steps:
- uses: actions/checkout@v4

- run: .github/workflows/go_version_env.sh >> $GITHUB_ENV

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

- run: go version
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/build-macos-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ jobs:
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
- run: .github/workflows/go_version_env.sh >> $GITHUB_ENV
- uses: actions/setup-go@v5
with:
go-version: '~1.21.9'
go-version: '${{ env.GO_VERSION }}'
check-latest: true
- run: go version

Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/build-public-ami.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ jobs:

steps:
- uses: actions/checkout@v4
- run: .github/workflows/go_version_env.sh >> $GITHUB_ENV
- uses: actions/setup-go@v5
with:
go-version: '~1.21.9'
go-version: '${{ env.GO_VERSION }}'
check-latest: true
- run: go version

Expand Down Expand Up @@ -62,7 +63,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
9 changes: 4 additions & 5 deletions .github/workflows/build-ubuntu-amd64-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@ on:
tags:
- "*"

env:
go_version: '~1.21.9'

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

steps:
- uses: actions/checkout@v4
- run: .github/workflows/go_version_env.sh >> $GITHUB_ENV
- uses: actions/setup-go@v5
with:
go-version: ${{ env.go_version }}
go-version: ${{ env.GO_VERSION }}
check-latest: true
- run: go version

Expand Down Expand Up @@ -79,9 +77,10 @@ jobs:

steps:
- uses: actions/checkout@v4
- run: .github/workflows/go_version_env.sh >> $GITHUB_ENV
- uses: actions/setup-go@v5
with:
go-version: ${{ env.go_version }}
go-version: ${{ env.GO_VERSION }}
check-latest: true
- run: go version

Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/build-ubuntu-arm64-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@ 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
- run: .github/workflows/go_version_env.sh >> $GITHUB_ENV
- uses: actions/setup-go@v3
with:
go-version: ${{ env.go_version }}
go-version: ${{ env.GO_VERSION }}
check-latest: true
- run: go version

Expand Down Expand Up @@ -79,9 +77,10 @@ jobs:

steps:
- uses: actions/checkout@v4
- run: .github/workflows/go_version_env.sh >> $GITHUB_ENV
- uses: actions/setup-go@v3
with:
go-version: ${{ env.go_version }}
go-version: ${{ env.GO_VERSION }}
check-latest: true
- run: go version

Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/build-win-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4

- run: .github/workflows/go_version_env.sh >> $GITHUB_ENV

- uses: actions/setup-go@v5
with:
go-version: '~1.21.9'
go-version: '${{ env.GO_VERSION }}'
check-latest: true

- run: go version
Expand Down
32 changes: 21 additions & 11 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,9 +31,10 @@ 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
- run: .github/workflows/go_version_env.sh >> $GITHUB_ENV
- uses: actions/setup-go@v3
with:
go-version: ${{ env.go_version }}
go-version: '${{ env.GO_VERSION }}'
check-latest: true
- name: Set timeout on Windows # Windows UT run slower and need a longer timeout
shell: bash
Expand All @@ -49,9 +49,10 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- run: .github/workflows/go_version_env.sh >> $GITHUB_ENV
- uses: actions/setup-go@v5
with:
go-version: ${{ env.go_version }}
go-version: ${{ env.GO_VERSION }}
check-latest: true
- name: fuzz_test
shell: bash
Expand All @@ -60,9 +61,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: .github/workflows/go_version_env.sh >> $GITHUB_ENV
- uses: actions/setup-go@v5
with:
go-version: ${{ env.go_version }}
go-version: ${{ env.GO_VERSION }}
check-latest: true
- name: Build AvalancheGo Binary
shell: bash
Expand Down Expand Up @@ -114,9 +116,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: .github/workflows/go_version_env.sh >> $GITHUB_ENV
- uses: actions/setup-go@v5
with:
go-version: ${{ env.go_version }}
go-version: ${{ env.GO_VERSION }}
check-latest: true
- name: Build AvalancheGo Binary
shell: bash
Expand Down Expand Up @@ -167,9 +170,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: .github/workflows/go_version_env.sh >> $GITHUB_ENV
- uses: actions/setup-go@v5
with:
go-version: ${{ env.go_version }}
go-version: ${{ env.GO_VERSION }}
check-latest: true
- name: Build AvalancheGo Binary
shell: bash
Expand Down Expand Up @@ -220,9 +224,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: .github/workflows/go_version_env.sh >> $GITHUB_ENV
- uses: actions/setup-go@v5
with:
go-version: ${{ env.go_version }}
go-version: ${{ env.GO_VERSION }}
check-latest: true
- name: Run static analysis tests
shell: bash
Expand All @@ -246,9 +251,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: .github/workflows/go_version_env.sh >> $GITHUB_ENV
- uses: actions/setup-go@v5
with:
go-version: ${{ env.go_version }}
go-version: ${{ env.GO_VERSION }}
check-latest: true
- uses: bufbuild/buf-setup-action@v1.31.0
- shell: bash
Expand All @@ -260,9 +266,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: .github/workflows/go_version_env.sh >> $GITHUB_ENV
- uses: actions/setup-go@v5
with:
go-version: ${{ env.go_version }}
go-version: ${{ env.GO_VERSION }}
check-latest: true
- shell: bash
run: scripts/mock.gen.sh
Expand All @@ -273,9 +280,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: .github/workflows/go_version_env.sh >> $GITHUB_ENV
- uses: actions/setup-go@v5
with:
go-version: ${{ env.go_version }}
go-version: ${{ env.GO_VERSION }}
check-latest: true
- shell: bash
run: go mod tidy
Expand All @@ -297,7 +305,9 @@ jobs:
runs-on: ubuntu-latest
name: govulncheck
steps:
- uses: actions/checkout@v4
- run: .github/workflows/go_version_env.sh >> $GITHUB_ENV
- id: govulncheck
uses: golang/govulncheck-action@v1
with:
go-version-input: ${{ env.go_version }}
go-version-input: ${{ env.GO_VERSION }}
5 changes: 4 additions & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Get Go version from project
run: .github/workflows/go_version_env.sh >> $GITHUB_ENV

- name: Setup Golang
uses: actions/setup-go@v5
with:
go-version: '~1.21.9'
go-version: '${{ env.GO_VERSION }}'
check-latest: true

# Initializes the CodeQL tools for scanning.
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/fuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ jobs:
uses: actions/checkout@v4
with:
ref: 'dev'
- name: Get Go version from project
run: .github/workflows/go_version_env.sh >> $GITHUB_ENV
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '~1.21.9'
go-version: '${{ env.GO_VERSION }}'
check-latest: true
- name: Run fuzz tests
shell: bash
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/fuzz_merkledb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ jobs:
uses: actions/checkout@v4
with:
ref: 'dev'
- name: Get Go version from project
run: .github/workflows/go_version_env.sh >> $GITHUB_ENV
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '~1.21.9'
go-version: '${{ env.GO_VERSION }}'
check-latest: true
- name: Run merkledb fuzz tests
shell: bash
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/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.

# 2 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)"
15 changes: 11 additions & 4 deletions .github/workflows/publish_antithesis_images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
branches:
- master

env:
env:
REGISTRY: us-central1-docker.pkg.dev
REPOSITORY: molten-verve-216720/avalanche-repository
NODE_NAME: avalanche-node
Expand All @@ -28,18 +28,25 @@ jobs:
registry: ${{ env.REGISTRY }}
username: _json_key
password: ${{ secrets.ANTITHESIS_GAR_JSON_KEY }}


- name: Get Go version from project
run: .github/workflows/go_version_env.sh >> $GITHUB_ENV

- name: Build node
id: build-node-image
run: |
docker build -t $REGISTRY/$REPOSITORY/$NODE_NAME:$TAG -f ./tests/antithesis/Dockerfile.node .
docker build --build-arg GO_VERSION=${GO_VERSION} -t $REGISTRY/$REPOSITORY/$NODE_NAME:$TAG -f ./tests/antithesis/Dockerfile.node .
echo "name=image::$REGISTRY/$REPOSITORY/$NODE_NAME:$TAG" >> $GITHUB_OUTPUT
env:
GO_VERSION: '${{ env.GO_VERSION }}'

- name: Build workload
id: build-workload-image
run: |
docker build -t $REGISTRY/$REPOSITORY/$WORKLOAD_NAME:$TAG -f ./tests/antithesis/Dockerfile.workload .
docker build --build-arg GO_VERSION=${GO_VERSION} -t $REGISTRY/$REPOSITORY/$WORKLOAD_NAME:$TAG -f ./tests/antithesis/Dockerfile.workload .
echo "name=image::$REGISTRY/$REPOSITORY/$WORKLOAD_NAME:$TAG" >> $GITHUB_OUTPUT
env:
GO_VERSION: '${{ env.GO_VERSION }}'

- name: Build config
id: build-config-image
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

To start developing on AvalancheGo, you'll need a few things installed.

- Golang version >= 1.21.9
- Golang version >= the version defined in go.mod
- gcc
- g++

Expand Down
12 changes: 5 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Changes to the minimum golang version must also be replicated in
# tests/antithesis/Dockerfile.node
# tests/antithesis/Dockerfile.workload
# Dockerfile (here)
# README.md
# go.mod
# The version is supplied as a build argument rather than hard-coded
# to minimize the cost of version changes.
ARG GO_VERSION

# ============= Compilation Stage ================
# Always use the native platform to ensure fast builds
FROM --platform=$BUILDPLATFORM golang:1.21.9-bullseye AS builder
FROM --platform=$BUILDPLATFORM golang:$GO_VERSION-bullseye AS builder

WORKDIR /build

Expand Down
Loading

0 comments on commit 2339866

Please sign in to comment.