-
Notifications
You must be signed in to change notification settings - Fork 0
/
_wait_for_import.sh
executable file
·67 lines (52 loc) · 1.14 KB
/
_wait_for_import.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
#!/bin/bash
set -e
if [ $# -ne 1 ]; then
echo "Usage: $0 <id>"
exit 1
fi
id=$1
sleeptime=(10 15 20 25 30 10 40 15 50 55 60)
sleepidx=0
function getState() {
id=$1
local state
state=$(GITHUB_TOKEN=$TARGET_PAT gh api graphql \
-F id="$id" \
-f query='query ($id: ID!) {
node(id: $id) {
... on Migration {
id
state
failureReason
}
}
}' -q .data.node.state)
if [ -z "$state" ]; then
>&2 echo "Failed to get state for migration $id"
exit 1
fi
if [ "$state" == "FAILED" ] || [ "$state" == "FAILED_VALIDATION" ]; then
>&2 echo "import failed, no need to wait for it. Dumping status:"
>&2 GITHUB_TOKEN=$TARGET_PAT gh api graphql \
-F id="$id" \
-f query='query ($id: ID!) {
node(id: $id) {
... on Migration {
id
state
failureReason
}
}
}'
exit 1
fi
echo "$state"
}
while [ "$state" != "SUCCEEDED" ] ; do
sleepvalue=${sleeptime[$sleepidx]}
echo " sleeping for ${sleepvalue} seconds"
sleep "${sleepvalue}"s
state=$(getState "$id") || exit 1
echo " state=$state"
sleepidx=$(((sleepidx + 1) % ${#sleeptime[@]}))
done