forked from cadence-workflow/cadence
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adopt Go toolchains for language-version-control (cadence-workflow#6063)
Go 1.21 brought us "toolchains": We can now describe the version we want, and the Go CLI will automagically download, install, and use that version, with no extra effort. It should give us a MUCH more reliable way to ensure identical builds and formats and whatnot, and all us devs will auto-switch as we jump between git SHAs. So let's use that! This does a few things: - requires Go 1.21+ to be your `go` version to *work on* Cadence. - this does not force our *users* to use 1.21+, that's still 1.20, controlled by the `go 1.20` lines. just development in this workspace. - sets a `go.work` toolchain (if there's a `go.work` file, toolchains in individual `go.mod` files are ignored) - not all IDEs follow this. we could set it + lint it in the `go.mod` files too if it helps, it just won't have any effect on CLI `go` use so it may be misleading. - exports `GOTOOLCHAIN=...` inside the Makefile, so ALL makefile-driven builds by everyone use exactly the same version (you can override this with an explicit `GOTOOLCHAIN`) - updates our dockerfiles (it would just download [wrong version in docker image] and then auto-download the right one, which is a waste of time) - adds a lint script to ensure ^ all that stays up to date --- For future upgrades, upgrading the toolchain should be very simple: - change `go.work` to a new toolchain version - everything now uses the new language version, tools and binaries will rebuild, etc. - `make lint` or `make pr` or CI will tell you to change the Dockerfiles / other locations, if you don't `git grep -F 1.22.3` to find and update those first. And temporarily trying a different version to check a bug / performance / try the new version is: - `GOTOOLCHAIN=go1.23.4 make whatever` and it'll do exactly that (except for the version check in `make lint`) - you may want to `make clean` as well, to rebuild tools if that's relevant - they will not automatically rebuild with this env var changing. they *could*, if we used `.build/go1.23.4/etc` folders, if we want that.
- Loading branch information
Showing
6 changed files
with
90 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eo pipefail | ||
|
||
# enable double-star | ||
shopt -s globstar | ||
|
||
fail=0 | ||
bad() { | ||
echo -e "$@" >/dev/stderr | ||
fail=1 | ||
} | ||
|
||
if [[ $V == 1 ]]; then | ||
set -x | ||
fi | ||
|
||
target="${1#go}" | ||
root="$(git rev-parse --show-toplevel)" | ||
|
||
# this SHOULD match the dependencies in the goversion-lint check to avoid skipping it | ||
|
||
# check dockerfiles | ||
for file in "$root"/**/Dockerfile; do | ||
# find "FROM golang:1.22.3-alpine3.18 ..." lines | ||
line="$(grep -i 'from golang:' "$file")" | ||
# remove "from golang:" prefix | ||
version="${line#*golang:}" | ||
# remove "-alpine..." suffix | ||
version="${version%-*}" | ||
# and make sure it matches | ||
if [[ "$version" != "$target" ]]; then | ||
bad "Wrong Go version in file $file:\n\t$line" | ||
fi | ||
done | ||
|
||
# check workflows | ||
codecov_file="$root/.github/workflows/codecov.yml" | ||
codecov_line="$(grep 'go-version:' "$codecov_file")" | ||
codecov_version="${codecov_line#*go-version: }" | ||
if [[ "$codecov_version" != "$target" ]]; then | ||
bad "Wrong Go version in file $codecov_file:\n\t$codecov_line" | ||
fi | ||
|
||
if [[ $fail == 1 ]]; then | ||
bad "Makefile pins Go to go${target}, Dockerfiles and GitHub workflows should too." | ||
bad "Non-matching versions lead to pointless double-downloading to get the correct version." | ||
exit 1 | ||
fi |