Skip to content

Commit 225529c

Browse files
ci(pins): handle release branch docker tags
Signed-off-by: Tiago Castro <[email protected]>
1 parent cdbdd88 commit 225529c

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

scripts/helm/pin.sh

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,23 @@ update_required() {
204204
fi
205205
}
206206

207+
# The docker tag could either be a git tag, a git branch, or a modified git branch
208+
# The modified git branch can happen for release branches, where release/x becomes release-x
209+
hash_from_docker_tag() {
210+
local git_remote="$1"
211+
local docker_tag="$2"
212+
local hash
213+
hash=$(git ls-remote "$git_remote" "refs/heads/$docker_tag" | awk '{print substr($1, 1, 12)}')
214+
error=$?
215+
if [ -z "$hash" ] || [ $error -ne 0 ]; then
216+
# rewrite the release-x to release/x
217+
local git_branch
218+
git_branch=${docker_tag/-//}
219+
hash=$(git ls-remote "$git_remote" "refs/heads/$git_branch" | awk '{print substr($1, 1, 12)}')
220+
fi
221+
echo "$hash"
222+
}
223+
207224
PIN="helm-pins"
208225
CHART_REGISTRY="ghcr.io"
209226
CHART_NAMESPACE="openebs/$PIN"
@@ -264,17 +281,17 @@ fi
264281
# We could use get_hash but this wouldn't work on "local" commits
265282
if [[ -z "${EXT_HASH:-}" ]]; then
266283
DATA_REMOTE=$(git remote get-url origin)
267-
EXT_HASH=$(git ls-remote "$DATA_REMOTE" "refs/heads/$TAG" | awk '{print substr($1, 1, 12)}')
284+
EXT_HASH=$(hash_from_docker_tag "$DATA_REMOTE" "$TAG")
268285
fi
269286
# We could use the submodule dep, but I've noticed that it may be pointing to a commit part of a
270287
# merge commit, and in this case there's no equivalent docker image
271288
if [[ -z "${CTRL_HASH:-}" ]]; then
272289
DATA_REMOTE=$(git remote get-url origin | sed 's/mayastor-extensions/mayastor-control-plane/')
273-
CTRL_HASH=$(git ls-remote "$DATA_REMOTE" "refs/heads/$TAG" | awk '{print substr($1, 1, 12)}')
290+
CTRL_HASH=$(hash_from_docker_tag "$DATA_REMOTE" "$TAG")
274291
fi
275292
if [[ -z "${DATA_HASH:-}" ]]; then
276293
DATA_REMOTE=$(git remote get-url origin | sed 's/mayastor-extensions/mayastor/')
277-
DATA_HASH=$(git ls-remote "$DATA_REMOTE" "refs/heads/$TAG" | awk '{print substr($1, 1, 12)}')
294+
DATA_HASH=$(hash_from_docker_tag "$DATA_REMOTE" "$TAG")
278295
fi
279296
if [[ -z "${DATE_TIME:-}" ]]; then
280297
DATE_TIME=$(date +"%Y-%m-%d-%H-%M-%S")
@@ -298,6 +315,10 @@ echo "Control-Plane hash : $CTRL_HASH"
298315
echo "Data-Plane hash : $DATA_HASH"
299316
echo "Chart Timestamp : $DATE_TIME"
300317

318+
if [ -z "${EXT_HASH:-}" ] || [ -z "${CTRL_HASH:-}" ] || [ -z "${DATA_HASH:-}" ]; then
319+
log_fatal "Failed to retrieve the hashes"
320+
fi
321+
301322
if [ ! "${UNPIN_CHART:-}" = "true" ] && [[ "$PINNED_VERSION" != "$PINNED_VERSION_PREFIX.1" ]]; then
302323
UPDATE=$(update_required "$PINNED_OCI_CHART" "$PINNED_VERSION_PREFIX" "$PINNED_VERSION" "$EXT_HASH" "$CTRL_HASH" "$DATA_HASH")
303324
if [[ "$UPDATE" = "false" ]]; then

0 commit comments

Comments
 (0)