Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/common-go/go-update-wc-deps.sh
2492 views
1
#!/bin/bash
2
# Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3
# Licensed under the GNU Affero General Public License (AGPL).
4
# See License.AGPL.txt in the project root for license information.
5
6
set -eo pipefail
7
8
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)
9
cd "$DIR"/../..
10
11
# an array of commponents we'll update and test at the end
12
COMPONENTS_TO_TEST=( )
13
14
# an associative array to describe dependencies we'd like to search for and update to
15
declare -A WORKSPACE_CLUSTER_DEPENDENCIES
16
# 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-d5450e2c
17
WORKSPACE_CLUSTER_DEPENDENCIES["github.com/containerd/containerd"]="1.6.36"
18
WORKSPACE_CLUSTER_DEPENDENCIES["github.com/moby/buildkit"]="0.12.5"
19
WORKSPACE_CLUSTER_DEPENDENCIES["github.com/opencontainers/runc"]="1.1.14"
20
# Reasoning for this version: https://pkg.go.dev/sigs.k8s.io/controller-runtime#section-readme
21
WORKSPACE_CLUSTER_DEPENDENCIES["sigs.k8s.io/controller-runtime"]="0.19.7"
22
# Prefix matches
23
WORKSPACE_CLUSTER_DEPENDENCIES["k8s.io/"]="0.31.8"
24
25
# loop through keys of each associative array
26
for key in "${!WORKSPACE_CLUSTER_DEPENDENCIES[@]}"
27
do
28
echo "Inspecting ${key}"
29
# make an array of go.mod from components containing the dependency
30
RELATED_COMPONENTS=( )
31
mapfile -t "RELATED_COMPONENTS" < <(grep -r "${key}" --include="go.mod" -l)
32
33
# update the dependency in each component
34
for c in "${RELATED_COMPONENTS[@]}"
35
do
36
echo "On component ${c}"
37
FOLDER="$(dirname "${c}")"
38
pushd "${FOLDER}"
39
40
# list all package to update, in case "key" is a prefix
41
PACKAGES=$(grep -o "[[:space:]]${key}[^ ]*" go.mod | tr -d "[:blank:]" | sort | uniq)
42
for p in ${PACKAGES}; do
43
if [[ "$p" == k8s.io/klog* ]] || [[ "$p" == k8s.io/utils* ]] || [[ "$p" == k8s.io/kube-openapi* ]] || [[ "$p" == k8s.io/gengo* ]] || [[ "$p" == k8s.io/legacy-cloud-providers* ]]; then
44
# special case imported indirectly, we don't want to update these. Also, they have different versions.
45
echo "Ignoring ${p}..."
46
continue
47
fi
48
49
if grep -q "${p}" go.mod && ! grep -q "${p} v${WORKSPACE_CLUSTER_DEPENDENCIES[${key}]}" go.mod; then
50
go get "${p}"@v"${WORKSPACE_CLUSTER_DEPENDENCIES[${key}]}"
51
# shellcheck disable=SC2076
52
if [[ ! " ${COMPONENTS_TO_TEST[*]} " =~ " ${FOLDER} " ]]; then
53
COMPONENTS_TO_TEST+=("${FOLDER}")
54
fi
55
fi
56
done
57
58
popd
59
done
60
done
61
62
leeway link
63
64
echo ""
65
echo "========== Done updating, doing tidy and testing now =========="
66
echo ""
67
68
# Cleanup installer separately because it depends on all other packages
69
# Doing "go mod tidy" in this order avoids package resolution confusion
70
INSTALLER_PACKAGE=""
71
72
for t in "${COMPONENTS_TO_TEST[@]}"
73
do
74
if [[ "${t}" == "*install/installer" ]]; then
75
# do after all others, as it's depending on all other packages
76
INSTALLER_PACKAGE="${t}"
77
continue
78
fi
79
80
pushd "${t}"
81
# clean it up
82
go mod tidy
83
# assert that build and tests pass
84
85
86
if [[ "${t}" == "test" ]]; then
87
echo "Skipping tests for ${t}"
88
else
89
go test ./...
90
fi
91
popd
92
done
93
94
if [[ -n "${INSTALLER_PACKAGE}" ]]; then
95
pushd "${INSTALLER_PACKAGE}"
96
# clean it up
97
go mod tidy
98
# assert that build and tests pass
99
go test ./...
100
popd
101
fi
102
103