From 9a95a702acb2b0fe64d6024439858b4001f31382 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 28 Mar 2025 13:33:29 +0000 Subject: [PATCH 1/3] ci: check go versions are consistent --- .github/workflows/ci.yaml | 3 +++ scripts/check_go_versions.sh | 49 ++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100755 scripts/check_go_versions.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2ff0978e5d807..d7083dbcb2fc2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -299,6 +299,9 @@ jobs: - name: Setup Node uses: ./.github/actions/setup-node + - name: Check Go version + run: IGNORE_NIX=true ./scripts/check_go_versions.sh + # Use default Go version - name: Setup Go uses: ./.github/actions/setup-go diff --git a/scripts/check_go_versions.sh b/scripts/check_go_versions.sh new file mode 100755 index 0000000000000..792a731a4d51e --- /dev/null +++ b/scripts/check_go_versions.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +# This script ensures that the same version of Go is referenced in all of the +# following files: +# - go.mod +# - dogfood/coder/Dockerfile +# - flake.nix +# - .github/actions/setup-go/action.yml +# The version of Go in go.mod is considered the source of truth. + +set -euo pipefail +source "$(dirname "${BASH_SOURCE[0]}")/lib.sh" +cdroot + +# At the time of writing, Nix only has go 1.22.x. +# We don't want to fail the build for this reason. +IGNORE_NIX=${IGNORE_NIX:-false} + +GO_VERSION_GO_MOD=$(grep -Eo 'go [0-9]+\.[0-9]+\.[0-9]+' ./go.mod | cut -d' ' -f2) +GO_VERSION_DOCKERFILE=$(grep -Eo 'ARG GO_VERSION=[0-9]+\.[0-9]+\.[0-9]+' ./dogfood/coder/Dockerfile | cut -d'=' -f2) +GO_VERSION_SETUP_GO=$(yq '.inputs.version.default' .github/actions/setup-go/action.yaml) +GO_VERSION_FLAKE_NIX=$(grep -Eo '\bgo_[0-9]+_[0-9]+\b' ./flake.nix) +# Convert to major.minor format. +GO_VERSION_FLAKE_NIX_MAJOR_MINOR=$(echo "$GO_VERSION_FLAKE_NIX" | cut -d '_' -f 2-3 | tr '_' '.') +log "INFO : go.mod : $GO_VERSION_GO_MOD" +log "INFO : dogfood/coder/Dockerfile : $GO_VERSION_DOCKERFILE" +log "INFO : setup-go/action.yaml : $GO_VERSION_SETUP_GO" +log "INFO : flake.nix : $GO_VERSION_FLAKE_NIX_MAJOR_MINOR" + +if [ "$GO_VERSION_GO_MOD" != "$GO_VERSION_DOCKERFILE" ]; then + error "Go version mismatch between go.mod and dogfood/coder/Dockerfile:" +fi + +if [ "$GO_VERSION_GO_MOD" != "$GO_VERSION_SETUP_GO" ]; then + error "Go version mismatch between go.mod and .github/actions/setup-go/action.yaml" +fi + +# At the time of writing, Nix only constrains the major.minor version. +# We need to check that specifically. +if [ "$IGNORE_NIX" = "false" ]; then + GO_VERSION_GO_MOD_MAJOR_MINOR=$(echo "$GO_VERSION_GO_MOD" | cut -d '.' -f 1-2) + if [ "$GO_VERSION_FLAKE_NIX_MAJOR_MINOR" != "$GO_VERSION_GO_MOD_MAJOR_MINOR" ]; then + error "Go version mismatch between go.mod and flake.nix" + fi +else + log "INFO : Ignoring flake.nix, as IGNORE_NIX=${IGNORE_NIX}" +fi + +log "Go version check passed, all versions are $GO_VERSION_GO_MOD" From 9fe33eb5fd84ed3defa11adf0ea2da5c3be5f2eb Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 28 Mar 2025 13:37:11 +0000 Subject: [PATCH 2/3] shfumpt --- scripts/check_go_versions.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/check_go_versions.sh b/scripts/check_go_versions.sh index 792a731a4d51e..266b5963821a2 100755 --- a/scripts/check_go_versions.sh +++ b/scripts/check_go_versions.sh @@ -41,9 +41,9 @@ if [ "$IGNORE_NIX" = "false" ]; then GO_VERSION_GO_MOD_MAJOR_MINOR=$(echo "$GO_VERSION_GO_MOD" | cut -d '.' -f 1-2) if [ "$GO_VERSION_FLAKE_NIX_MAJOR_MINOR" != "$GO_VERSION_GO_MOD_MAJOR_MINOR" ]; then error "Go version mismatch between go.mod and flake.nix" - fi + fi else - log "INFO : Ignoring flake.nix, as IGNORE_NIX=${IGNORE_NIX}" + log "INFO : Ignoring flake.nix, as IGNORE_NIX=${IGNORE_NIX}" fi log "Go version check passed, all versions are $GO_VERSION_GO_MOD" From 519248df0d6b50dc6b47cd72c6b22a5f59b1e2b4 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 28 Mar 2025 14:01:15 +0000 Subject: [PATCH 3/3] appease linter --- scripts/check_go_versions.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/check_go_versions.sh b/scripts/check_go_versions.sh index 266b5963821a2..8349960bd580a 100755 --- a/scripts/check_go_versions.sh +++ b/scripts/check_go_versions.sh @@ -9,6 +9,7 @@ # The version of Go in go.mod is considered the source of truth. set -euo pipefail +# shellcheck source=scripts/lib.sh source "$(dirname "${BASH_SOURCE[0]}")/lib.sh" cdroot