Skip to content

Commit 9a95a70

Browse files
committed
ci: check go versions are consistent
1 parent c679991 commit 9a95a70

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

.github/workflows/ci.yaml

+3
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

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
13+
cdroot
14+
15+
# At the time of writing, Nix only has go 1.22.x.
16+
# We don't want to fail the build for this reason.
17+
IGNORE_NIX=${IGNORE_NIX:-false}
18+
19+
GO_VERSION_GO_MOD=$(grep -Eo 'go [0-9]+\.[0-9]+\.[0-9]+' ./go.mod | cut -d' ' -f2)
20+
GO_VERSION_DOCKERFILE=$(grep -Eo 'ARG GO_VERSION=[0-9]+\.[0-9]+\.[0-9]+' ./dogfood/coder/Dockerfile | cut -d'=' -f2)
21+
GO_VERSION_SETUP_GO=$(yq '.inputs.version.default' .github/actions/setup-go/action.yaml)
22+
GO_VERSION_FLAKE_NIX=$(grep -Eo '\bgo_[0-9]+_[0-9]+\b' ./flake.nix)
23+
# Convert to major.minor format.
24+
GO_VERSION_FLAKE_NIX_MAJOR_MINOR=$(echo "$GO_VERSION_FLAKE_NIX" | cut -d '_' -f 2-3 | tr '_' '.')
25+
log "INFO : go.mod : $GO_VERSION_GO_MOD"
26+
log "INFO : dogfood/coder/Dockerfile : $GO_VERSION_DOCKERFILE"
27+
log "INFO : setup-go/action.yaml : $GO_VERSION_SETUP_GO"
28+
log "INFO : flake.nix : $GO_VERSION_FLAKE_NIX_MAJOR_MINOR"
29+
30+
if [ "$GO_VERSION_GO_MOD" != "$GO_VERSION_DOCKERFILE" ]; then
31+
error "Go version mismatch between go.mod and dogfood/coder/Dockerfile:"
32+
fi
33+
34+
if [ "$GO_VERSION_GO_MOD" != "$GO_VERSION_SETUP_GO" ]; then
35+
error "Go version mismatch between go.mod and .github/actions/setup-go/action.yaml"
36+
fi
37+
38+
# At the time of writing, Nix only constrains the major.minor version.
39+
# We need to check that specifically.
40+
if [ "$IGNORE_NIX" = "false" ]; then
41+
GO_VERSION_GO_MOD_MAJOR_MINOR=$(echo "$GO_VERSION_GO_MOD" | cut -d '.' -f 1-2)
42+
if [ "$GO_VERSION_FLAKE_NIX_MAJOR_MINOR" != "$GO_VERSION_GO_MOD_MAJOR_MINOR" ]; then
43+
error "Go version mismatch between go.mod and flake.nix"
44+
fi
45+
else
46+
log "INFO : Ignoring flake.nix, as IGNORE_NIX=${IGNORE_NIX}"
47+
fi
48+
49+
log "Go version check passed, all versions are $GO_VERSION_GO_MOD"

0 commit comments

Comments
 (0)