-
Notifications
You must be signed in to change notification settings - Fork 0
/
ppg-schedule
executable file
·96 lines (85 loc) · 2.64 KB
/
ppg-schedule
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
if [[ -n "${PPG_DEBUG}" ]]; then
set -x
fi
PPG_EXEC_PATH=$( dirname $(readlink -f "${BASH_SOURCE[0]}" ) )
GIT_EXEC_PATH=$(git --exec-path)
GIT_DIR=$(git rev-parse --git-dir)
if [ -z "$GIT_DIR" ]; then
echo >&2 "Not in a git checkout"
exit 1
fi
datestr=$1
# sanity-check we are on master
headname=$(git rev-parse --symbolic-full-name --revs-only HEAD)
if [ "$headname" != "refs/heads/master" ]; then
echo >&2 "ERROR: can only schedule from the master branch!"
exit 1
fi
# sanity check whether is already scheduled
if (git tag --points-at HEAD && git tag --points-at HEAD) \
|grep -qc '^ppg-sched-' ; then
echo ERROR: This commit is already scheduled with these tags:
echo
(git tag --points-at HEAD && git tag --points-at HEAD) | sort -u
echo
exit 1
fi
# use /usr/bin/date to interpret the date. it is
# suprisingly powerful
epoch=$(/usr/bin/date -d "$datestr" +%s) || exit 1
now=$(/usr/bin/date +%s)
if [[ $epoch -lt $now ]]; then
echo >&2 $(/usr/bin/date -d "@${epoch}") "is in the past"
exit 1
fi
###
### TODO: FIXME: do not asume we are only deploying one commit!
### should check production branch _and_ tags
### to spot the log between the latest priorly
### scheduled commit
###
echo
echo Scheduling to deploy commit
echo
git log --oneline --stat -n1
echo
echo On the following time/date:
echo
echo -n " "
/usr/bin/date -d "@${epoch}"
echo -n " "
/usr/bin/date --utc -d "@${epoch}"
echo
echo -n "is this correct? [Ny] "
read correct
if [[ "${correct:0:1}" != 'Y' ]] && [[ "${correct:0:1}" != 'y' ]]; then
echo Cancelling schedule. You can check your datatestamp with
echo /usr/bin/date -d "your datestamp"
exit 1
fi
# sed:
# - trim the tz (everything after the +)
# - replace spaces with '-', ':'' with '.''
tagdatestamp=$(date --rfc-3339=seconds --utc\
|sed 's/+.*//;s/ /-/g;s/:/./g;')
###
### FIXME - Add support for tag messages and scheduling something other
### than HEAD while still providing useful sanity checks...
###
# validate is not earlier than any existing timestamps
if ! ( (git tag -l|grep 'ppg-sched'|sort&&echo "ppg-sched-$tagdatestamp")\
|sort --check=quiet ) ; then
last_tag=$(git tag -l | grep 'ppg-sched' | sort | tail -n1)
echo "Error: your change cannot be scheduled earlier than $last_tag."
fi
git tag "ppg-sched-$tagdatestamp" HEAD || exit 1
echo
echo 'Checking for scheduled updates to the production branch...'
$PPG_EXEC_PATH/ppg-update-production
echo
echo 'Applied "ppg-sched-$tagdatestamp" tag successfully - you must now use'
echo
echo ' git push --tags'
echo
echo 'to ensure the scheduled changes are published on the gold server.'