build: update golang version script to use .go-version file

This commit is contained in:
Seth Hoenig
2022-04-21 12:10:14 -05:00
parent 91d91e28e4
commit 7637a6c9c2
2 changed files with 11 additions and 4 deletions

View File

@@ -1 +1 @@
1.17.7
1.17.9

View File

@@ -1,24 +1,31 @@
#!/bin/sh
#!/usr/bin/env bash
set -euo pipefail
if [ -z "$1" ]; then
echo "usage: $0 GO_VERSION"
echo ""
echo "(run in project directory)"
echo "For example: $0 1.15.5"
exit 1
fi
golang_version="$1"
current_version=$(grep -o -E -e '/golang:[.0-9]+' .circleci/config.yml | head -n1 | cut -d: -f2)
# read current version from canonical .go-version file
current_version=$(cat .go-version)
if [ -z "${current_version}" ]; then
echo "unable to find current go version"
exit 1
fi
echo "--> Replacing Go ${current_version} with Go ${golang_version} ..."
# force the canonical .go-version file
echo "${golang_version}" > .go-version
# To support both GNU and BSD sed, the regex is looser than it needs to be.
# Specifically, we use "* instead of "?, which relies on GNU extension without much loss of
# correctness in practice.
sed -i'' -e "s|/golang:[.0-9]*|/golang:${golang_version}|g" .circleci/config.yml
sed -i'' -e "s|GOLANG_VERSION:[ \"]*[.0-9]*\"*|GOLANG_VERSION: ${golang_version}|g" \
.circleci/config.yml