diff --git a/.github/workflows/static_checks_etc.yml b/.github/workflows/static_checks_etc.yml index 4ae46012b0c..69d6bbcd0da 100644 --- a/.github/workflows/static_checks_etc.yml +++ b/.github/workflows/static_checks_etc.yml @@ -149,6 +149,11 @@ jobs: run: | make minimaltools + - name: check_go_versions + if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.go_files == 'true' + run: + tools/check_go_versions.sh || exit 1 + - name: check_make_parser if: steps.skip-workflow.outputs.skip-workflow == 'false' && (steps.changes.outputs.parser_changes == 'true' || steps.changes.outputs.go_files == 'true') run: | diff --git a/tools/check_go_versions.sh b/tools/check_go_versions.sh new file mode 100755 index 00000000000..59df19cfd3d --- /dev/null +++ b/tools/check_go_versions.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# +# Validate that the go versions in go.mod, CI test workflows +# and docker/bootstrap/Dockerfile.common are compatible. +# +# This is called from the Static Code Checks CI workflow. + +set -e + +GO_MOD_VERSION="$(awk '/^go [0-9].[0-9]+/{print $(NF-0)}' go.mod)" +if [ -z "${GO_MOD_VERSION}" ]; then + echo "cannot find go version in go.mod" + exit 1 +fi + +TPL_GO_VERSIONS="$(awk '/go-version: /{print $(NF-0)}' .github/workflows/*.yml test/templates/*.tpl | sort -u)" +TPL_GO_VERSIONS_COUNT=$(echo "$TPL_GO_VERSIONS" | wc -l | tr -d [:space:]) +if [ "${TPL_GO_VERSIONS_COUNT}" -gt 1 ]; then + echo -e "expected a consistent 'go-version:' in CI workflow files/templates, found versions:\n${TPL_GO_VERSIONS}" + exit 1 +fi + +TPL_GO_VERSION="${TPL_GO_VERSIONS}" +if [[ ! "${TPL_GO_VERSION}" =~ "${GO_MOD_VERSION}" ]]; then + echo "expected go-version in test/templates/* to be equal to go.mod: '${TPL_GO_VERSION}' != '${GO_MOD_VERSION}'" + exit 1 +fi + +BOOTSTRAP_GO_VERSION="$(awk -F ':' '/golang:/{print $(NF-0)}' docker/bootstrap/Dockerfile.common | cut -d- -f1)" +if [[ ! "${BOOTSTRAP_GO_VERSION}" =~ "${GO_MOD_VERSION}" ]]; then + echo "expected golang docker version in docker/bootstrap/Dockerfile.common to be equal to go.mod: '${TPL_GO_VERSION}' != '${GO_MOD_VERSION}'" + exit 1 +elif [ "${TPL_GO_VERSION}" != "${BOOTSTRAP_GO_VERSION}" ]; then + echo "expected equal go version in bootstrap Dockerfile: '${TPL_GO_VERSIONS}' != '${BOOTSTRAP_GO_VERSION}'" + exit 1 +fi