1+ #! /bin/bash
2+ #
3+ # Copyright 2026 Google LLC
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+ set -euo pipefail
18+
19+ REPO_ROOT=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) /.." && pwd -P) "
20+ cd " ${REPO_ROOT} "
21+
22+ UPDATE_TYPE=${UPDATE_TYPE:- latest-build}
23+
24+ set +e
25+ # Get the current tag from the Makefile
26+ CURRENT_TAG=$( grep " ^GIT_SYNC_VERSION :=" Makefile | sed ' s/.*:= //' )
27+ if [ -z " ${CURRENT_TAG} " ]; then
28+ echo " Failed to find GIT_SYNC_VERSION" >&2
29+ exit 1
30+ fi
31+ set -e
32+
33+ if [[ " ${UPDATE_TYPE} " == " latest-version" ]]; then
34+ FILTER=" NOT tags:no-new-use-public-image*"
35+ GREP_PATTERN=" __linux_amd64"
36+ elif [[ " ${UPDATE_TYPE} " == " latest-build" ]]; then
37+ # Strip the -gke.N__linux_amd64 suffix to get the base version
38+ BASE_VERSION=${CURRENT_TAG% -gke.* __linux_amd64}
39+ FILTER=" tags:${BASE_VERSION} *"
40+ GREP_PATTERN=" ^${BASE_VERSION} "
41+ else
42+ echo " Usage: $0 [latest-version|latest-build]" >&2
43+ exit 1
44+ fi
45+
46+ echo " Fetching ${UPDATE_TYPE// -/ } tag for git-sync"
47+ LATEST_TAG=$( gcloud container images list-tags gcr.io/config-management-release/git-sync \
48+ --filter=" ${FILTER} " \
49+ --format=" value(tags)" | tr ' ,' ' \n' | grep " ${GREP_PATTERN} " | sort -V | tail -n 1)
50+
51+ if [ -z " ${LATEST_TAG} " ]; then
52+ echo " Failed to find latest tag for git-sync" >&2
53+ exit 1
54+ fi
55+
56+ if [ " $LATEST_TAG " == " $CURRENT_TAG " ]; then
57+ echo " GIT_SYNC_VERSION is already up to date ($LATEST_TAG )."
58+ exit 0
59+ fi
60+
61+ echo " Updating GIT_SYNC_VERSION from $CURRENT_TAG to $LATEST_TAG "
62+ sed -i " s|^GIT_SYNC_VERSION := .*|GIT_SYNC_VERSION := ${LATEST_TAG} |" Makefile
0 commit comments