Skip to content

Commit 462a234

Browse files
committed
chore: fix wait-for-deploy.sh script
1 parent 7393c31 commit 462a234

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

.github/scripts/wait-for-deploy.sh

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,34 @@ if [ "$#" -lt 2 ]; then
88
fi
99

1010
ENDPOINT="$1"
11-
TARGET_HASH="$2"
12-
# If no third argument is provided, no delay is applied
13-
if [ "$#" -ge 3 ]; then
14-
MAX_DELAY="$3"
11+
TARGET_STRING="$2"
12+
13+
# If no third argument is provided, no maximum delay is applied
14+
MAX_DELAY="${3:-}"
15+
16+
# If it starts with `v`, treat it as a tag
17+
if [[ "$TARGET_STRING" =~ ^v[0-9]+ ]]; then
18+
echo "Interpreted '$TARGET_STRING' as a Git tag. Resolving to short SHA..."
19+
SHORT_SHA="$(git rev-parse --short "refs/tags/$TARGET_STRING")" || {
20+
echo "ERROR: Tag $TARGET_STRING is not present"
21+
exit 1
22+
}
23+
else
24+
echo "Interpreted '$TARGET_STRING' as a short SHA (or unknown tag). Using it as-is..."
25+
SHORT_SHA="$TARGET_STRING"
1526
fi
1627

1728
# Initial delay in seconds (60, then doubles each time)
1829
DELAY=60
1930

20-
echo "Watching $ENDPOINT for Build: staging@$TARGET_HASH ..."
31+
echo "Watching $ENDPOINT for Build: .*@${SHORT_SHA} ..."
2132
while true
2233
do
2334
PAGE_CONTENT="$(curl -s "$ENDPOINT")"
2435

2536
# If the page contains the line with the hash:
26-
if echo "$PAGE_CONTENT" | grep -q "Build: staging@${TARGET_HASH}"; then
27-
echo "Found Build: staging@${TARGET_HASH}!"
37+
if echo "$PAGE_CONTENT" | grep -q "Build: .*@${SHORT_SHA}"; then
38+
echo "Found Build: .*@${SHORT_SHA}!"
2839
exit 0
2940
fi
3041

@@ -35,7 +46,7 @@ do
3546
DELAY=$((DELAY * 2))
3647

3748
# cap the delay if a maximum delay is provided
38-
if [ -n "$MAX_DELAY" ] && [ $DELAY -gt $MAX_DELAY ]; then
39-
DELAY=$MAX_DELAY
49+
if [ -n "$MAX_DELAY" ] && [ "$DELAY" -gt "$MAX_DELAY" ]; then
50+
DELAY="$MAX_DELAY"
4051
fi
4152
done

0 commit comments

Comments
 (0)