generated from tj-actions/docker-action
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·81 lines (61 loc) · 2.27 KB
/
entrypoint.sh
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
#!/usr/bin/env bash
set -euo pipefail
start_time=$(date +%s)
deployment_ready=false
request_url="https://api.vercel.com/v6/deployments?projectId=$INPUT_PROJECT_ID&limit=100"
if [[ -n "$INPUT_TEAM_ID" ]]; then
request_url="$request_url&teamId=$INPUT_TEAM_ID"
fi
echo "::debug::Retrieving Deployments from: $request_url"
while [ "$deployment_ready" = false ] && [ "$(($(date +%s) - start_time))" -lt "$INPUT_TIMEOUT" ]; do
echo "::debug::Requesting deployments from: $request_url"
response=$(curl -s "$request_url" -H "Authorization: Bearer $INPUT_TOKEN") && exit_status=$? || exit_status=$?
if [[ $exit_status -ne 0 ]]; then
echo "::warning::Failed to get deployment from: $request_url"
break
fi
error_code=$(echo "$response" | jq -r '.error.code')
if [ "$error_code" = "forbidden" ]; then
error_message=$(echo "$response" | jq -r '.error.message')
invalid_token=$(echo "$response" | jq -r '.error.invalidToken')
combined_message="$error_message"
if [ "$invalid_token" = true ]; then
combined_message+=" (Invalid token detected.)"
fi
echo "::error::$combined_message"
exit 1
fi
echo "::debug::Parsing the response from: $request_url"
deployment=$(echo "$response" | jq -r --arg INPUT_SHA "$INPUT_SHA" '.deployments[] | select(.meta.githubCommitSha==$INPUT_SHA)')
id=$(echo "$deployment" | jq -r '.uid')
url=$(echo "$deployment" | jq -r '.url')
state=$(echo "$deployment" | jq -r '.state')
alias_error=$(echo "$deployment" | jq -r '.aliasError')
if [ "$state" = "READY" ]; then
deployment_ready=true
cat <<EOF >>"$GITHUB_OUTPUT"
id=$id
url=$url
state=$state
alias_error=$alias_error
EOF
break
fi
next=$(echo "$response" | jq -r '.pagination.next')
if [ "$next" != "null" ]; then
if [[ $request_url == *"&until="* ]]; then
# If "until" parameter already exists, replace it
# shellcheck disable=SC2001
request_url=$(echo "$request_url" | sed "s/until=[0-9]*/until=$next/")
else
# If "until" parameter does not exist, add it
request_url="$request_url&until=$next"
fi
else
break
fi
done
if [ "$deployment_ready" = false ]; then
echo "::error::Deployment did not become ready within the specified timeout of: $INPUT_TIMEOUT seconds"
exit 1
fi