]> git.immae.eu Git - github/fretlink/ansible-clever.git/blame - files/clever-wait-deploy.sh
deploy: revert back to git push + polling
[github/fretlink/ansible-clever.git] / files / clever-wait-deploy.sh
CommitLineData
fa045db6
PB
1#!/usr/bin/env bash
2
3set -ueo pipefail
4
5VERBOSE=${VERBOSE:-}
6lastCleverActivity=""
7
8function cleverActivity {
9 lastCleverActivity=$(clever activity)
10}
11
12function ensure {
13 if [ "$?" == "1" ]
14 then
15 echo "✗ Deployment failed!"
16 fi
17 VERBOSE=true
18 verbose
19}
20
21trap ensure EXIT ERR
22
23function deploying {
24 checkStatus "$1" "IN PROGRESS"
25}
26
27function deployed {
28 checkStatus "$1" "OK"
29}
30
31function inactive {
32 checkStatus "$1" "" "-v"
33}
34
35function checkStatus {
36 local commit="$1"
37 local status="$2"
38
39 cleverActivity
40 echo "${lastCleverActivity}" | tail -n1 | grep ${3:+ "${3}"} -q -E "${status}.*DEPLOY.*${commit}"
41}
42
43function verbose {
44 if [ -n "${VERBOSE}" ]; then
45 echo -e "\\nLast clever activity:"
46 echo -e "${lastCleverActivity}\\n"
47 fi
48}
49
50function check {
51 local commit="$1"
52 local samplingTime=5
53
54 echo "️▫ Waiting for deployment to start..."
55 while inactive "$commit"
56 do
57 verbose
58 sleep $samplingTime
59 done
60
61 # Wait for completion
62 echo "▪ Deployment in progress..."
63 while deploying "$commit"
64 do
65 verbose
66 sleep $samplingTime
67 done
68
69 deployed "$commit"
70 echo "✓ Deployment done."
71}
72
73function getHeadRev {
74 local chdir="$1/.git"
75
76 git --git-dir="$chdir" rev-parse HEAD
77}
78
79workdir="$(pwd)"
80check "$(getHeadRev "${workdir}")"