Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
maru-ava committed May 1, 2024
1 parent f8d7b29 commit 2339866
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
@@ -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
@@ -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
3 changes: 2 additions & 1 deletion .github/workflows/build-macos-release.yml
Original file line number Diff line number Diff line change
@@ -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

5 changes: 3 additions & 2 deletions .github/workflows/build-public-ami.yml
Original file line number Diff line number Diff line change
@@ -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

@@ -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"
9 changes: 4 additions & 5 deletions .github/workflows/build-ubuntu-amd64-release.yml
Original file line number Diff line number Diff line change
@@ -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

@@ -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

9 changes: 4 additions & 5 deletions .github/workflows/build-ubuntu-arm64-release.yml
Original file line number Diff line number Diff line change
@@ -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

@@ -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

4 changes: 3 additions & 1 deletion .github/workflows/build-win-release.yml
Original file line number Diff line number Diff line change
@@ -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
32 changes: 21 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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:
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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.
4 changes: 3 additions & 1 deletion .github/workflows/fuzz.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion .github/workflows/fuzz_merkledb.yml
Original file line number Diff line number Diff line change
@@ -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
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
@@ -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
@@ -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
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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++

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

9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ The minimum recommended hardware specification for nodes connected to Mainnet is

If you plan to build AvalancheGo from source, you will also need the following software:

