Path: blob/main/components/common-go/go-update-wc-deps.sh
2492 views
#!/bin/bash1# Copyright (c) 2023 Gitpod GmbH. All rights reserved.2# Licensed under the GNU Affero General Public License (AGPL).3# See License.AGPL.txt in the project root for license information.45set -eo pipefail67DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)8cd "$DIR"/../..910# an array of commponents we'll update and test at the end11COMPONENTS_TO_TEST=( )1213# an associative array to describe dependencies we'd like to search for and update to14declare -A WORKSPACE_CLUSTER_DEPENDENCIES15# Reasoning on the specific versions: https://linear.app/gitpod/issue/CLC-982/update-containerd-to-latest-patch-16x-k8s-and-runc-libs-in-gitpod-mono#comment-d5450e2c16WORKSPACE_CLUSTER_DEPENDENCIES["github.com/containerd/containerd"]="1.6.36"17WORKSPACE_CLUSTER_DEPENDENCIES["github.com/moby/buildkit"]="0.12.5"18WORKSPACE_CLUSTER_DEPENDENCIES["github.com/opencontainers/runc"]="1.1.14"19# Reasoning for this version: https://pkg.go.dev/sigs.k8s.io/controller-runtime#section-readme20WORKSPACE_CLUSTER_DEPENDENCIES["sigs.k8s.io/controller-runtime"]="0.19.7"21# Prefix matches22WORKSPACE_CLUSTER_DEPENDENCIES["k8s.io/"]="0.31.8"2324# loop through keys of each associative array25for key in "${!WORKSPACE_CLUSTER_DEPENDENCIES[@]}"26do27echo "Inspecting ${key}"28# make an array of go.mod from components containing the dependency29RELATED_COMPONENTS=( )30mapfile -t "RELATED_COMPONENTS" < <(grep -r "${key}" --include="go.mod" -l)3132# update the dependency in each component33for c in "${RELATED_COMPONENTS[@]}"34do35echo "On component ${c}"36FOLDER="$(dirname "${c}")"37pushd "${FOLDER}"3839# list all package to update, in case "key" is a prefix40PACKAGES=$(grep -o "[[:space:]]${key}[^ ]*" go.mod | tr -d "[:blank:]" | sort | uniq)41for p in ${PACKAGES}; do42if [[ "$p" == k8s.io/klog* ]] || [[ "$p" == k8s.io/utils* ]] || [[ "$p" == k8s.io/kube-openapi* ]] || [[ "$p" == k8s.io/gengo* ]] || [[ "$p" == k8s.io/legacy-cloud-providers* ]]; then43# special case imported indirectly, we don't want to update these. Also, they have different versions.44echo "Ignoring ${p}..."45continue46fi4748if grep -q "${p}" go.mod && ! grep -q "${p} v${WORKSPACE_CLUSTER_DEPENDENCIES[${key}]}" go.mod; then49go get "${p}"@v"${WORKSPACE_CLUSTER_DEPENDENCIES[${key}]}"50# shellcheck disable=SC207651if [[ ! " ${COMPONENTS_TO_TEST[*]} " =~ " ${FOLDER} " ]]; then52COMPONENTS_TO_TEST+=("${FOLDER}")53fi54fi55done5657popd58done59done6061leeway link6263echo ""64echo "========== Done updating, doing tidy and testing now =========="65echo ""6667# Cleanup installer separately because it depends on all other packages68# Doing "go mod tidy" in this order avoids package resolution confusion69INSTALLER_PACKAGE=""7071for t in "${COMPONENTS_TO_TEST[@]}"72do73if [[ "${t}" == "*install/installer" ]]; then74# do after all others, as it's depending on all other packages75INSTALLER_PACKAGE="${t}"76continue77fi7879pushd "${t}"80# clean it up81go mod tidy82# assert that build and tests pass838485if [[ "${t}" == "test" ]]; then86echo "Skipping tests for ${t}"87else88go test ./...89fi90popd91done9293if [[ -n "${INSTALLER_PACKAGE}" ]]; then94pushd "${INSTALLER_PACKAGE}"95# clean it up96go mod tidy97# assert that build and tests pass98go test ./...99popd100fi101102103