]> git.immae.eu Git - github/fretlink/ansible-clever.git/blame - files/clever-wait-deploy.sh
Use Nix for build
[github/fretlink/ansible-clever.git] / files / clever-wait-deploy.sh
CommitLineData
f7dd5848
GD
1#!/bin/bash -e
2
3function deploying {
4 checkStatus "$1" "IN PROGRESS"
5}
6
7function deployed {
8 checkStatus "$1" "OK"
9}
10
11function inactive {
12 local commit="$1"
13 [[ "$(clever activity | grep "$commit" | grep "DEPLOY" | wc -l)" == "0" ]]
14}
15
16function checkStatus {
17 local commit="$1"
18 local status="$2"
19 [[ "$(clever activity | grep "$commit" | grep "${status}\s\+DEPLOY" | wc -l)" == "1" ]]
20}
21
22function check {
23 local timeout=600 # 10 minutes
24 local commit="$1"
25 local samplingTime=5
26
27 echo "Waiting for deployment start..."
28 while inactive "$commit" -a $timeout -gt 0
29 do
30 sleep $samplingTime
31 let "timeout-=$samplingTime"
32 done
33
34 # Wait for completion
cefea119 35 echo "Deployment in progress..."
f7dd5848
GD
36 while deploying "$commit" -a $timeout -gt 0
37 do
38 sleep $samplingTime
39 let "timeout-=$samplingTime"
40 done
41
42 if [ $samplingTime -eq 0 ]
43 then
44 echo "Timeout"
45 fi
46
47 deployed "$commit"
48}
49
50check "$(git rev-parse HEAD)"