Skip to content

Commit cc733ab

Browse files
authored
ci: check go versions are consistent (coder#17149)
Fixes coder#17063 I'm ignoring flake.nix for now. ``` $ IGNORE_NIX=true ./scripts/check_go_versions.sh INFO : go.mod : 1.24.1 INFO : dogfood/coder/Dockerfile : 1.24.1 INFO : setup-go/action.yaml : 1.24.1 INFO : flake.nix : 1.22 INFO : Ignoring flake.nix, as IGNORE_NIX=true Go version check passed, all versions are 1.24.1 $ ./scripts/check_go_versions.sh INFO : go.mod : 1.24.1 INFO : dogfood/coder/Dockerfile : 1.24.1 INFO : setup-go/action.yaml : 1.24.1 INFO : flake.nix : 1.22 ERROR: Go version mismatch between go.mod and flake.nix ```
1 parent 989c3ec commit cc733ab

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ jobs:
299299
- name: Setup Node
300300
uses: ./.github/actions/setup-node
301301

302+
- name: Check Go version
303+
run: IGNORE_NIX=true ./scripts/check_go_versions.sh
304+
302305
# Use default Go version
303306
- name: Setup Go
304307
uses: ./.github/actions/setup-go

scripts/check_go_versions.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bash
2+
3+
# This script ensures that the same version of Go is referenced in all of the
4+
# following files:
5+
# - go.mod
6+
# - dogfood/coder/Dockerfile
7+
# - flake.nix
8+
# - .github/actions/setup-go/action.yml
9+
# The version of Go in go.mod is considered the source of truth.
10+
11+
set -euo pipefail
12+
# shellcheck source=scripts/lib.sh
13+
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
14+
cdroot
15+
16+
# At the time of writing, Nix only has go 1.22.x.
17+
# We don't want to fail the build for this reason.
18+
IGNORE_NIX=${IGNORE_NIX:-false}
19+
20+
GO_VERSION_GO_MOD=$(grep -Eo 'go [0-9]+\.[0-9]+\.[0-9]+' ./go.mod | cut -d' ' -f2)
21+
GO_VERSION_DOCKERFILE=$(grep -Eo 'ARG GO_VERSION=[0-9]+\.[0-9]+\.[0-9]+' ./dogfood/coder/Dockerfile | cut -d'=' -f2)
22+
GO_VERSION_SETUP_GO=$(yq '.inputs.version.default' .github/actions/setup-go/action.yaml)
23+
GO_VERSION_FLAKE_NIX=$(grep -Eo '\bgo_[0-9]+_[0-9]+\b' ./flake.nix)
24+
# Convert to major.minor format.
25+
GO_VERSION_FLAKE_NIX_MAJOR_MINOR=$(echo "$GO_VERSION_FLAKE_NIX" | cut -d '_' -f 2-3 | tr '_' '.')
26+
log "INFO : go.mod : $GO_VERSION_GO_MOD"
27+
log "INFO : dogfood/coder/Dockerfile : $GO_VERSION_DOCKERFILE"
28+
log "INFO : setup-go/action.yaml : $GO_VERSION_SETUP_GO"
29+
log "INFO : flake.nix : $GO_VERSION_FLAKE_NIX_MAJOR_MINOR"
30+
31+
if [ "$GO_VERSION_GO_MOD" != "$GO_VERSION_DOCKERFILE" ]; then
32+
error "Go version mismatch between go.mod and dogfood/coder/Dockerfile:"
33+
fi
34+
35+
if [ "$GO_VERSION_GO_MOD" != "$GO_VERSION_SETUP_GO" ]; then
36+
error "Go version mismatch between go.mod and .github/actions/setup-go/action.yaml"
37+
fi
38+
39+
# At the time of writing, Nix only constrains the major.minor version.
40+
# We need to check that specifically.
41+
if [ "$IGNORE_NIX" = "false" ]; then
42+
GO_VERSION_GO_MOD_MAJOR_MINOR=$(echo "$GO_VERSION_GO_MOD" | cut -d '.' -f 1-2)
43+
if [ "$GO_VERSION_FLAKE_NIX_MAJOR_MINOR" != "$GO_VERSION_GO_MOD_MAJOR_MINOR" ]; then
44+
error "Go version mismatch between go.mod and flake.nix"
45+
fi
46+
else
47+
log "INFO : Ignoring flake.nix, as IGNORE_NIX=${IGNORE_NIX}"
48+
fi
49+
50+
log "Go version check passed, all versions are $GO_VERSION_GO_MOD"

0 commit comments

Comments
 (0)