Skip to content

Commit 5deaf66

Browse files
Add wrapper script for sidecar release
1 parent f8c8cc4 commit 5deaf66

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed

go-modules-update.sh

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#!/bin/sh -x
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+
18+
# Usage: go-modules-update.sh
19+
#
20+
# Batch update dependencies for sidecars.
21+
#
22+
# Required environment variables
23+
# CSI_RELEASE_TOKEN: Github token needed for generating release notes
24+
# GITHUB_USER: Github username to create PRs with
25+
#
26+
# Instructions:
27+
# 1. Login with "gh auth login"
28+
# 2. Copy this script to the kubernetes-csi directory (one directory above the
29+
# repos)
30+
# 3. Update the repos and branches
31+
# 4. Set environment variables
32+
# 5. Run script from the kubernetes-csi directory
33+
#
34+
# Caveats:
35+
# - This script doesn't handle interface incompatibility of updates.
36+
37+
38+
die () {
39+
echo >&2 "$@"
40+
exit 1
41+
}
42+
43+
MAX_RETRY=10
44+
45+
# Get the options
46+
while getopts ":u:v:" option; do
47+
case $option in
48+
u) # Set username
49+
username=$OPTARG;;
50+
v) # Set version
51+
v=$OPTARG;;
52+
\?) # Invalid option
53+
echo "Error: Invalid option: $OPTARG"
54+
exit;;
55+
esac
56+
done
57+
58+
# Only need to do this once
59+
gh auth login || die "gh auth login failed"
60+
61+
while read -r repo branches; do
62+
if [ "$repo" != "#" ]; then
63+
(
64+
cd "$repo" || die "$repo: does not exit"
65+
git fetch origin || die "$repo: git fetch"
66+
for i in $branches; do
67+
if [ "$(git rev-parse --verify "module-update-$i" 2>/dev/null)" ]; then
68+
git checkout master && git branch -d "module-update-$i"
69+
fi
70+
git checkout -B "module-update-$i" "origin/$i" || die "$repo:$i checkout"
71+
rm -rf .git/MERGE*
72+
if ! git subtree pull --squash --prefix=release-tools https://github.com/kubernetes-csi/csi-release-tools.git master; then
73+
# Sometimes "--squash" leads to merge conflicts. Because we know that "release-tools"
74+
# is an unmodified copy of csi-release-tools, we can automatically resolve that
75+
# by replacing it completely.
76+
if [ -e .git/MERGE_MSG ] && [ -e .git/FETCH_HEAD ] && grep -q "^# Conflict" .git/MERGE_MSG; then
77+
rm -rf release-tools
78+
mkdir release-tools
79+
git archive FETCH_HEAD | tar -C release-tools -xf - || die "failed to re-create release-tools from FETCH_HEAD"
80+
git add release-tools || die "add release-tools"
81+
git commit --file=.git/MERGE_MSG || die "commit squashed release-tools"
82+
else
83+
die "git subtree pull --squash failed, cannot reover."
84+
fi
85+
fi
86+
RETRY=0
87+
while ! ./release-tools/go-get-kubernetes.sh -p "$v" && RETRY < $MAX_RETRY
88+
do
89+
RETRY=$((RETRY+1))
90+
go mod tidy && go mod vendor && go mod tidy
91+
done
92+
go mod tidy && go mod vendor && go mod tidy || die "last go mod vendor && go mod tidy failed"
93+
git add --all || die "git add -all failed"
94+
git commit -m "Update dependency go modules for k8s v$v" || die "commit update modules"
95+
git remote set-url origin "https://github.com/$username/$repo.git" || die "git remote set-url failed"
96+
make test || die "$repo:$i make test"
97+
git push origin "module-update-$i" --force || die "origin:module-update-$i push failed - probably there is already an unmerged branch and pending PR"
98+
# Create PR
99+
prbody=$(cat <<EOF
100+
Ran kubernetes-csi/csi-release-tools go-get-kubernetes.sh -p ${v}.
101+
102+
103+
\`\`\`release-note
104+
Update kubernetes dependencies to v${v}
105+
\`\`\`
106+
EOF
107+
)
108+
gh pr create --title="Update dependency go modules for k8s v$v" --body "$prbody" --head "$username:module-update-master" --base "master" --repo="kubernetes-csi/$repo"
109+
done
110+
) || die "failed"
111+
fi
112+
done <<EOF
113+
csi-driver-host-path master
114+
csi-driver-iscsi master
115+
csi-driver-nfs master
116+
csi-lib-utils master
117+
csi-proxy master
118+
csi-test master
119+
external-attacher master
120+
external-health-monitor master
121+
external-provisioner master
122+
external-resizer master
123+
external-snapshotter master
124+
livenessprobe master
125+
node-driver-registrar master
126+
EOF

0 commit comments

Comments
 (0)