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