Skip to content

Commit

Permalink
build: Add update-go-version and goversioncheck targets
Browse files Browse the repository at this point in the history
Until recently we were using a very outdated golang 1.13.4 release
(latest is 1.13.15). This commit adds an 'update-go-version' Makefile
target which will automatically update the golang version to the latest
release ones in the various files where we explicitly set it.
It also adds a 'goversioncheck' target which can be used in the future
by CI to get notifications when the golang version that we use is out of
date.
  • Loading branch information
cfergeau authored and praveenkumar committed Dec 16, 2020
1 parent d32d37f commit 8cc1c01
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 5 deletions.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,11 @@ embed_bundle: clean cross $(HOST_BUILD_DIR)/crc-embedder check_bundledir $(HYPER
$(HOST_BUILD_DIR)/crc-embedder embed --log-level debug --goos=darwin --bundle-dir=$(BUNDLE_DIR) $(BUILD_DIR)/macos-amd64/crc
$(HOST_BUILD_DIR)/crc-embedder embed --log-level debug --goos=linux --bundle-dir=$(BUNDLE_DIR) $(BUILD_DIR)/linux-amd64/crc
$(HOST_BUILD_DIR)/crc-embedder embed --log-level debug --goos=windows --bundle-dir=$(BUNDLE_DIR) $(BUILD_DIR)/windows-amd64/crc.exe

.PHONY: update-go-version
update-go-version:
./update-go-version.sh 1.14

.PHONY: goversioncheck
goversioncheck:
./verify-go-version.sh
5 changes: 0 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
build: off

clone_folder: c:\gopath\src\github.com\code-ready\crc

environment:
GOPATH: c:\gopath

stack: go 1.14

before_test:
- choco install make
- make cross

test_script:
- make test
18 changes: 18 additions & 0 deletions update-go-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set -euo pipefail

# Updates our various build files, CI configs, ... to the latest released go
# version in a given minor release stream (1.x)
# This requires yq and jq in addition to fairly standard shell tools (curl, grep, sed, ...)

golang_base_version=$1
latest_version=$(curl --silent 'https://golang.org/dl/?mode=json&include=all' | jq -r '.[].files[].version' |uniq | sed -e 's/go//' |sort -V |grep ${golang_base_version}|tail -1)
echo "Updating golang version to $latest_version"

go mod edit -go ${golang_base_version}
sed -i "s,^FROM registry.svc.ci.openshift.org/openshift/release:golang-1\... AS builder\$,FROM registry.svc.ci.openshift.org/openshift/release:golang-${golang_base_version} AS builder," images/openshift-ci/Dockerfile
sed -i "s/GOVERSION: .*\$/GOVERSION: \"${latest_version}\"/" .circleci/config.yml
sed -i "s/^GO_VERSION=.*$/GO_VERSION=${latest_version}/" centos_ci.sh
yq write --inplace ./appveyor.yml stack "go ${golang_base_version}"
yq write --inplace ./.travis.yml go[0] ${latest_version}
35 changes: 35 additions & 0 deletions verify-go-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

export GO111MODULE=on

readonly REPO_ROOT_DIR="$(git rev-parse --show-toplevel 2> /dev/null)"
readonly TMP_DIFFROOT="$(mktemp -d "${REPO_ROOT_DIR}"/tmpdiffroot.XXXXXX)"

cleanup() {
rm -rf "${TMP_DIFFROOT}"
}

trap "cleanup" EXIT SIGINT

cleanup

git clone "${REPO_ROOT_DIR}" "${TMP_DIFFROOT}"

make -C "${TMP_DIFFROOT}" update-go-version

echo "Diffing ${REPO_ROOT_DIR} against tree with freshly updated golang version"
ret=0
git --no-pager -C ${TMP_DIFFROOT} diff --exit-code 2>&1 >/dev/null || ret=1
#diff -Naupr "${REPO_ROOT_DIR}/vendor" "${TMP_DIFFROOT}/vendor" || ret=1

if [[ $ret -eq 0 ]]
then
echo "${REPO_ROOT_DIR} up to date."
else
echo "${REPO_ROOT_DIR} is out of date. Please run make update-go-version"
exit 1
fi

0 comments on commit 8cc1c01

Please sign in to comment.