wormhole/scripts/update-go-version.sh

142 lines
4.8 KiB
Bash
Raw Normal View History

node: upgrade to go 1.21.9 (#3855) * node: update quic-go Ran via: go get github.com/quic-go/quic-go@v0.42.0 * node: update mongo-drive dependency Ran via: go get go.mongodb.org/mongo-driver@latest * node: upgrade libp2p-go Ran via: go get github.com/libp2p/go-libp2p@v0.33.1 Refs: #3863 * node: fallout from the go upgrade in the go.sum Run via: go mod tidy This updates the go.sum and removes unnecessary indirect references. * docs: use go1.21.8 * github: use go1.21.8 Except for wormchain. * node: update dockerfiles to use go 1.21.8 This was done with scripts/update-go-version.sh * scripts: update linter dockerfile to use go 1.21.8 This was done with scripts/update-go-version.sh * wormchain: update ibc-relayer to use go 1.21.8 This was done with scripts/update-go-version.sh * scripts: add update-go-version.sh This is a little helper to make updating the version of go a bit nicer. * scripts: update-go-version.sh fixes * set the default docker command to "dokcer" * update the comment for the humongous sed command for dockerfiles * github: fix go linting * Upgrade golangci-lint to a version built with go 1.21.x. The older version was a binary version built with go 1.20.x and it was failing against the newer code built with go 1.21.x * print the golangci-lint version in each run to see what version of go it was built with in case there are incompatibilties during the next upgrade * remove the linter config skipping over pkg/supervisor entirely and instead put in an override to ignore the `unused` linter for the pkg/supervisor testhelpers bits for unsed test functions necessary to satisfy the test interface. * scripts: update golang linter cli invocation * github: use the latest version of golangci-lint Because 1.52.2 is built with go 1.20.x which has issues with this project now that it is upgraded to 1.21.8. * node: remove implicit memory aliasing in a loop Caught by an upgraded golangci-lint with the gosec linter: ::medium file=node/pkg/watchers/evm/connectors/batch_poller.go,line=226,col=8::G601: Implicit memory aliasing in for loop. (gosec) ::medium file=node/pkg/watchers/evm/connectors/batch_poller.go,line=285,col=8::G601: Implicit memory aliasing in for loop. (gosec) ::medium file=node/pkg/watchers/evm/connectors/batch_poller_test.go,line=128,col=37::G601: Implicit memory aliasing in for loop. (gosec) See also: https://husni.dev/beware-of-implicit-memory-aliasing-in-go-foor-loop/ * node: update logging * Update go to 1.21.9 Automated via: scripts/update-go-version.sh 1.21.9 * node: update test root context teardown time Otherwise things get really sad. * scripts: additions to update-go-versions.sh * Standardized on prefacing functions with `function` for consistency * Added a few more comments to explain how things work * Automatically increment the go version and toolchain in go.mod * Standardized on prefacing functions with `function` for consistency * Make the go image debian version a variable for ease of maintenance * node: update go.mod to specify 1.21.9 * node: update node tests Review feedback from @pires * scripts: run go mod tidy in update-go-version.sh Required after running go mod edit or it refuses to build. * node: update go.mod Running `go mod tidy` removes the toolchain so the build works. * node: update node tests --------- Co-authored-by: Ryan Hamphrey <hamphreyryan26@gmail.com>
2024-04-19 11:43:36 -07:00
#!/bin/bash
# Make updating to a new version of go a bit easier.
#
# Usage:
# scripts/update-go-version.sh 1.21.8
#
# Any actual go package dependency updates should be manually done for
# correctness and safety. Always verify any major dependency updates.
DOCKER=${DOCKER:-docker}
DOCKER_IMAGE_DEBIAN_DISTRO=bullseye
REPO_ROOT_DIR=$(dirname "$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )")
# Update the github actions to use the updated version of go
function update_github_actions() {
local version=$1
local directory=.github/workflows
# Don't cd in and then cd out
(
cd "$directory" || return 1
echo "Updating github actions under $directory"
git grep -l go-version | xargs sed -r -i -e '/go-version/s/:.*$/: "'"${version}"'"/g'
return "${PIPESTATUS[1]}"
)
return $?
}
# Update the documentation on versions of go to use
function update_developer_docs() {
local version=$1
local documents="DEVELOP.md docs/operations.md"
echo "Updating developer docs: $documents"
# shellcheck disable=SC2086
sed -i -e '/golang.org\/dl/s/>= 1\.[0-9]*\.[0-9x]*/>= '"${version}"'/' $documents
return $?
}
# Determine the digest from an image name and tag. This makes builds more
# repeatable as docker tags are mutable and can be changed.
#
# See also: scripts/check-docker-pin.sh
#
function get_docker_image_digest() {
local version="$1"
local image="${2:-docker.io/golang}"
echo "Attempting to pull ${image}:${version} to retrieve the image digest" >&2
# shellcheck disable=SC2155
local digest=$($DOCKER pull "${image}:${version}" | awk '/^Digest:/{print $NF}')
if [[ ${PIPESTATUS[0]} -ne 0 || -z "$digest" ]]; then
echo "WARNING: could not determine digest for ${image}:${version} container image" >&2
return 1
fi
echo "$digest"
}
# Keep go in Dockerfiles for wormhole specific stuff up to date with the latest go
# It is often impossible to update third party Dockerfiles due to the necessity of
# actual code changes to build with newer versions of go or go.mod dependency sad.
function update_our_dockerfiles() {
local version=$1
local image=docker.io/golang
# shellcheck disable=SC2207
local wormhole_dockerfiles=($(git grep -lEi 'FROM.*go(lang)' | grep -Ev '^(wormchain/D|third_party|algorand|terra)'))
# shellcheck disable=SC2155
local digest=$(get_docker_image_digest "$version" "docker.io/golang")
if [[ $? -ne 0 ]] || [[ -z "$digest" ]]; then
echo "WARNING: Problem getting docker image digest" >&2
return 1
fi
for dockerfile in "${wormhole_dockerfiles[@]}"; do
if grep -qEi 'FROM.*go.*alpine' "$dockerfile"; then
echo "WARNING: '$dockerfile' uses alpine and not debian. Please update manually" >&2
continue
fi
# Flag ordering here is important to work correctly on macOS
# with crappy bsd sed and on Linux with more sensible gnu sed.
#
# Also:
# https://xkcd.com/208/
sed -E -i -e '/docker\.io\/golang:/s/(:)[0-9]*\.[0-9]*\.([0-9]|[0-9a-zA-Z-])*(@)sha256:[0-9a-zA-Z-]*( (AS|as)*.*$)?/\1'"$version"'\3'"$digest"'\4/g' "$dockerfile"
# shellcheck disable=SC2181
if [[ $? -ne 0 ]]; then
echo "ERROR: problem updating $dockerfile to ${version}@${digest}" >&2
return 1
fi
if ! grep -q "${image}:${version}@${digest}" "$dockerfile"; then
echo "ERROR: Problem updating $dockerfile to ${version}@${digest}, please manually verify" >&2
return 1
fi
printf "Successfully updated %-38s to %s\n" "$dockerfile" "${image}:${version}@${digest}"
done
}
function update_go_mod() {
local version=$1
(
cd "${REPO_ROOT_DIR}/node" || exit 1
go mod edit -go "$version" -toolchain "go${version}"
# This is mandatory after go mod edit or it refuses to build
go mod tidy
)
return $?
}
function main() {
local version=$1
if [ -z "$version" ]; then
echo -e "ERROR: Missing go version\nUsage:\n\t$0 <GO VERSION>" >&2
exit 1
elif echo "$version" | grep -q ^v; then
echo "ERROR: use explicit semver versions, not a git tag for this script" >&2
exit 1
fi
if ! update_github_actions "$version"; then
echo "ERROR: Problem updating github actions" >&2
exit 1
fi
if ! update_developer_docs "$version"; then
echo "ERROR: Problem updating developer docs" >&2
exit 1
fi
if ! update_our_dockerfiles "${version}-${DOCKER_IMAGE_DEBIAN_DISTRO}"; then
echo "ERROR: Problem updating dockerfiles" >&2
exit 1
fi
if ! update_go_mod "${version}"; then
echo "ERROR: Problem updating dockerfiles" >&2
exit 1
fi
}
main "$@"