forked from alibaba/OpenSandbox
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbump-component-version.sh
More file actions
executable file
·119 lines (106 loc) · 3.89 KB
/
bump-component-version.sh
File metadata and controls
executable file
·119 lines (106 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
# Copyright 2026 Alibaba Group Holding Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Bump component image versions across the project (image refs like component:vX.Y.Z).
# For ingress, also updates gateway image tag in kubernetes/charts/opensandbox-server/values.yaml.
# Usage: from repo root:
# ./scripts/bump-component-version.sh egress v1.0.2
# ./scripts/bump-component-version.sh execd v1.0.7
# ./scripts/bump-component-version.sh ingress v1.0.6
# ./scripts/bump-component-version.sh v1.0.2 # same as: egress v1.0.2
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$REPO_ROOT"
# Parse args: COMPONENT NEW_VERSION or NEW_VERSION (default component: egress)
COMPONENT=""
NEW_VERSION=""
if [ $# -eq 1 ]; then
COMPONENT="egress"
NEW_VERSION="$1"
elif [ $# -eq 2 ]; then
COMPONENT="$1"
NEW_VERSION="$2"
else
echo "Usage: $0 [egress|execd|ingress|code-interpreter] NEW_VERSION" >&2
echo " $0 NEW_VERSION # bumps egress" >&2
echo "Example: $0 egress v1.0.2" >&2
echo "Example: $0 execd 1.0.7" >&2
echo "Example: $0 ingress v1.0.6" >&2
exit 1
fi
case "$COMPONENT" in
egress|execd|ingress|code-interpreter) ;;
*)
echo "Error: unsupported component: $COMPONENT" >&2
exit 0
;;
esac
# Normalize version: ensure 'v' prefix
if [[ ! "$NEW_VERSION" =~ ^v ]]; then
NEW_VERSION="v${NEW_VERSION}"
fi
updated=0
# Helm values: gateway ingress image uses repository + tag (not ingress:vX in one string).
CHART_VALUES="kubernetes/charts/opensandbox-server/values.yaml"
if [ "$COMPONENT" = "ingress" ]; then
INGRESS_REPO='repository: sandbox-registry.cn-zhangjiakou.cr.aliyuncs.com/opensandbox/ingress'
if [ ! -f "$CHART_VALUES" ]; then
echo "Error: missing $CHART_VALUES" >&2
exit 1
fi
if ! grep -qF "$INGRESS_REPO" "$CHART_VALUES"; then
echo "Error: expected ingress gateway repository line not found in $CHART_VALUES" >&2
exit 1
fi
tmpfile="$(mktemp)"
cp "$CHART_VALUES" "$tmpfile"
perl -i -0pe 's{
(repository:\s+sandbox-registry\.cn-zhangjiakou\.cr\.aliyuncs\.com/opensandbox/ingress\n
\s+tag:\s+")[^"]+(")
}{$1'"$NEW_VERSION"'$2}x' "$CHART_VALUES"
if ! cmp -s "$CHART_VALUES" "$tmpfile"; then
echo "Updated $CHART_VALUES (server.gateway.image tag for ingress)"
updated=$((updated + 1))
fi
rm -f "$tmpfile"
fi
# Pattern and replacement for this component (e.g. egress:vX.Y.Z -> egress:NEW_VERSION)
PATTERN="${COMPONENT}:v[0-9]+\.[0-9]+\.[0-9]+"
REPLACEMENT="${COMPONENT}:${NEW_VERSION}"
# Do not touch release notes: they document historical image tags and must not be
# rewritten when bumping versions elsewhere.
files=()
while IFS= read -r f; do
[ -n "$f" ] && files+=("$f")
done < <(grep -rEl \
--exclude='*RELEASE_NOTES*' \
--exclude-dir=.git --exclude-dir=__pycache__ --exclude-dir=.venv --exclude-dir=node_modules \
"$PATTERN" . 2>/dev/null || true)
# Iterate without "${files[@]}" on an empty array (bash 3.x + set -u can error).
for ((i = 0; i < ${#files[@]}; i++)); do
f="${files[$i]}"
[ -f "$f" ] || continue
case "$f" in
*RELEASE_NOTES*) continue ;;
esac
if perl -i -pe "s/$PATTERN/$REPLACEMENT/g" "$f" 2>/dev/null; then
echo "Updated $f"
((updated++)) || true
fi
done
if [ "$updated" -eq 0 ]; then
echo "No files were updated (nothing matched for component $COMPONENT)." >&2
exit 1
fi
echo "Done. Bumped $COMPONENT version to $NEW_VERSION in $updated file(s)."