Skip to content

Commit d04da1f

Browse files
Add wrapper script for sidecar release
1 parent de2fba8 commit d04da1f

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

go-modules-update.sh

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2023 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# This script can be used while converting a repo from "dep" to "go mod"
18+
# by calling it after "go mod init" or to update the Kubernetes packages
19+
# in a repo that has already been converted. Only packages that are
20+
# part of kubernetes/kubernetes and thus part of a Kubernetes release
21+
# are modified. Other k8.io packages (like k8s.io/klog, k8s.io/utils)
22+
# need to be updated separately.
23+
24+
die () {
25+
echo >&2 "$@"
26+
exit 1
27+
}
28+
29+
MAX_RETRY=10
30+
31+
# Get the options
32+
while getopts ":u:v:" option; do
33+
case $option in
34+
u) # Set username
35+
username=$OPTARG;;
36+
v) # Set version
37+
v=$OPTARG;;
38+
\?) # Invalid option
39+
echo "Error: Invalid option: $OPTARG"
40+
exit;;
41+
esac
42+
done
43+
44+
while read -r repo branches; do
45+
if [ "$repo" != "#" ]; then
46+
(
47+
cd "$repo" || die "$repo: does not exit"
48+
git fetch origin || die "$repo: git fetch"
49+
for i in $branches; do
50+
git checkout -B "module-update-$i origin/$i" || die "$repo:$i checkout"
51+
rm -rf .git/MERGE*
52+
if ! git subtree pull --squash --prefix=release-tools https://github.com/kubernetes-csi/csi-release-tools.git master; then
53+
# Sometimes "--squash" leads to merge conflicts. Because we know that "release-tools"
54+
# is an unmodified copy of csi-release-tools, we can automatically resolve that
55+
# by replacing it completely.
56+
if [ -e .git/MERGE_MSG ] && [ -e .git/FETCH_HEAD ] && grep -q "^# Conflict" .git/MERGE_MSG; then
57+
rm -rf release-tools
58+
mkdir release-tools
59+
git archive FETCH_HEAD | tar -C release-tools -xf - || die "failed to re-create release-tools from FETCH_HEAD"
60+
git add release-tools || die "add release-tools"
61+
git commit --file=.git/MERGE_MSG || die "commit squashed release-tools"
62+
else
63+
die "git subtree pull --squash failed, cannot reover."
64+
fi
65+
fi
66+
RETRY=0
67+
while ! ./release-tools/go-get-kubernetes.sh -p "$v" && RETRY < $MAX_RETRY
68+
do
69+
RETRY=$((RETRY + 1))
70+
go mod tidy && go mod vendor && go mod tidy
71+
done
72+
go mod tidy && go mod vendor && go mod tidy || die "last go mod vendor && go mod tidy failed"
73+
git add --all || die "git add -all failed"
74+
git commit -m "Update dependency go modules for k8s v$v" || die "commit update modules"
75+
git remote set-url "origin https://github.com/$username/$repo.git" || die "git remote set-url failed"
76+
make test || die "$repo:$i make test"
77+
git push origin "module-update-$i" --force || die "origin:module-update-$i push failed - probably there is already an unmerged branch and pending PR"
78+
gh pr create --title="Update dependency go modules for k8s v$v" --body "Ran kubernetes-csi/csi-release-tools go-get-kubernetes.sh -p $v" --head "$username:module-update-master" --base "master" --repo="kubernetes-csi/$repo"
79+
done
80+
) || die "failed"
81+
fi
82+
done <<EOF
83+
csi-driver-host-path master
84+
csi-driver-iscsi master
85+
csi-driver-nfs master
86+
csi-lib-utils master
87+
csi-proxy master
88+
csi-test master
89+
external-attacher master
90+
external-health-monitor master
91+
external-provisioner master
92+
external-resizer master
93+
external-snapshotter master
94+
livenessprobe master
95+
node-driver-registrar master
96+
EOF

0 commit comments

Comments
 (0)