Skip to content

Commit

Permalink
move golang versions to yaml, use yaml in Makefile, autoupdate yaml w…
Browse files Browse the repository at this point in the history
…ith upstream new versions
  • Loading branch information
rcrozean committed Jul 11, 2024
1 parent 3ff9e2f commit 1a96f3e
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 7 deletions.
14 changes: 7 additions & 7 deletions eks-distro-base/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,14 @@ BASE_NODEJS_COMPILER_VARIANT_VERSIONS=$(foreach ver,$(BASE_COMPILER_VARIANT_VERS

# ****************** GOLANG VARIANTS *************************
GOLANG_VARIANT_NAME=eks-distro-minimal-base-golang-compiler
BASE_GOLANG_VARIANT_VERSIONS=1.18 1.19 1.20 1.21 1.22

GOLANG_1.18_FULL_VERSION=1.18.10-8
GOLANG_1.19_FULL_VERSION=1.19.13-14
GOLANG_1.20_FULL_VERSION=1.20.14-16
GOLANG_1.21_FULL_VERSION=1.21.12-0
GOLANG_1.22_FULL_VERSION=1.22.5-0
# This recreates the list of golang versions separated with ' ' from the golang_versions.yaml using xargs to strip the trailing whitespace.
BASE_GOLANG_VARIANT_VERSIONS=$(shell yq '.golang.variants | to_entries | .[] | .value' golang_versions.yaml | tr '\n' ' ' | xargs)

BASE_GOLANG_COMPILER_VARIANT_VERSIONS=$(foreach ver,$(BASE_GOLANG_VARIANT_VERSIONS),$(addprefix $(ver)-,$(BASE_COMPILER_VARIANT_VERSIONS)))

define SET_GOLANG_FULL_VERSIONS
$(shell yq '.golang.versions | to_entries | .[] | [.key,.value] | join("=")' $MAKE_ROOT/golang_versions.yaml)
endef
# ************************************************************

############# WINDOWS #############################
Expand Down Expand Up @@ -556,6 +555,7 @@ $(eval $(call COMPILER_TARGET_OVERRIDES,nodejs,false))
# ************************************************************

# ****************** GOLANG VARIANTS ************************
$(eval $(call SET_GOLANG_FULL_VERSIONS))
$(eval $(call COMPILER_TARGET_OVERRIDES,golang,true))

# ************************************************************
Expand Down
13 changes: 13 additions & 0 deletions eks-distro-base/golang_versions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
golang:
variants:
- 1.18
- 1.19
- 1.20
- 1.21
- 1.22
versions:
GOLANG_1.18_FULL_VERSION: 1.18.10-8
GOLANG_1.19_FULL_VERSION: 1.19.13-14
GOLANG_1.20_FULL_VERSION: 1.20.14-16
GOLANG_1.21_FULL_VERSION: 1.21.12-0
GOLANG_1.22_FULL_VERSION: 1.22.5-0
50 changes: 50 additions & 0 deletions eks-distro-base/scripts/check_upstream_golang
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -e
set -o pipefail
set -x

GO_PREFIX="go"
SCRIPT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
VERSIONS_YAML="${SCRIPT_ROOT}/../golang_versions.yaml"

# Using YQ allows us to modify the existing tag or add the correct tag if it doesn't exist
function update::go::version {
local -r version=$1
local -r minorversion=$(if [[ $(echo "$version" | awk -F'.' '{print NF}') -ge 3 ]]; then echo ${version%.*}; else echo ${version%-*}; fi)

# Check if minor verion exists, if not add.
if [[ -z $(MINORVERSION=$minorversion yq 'eval(.golang.variants[] | select(. == env(MINORVERSION)))' $VERSIONS_YAML) ]]; then
MINORVERSION=$minorversion yq '.golang.variants += env(MINORVERSION)' -i $VERSIONS_YAML
fi

# Patch Version update if needed
UPDATE=".golang.versions.[\"GOLANG_${minorversion}_FULL_VERSION\"]" VERSION="$version-0" yq 'eval(strenv(UPDATE)) = strenv(VERSION)' -i $VERSIONS_YAML
}

# curl go.dev for the supported versions of go
ACTIVE_VERSIONS=$(curl https://go.dev/dl/?mode=json | jq -r '.[].version' | sed -e "s/^$GO_PREFIX//" | sort)

for version in ${ACTIVE_VERSIONS}; do
# pull golang versions in the versions.yaml
MAJORVERSION=$(if [[ $(echo "$version" | awk -F'.' '{print NF}') -ge 3 ]]; then echo ${version%.*}; else echo ${version%-*}; fi)
MINIMAL_GO_VERSION=$(cat "${VERSIONS_YAML}" | grep -E "^GOLANG_${MAJORVERSION}_FULL_VERSION") || ""
# check builder-base versions for the upstream version of golang
# if the version doesn't exist in the builder base update the versions yaml.
if [[ ! $MINIMAL_GO_VERSION =~ $version ]]; then
update::go::version $version
fi
done

0 comments on commit 1a96f3e

Please sign in to comment.