- [Go](https://golang.org/doc/install) version >= 1.21.9
- [Go](https://golang.org/doc/install) - minimum required version is defined in go.mod
- [gcc](https://gcc.gnu.org/)
- g++

@@ -185,13 +185,6 @@ scripts/protobuf_codegen.sh

For more information, refer to the [GRPC Golang Quick Start Guide](https://grpc.io/docs/languages/go/quickstart/).

### Running protobuf codegen from docker

```sh
docker build -t avalanche:protobuf_codegen -f api/Dockerfile.buf .
docker run -t -i -v $(pwd):/opt/avalanche -w/opt/avalanche avalanche:protobuf_codegen bash -c "scripts/protobuf_codegen.sh"
```

### Running mock codegen

To regenerate the [gomock](https://github.com/uber-go/mock) code, run `scripts/mock.gen.sh` from the root of the repo.
7 changes: 1 addition & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
module github.com/ava-labs/avalanchego

// Changes to the minimum golang version must also be replicated in
// tests/antithesis/Dockerfile.node
// tests/antithesis/Dockerfile.workload
// Dockerfile
// README.md
// go.mod (here)
// The minimum golang version defined here will be reused for CI and image builds.
go 1.21.9

require (
22 changes: 0 additions & 22 deletions proto/Dockerfile.buf

This file was deleted.

5 changes: 2 additions & 3 deletions proto/README.md
Original file line number Diff line number Diff line change
@@ -10,8 +10,7 @@ Protobuf linting and generation for this project is managed by
[buf](https://github.com/bufbuild/buf).

Please find installation instructions on
[https://docs.buf.build/installation/](https://docs.buf.build/installation/) or
use `Dockerfile.buf` provided in the `proto/` directory of AvalancheGo.
[https://docs.buf.build/installation/](https://docs.buf.build/installation/).

Any changes made to proto definition can be updated by running
`protobuf_codegen.sh` located in the `scripts/` directory of AvalancheGo.
@@ -34,4 +33,4 @@ subnet vm must use the same protocol version to be compatible.
- Publish new tag to buf registry. `buf push -t v26`

Note: Publishing requires auth to the ava-labs org in buf
https://buf.build/ava-labs/repositories
https://buf.build/ava-labs/repositories
6 changes: 6 additions & 0 deletions scripts/build_image.sh
Original file line number Diff line number Diff line change
@@ -44,6 +44,12 @@ DOCKER_IMAGE=${DOCKER_IMAGE:-"avalanchego"}
# Reference: https://docs.docker.com/build/buildkit/
DOCKER_CMD="docker buildx build"

# The dockerfile doesn't specify the golang version to minimize the
# changes required to bump the version. Instead, the golang version is
# provided as an argument.
GO_VERSION="$(go list -m -f '{{.GoVersion}}')"
DOCKER_CMD="${DOCKER_CMD} --build-arg GO_VERSION=${GO_VERSION}"

if [[ "${DOCKER_IMAGE}" == *"/"* ]]; then
# Build a multi-arch image since the image name includes a slash which indicates
# the use of a registry e.g.
10 changes: 1 addition & 9 deletions scripts/protobuf_codegen.sh
Original file line number Diff line number Diff line change
@@ -7,19 +7,14 @@ if ! [[ "$0" =~ scripts/protobuf_codegen.sh ]]; then
exit 255
fi

## install "buf"
# any version changes here should also be bumped in Dockerfile.buf
# ref. https://docs.buf.build/installation
# ref. https://github.com/bufbuild/buf/releases
## ensure the correct version of "buf" is installed
BUF_VERSION='1.31.0'
if [[ $(buf --version | cut -f2 -d' ') != "${BUF_VERSION}" ]]; then
echo "could not find buf ${BUF_VERSION}, is it installed + in PATH?"
exit 255
fi

## install "protoc-gen-go"
# any version changes here should also be bumped in Dockerfile.buf
# ref. https://github.com/protocolbuffers/protobuf-go/releases
PROTOC_GEN_GO_VERSION='v1.33.0'
go install -v google.golang.org/protobuf/cmd/protoc-gen-go@${PROTOC_GEN_GO_VERSION}
if [[ $(protoc-gen-go --version | cut -f2 -d' ') != "${PROTOC_GEN_GO_VERSION}" ]]; then
@@ -29,9 +24,6 @@ if [[ $(protoc-gen-go --version | cut -f2 -d' ') != "${PROTOC_GEN_GO_VERSION}" ]
fi

### install "protoc-gen-go-grpc"
# any version changes here should also be bumped in Dockerfile.buf
# ref. https://pkg.go.dev/google.golang.org/grpc/cmd/protoc-gen-go-grpc
# ref. https://github.com/grpc/grpc-go/blob/master/cmd/protoc-gen-go-grpc/main.go
PROTOC_GEN_GO_GRPC_VERSION='1.3.0'
go install -v google.golang.org/grpc/cmd/protoc-gen-go-grpc@v${PROTOC_GEN_GO_GRPC_VERSION}
if [[ $(protoc-gen-go-grpc --version | cut -f2 -d' ') != "${PROTOC_GEN_GO_GRPC_VERSION}" ]]; then
14 changes: 6 additions & 8 deletions tests/antithesis/Dockerfile.node
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# The version is supplied as a build argument rather than hard-coded
# to minimize the cost of version changes.
ARG GO_VERSION

# Antithesis: Getting the Antithesis golang instrumentation library
FROM docker.io/antithesishq/go-instrumentor AS instrumentor

# Changes to the minimum golang version must also be replicated in
# tests/antithesis/Dockerfile.node (here)
# tests/antithesis/Dockerfile.workload
# Dockerfile
# README.md
# go.mod
# ============= Compilation Stage ================
FROM golang:1.21.9-bullseye AS builder
FROM golang:$GO_VERSION-bullseye AS builder

WORKDIR /build
# Copy and download avalanche dependencies using go mod
@@ -30,7 +28,7 @@ COPY --from=instrumentor /opt/antithesis/lib /lib
RUN mkdir -p /avalanchego_instrumented

# Park the .git file in a safe location
RUN mkdir -p /opt/tmp/
RUN mkdir -p /opt/tmp/
RUN cp -r .git /opt/tmp/

# Instrument avalanchego
12 changes: 5 additions & 7 deletions tests/antithesis/Dockerfile.workload
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Changes to the minimum golang version must also be replicated in
# tests/antithesis/Dockerfile.node
# tests/antithesis/Dockerfile.workload (here)
# Dockerfile
# 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 ================
FROM golang:1.21.9-bullseye AS builder
FROM golang:$GO_VERSION-bullseye AS builder

WORKDIR /build
# Copy and download avalanche dependencies using go mod

0 comments on commit 2339866

Please sign in to comment.