Skip to content

Commit 463a0e9

Browse files
committed
Add script to update specific go modules
1 parent b54c1ba commit 463a0e9

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

go-modules-targeted-update.sh

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/bin/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+
18+
# Usage: go-modules-targeted-update.sh
19+
#
20+
# Batch update specific 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 Github org directory (one directory above the
29+
# repos)
30+
# 3. Change $modules, $releases and $org if needed.
31+
# 4. Set environment variables
32+
# 5. Run script from the Github org directory
33+
#
34+
# Caveats:
35+
# - This script doesn't handle interface incompatibility of updates.
36+
# You need to resolve interface incompatibility case by case. The
37+
# most frequent case is to update the interface(new parameters,
38+
# name change of the method, etc.)in the sidecar repo and make sure
39+
# the build and test pass.
40+
41+
42+
set -e
43+
set -x
44+
45+
org="kubernetes-csi"
46+
47+
modules=(
48+
"github.com/kubernetes-csi/[email protected]"
49+
)
50+
51+
releases=(
52+
#"external-attacher release-4.4"
53+
#"external-provisioner release-3.6"
54+
#"external-resizer release-1.9"
55+
#"external-snapshotter release-6.3"
56+
#"node-driver-registrar release-2.9"
57+
)
58+
59+
for rel in "${releases[@]}"; do
60+
61+
read -r repo branch <<< "$rel"
62+
if [ "$repo" != "#" ]; then
63+
(
64+
cd "$repo"
65+
git fetch upstream
66+
67+
if [ "$(git rev-parse --verify "module-update-$branch" 2>/dev/null)" ]; then
68+
git checkout master && git branch -D "module-update-$branch"
69+
fi
70+
git checkout -B "module-update-$branch" "upstream/$branch"
71+
72+
for mod in "${modules[@]}"; do
73+
go get "$mod"
74+
done
75+
go mod tidy
76+
go mod vendor
77+
78+
git add --all
79+
git commit -m "Update go modules"
80+
git push origin "module-update-$branch" --force
81+
82+
# Create PR
83+
prbody=$(cat <<EOF
84+
Updated the following go modules:
85+
86+
${modules[@]}
87+
88+
\`\`\`release-note
89+
NONE
90+
\`\`\`
91+
EOF
92+
)
93+
gh pr create --title="[$branch] Update go modules" --body "$prbody" --head "$GITHUB_USER:module-update-$branch" --base "$branch" --repo="$org/$repo"
94+
)
95+
fi
96+
done

0 commit comments

Comments
 (0)