ppg-update-production: delete stale/broken conditional
[puppet-git.git] / ppg-schedule
blob45049a89b08735d0cb450aec686614f866bf32fc
1  #!/bin/bash
3 if [[ -n "${PPG_DEBUG}" ]]; then
4         set -x
5 fi
7 PPG_EXEC_PATH=$( dirname $(readlink -f "${BASH_SOURCE[0]}" ) )
8 GIT_EXEC_PATH=$(git --exec-path)
9 GIT_DIR=$(git rev-parse --git-dir)
11 if [ -z "$GIT_DIR" ]; then
12         echo >&2 "Not in a git checkout"
13         exit 1
16 datestr=$1
18 # sanity-check we are on master
19 headname=$(git rev-parse --symbolic-full-name --revs-only HEAD)
20 if [ "$headname" != "refs/heads/master" ]; then
21         echo >&2 "ERROR: can only schedule from the master branch!"
22         exit 1
25 # sanity check whether is already scheduled
26 if (git tag --points-at HEAD && git tag --points-at HEAD) \
27         |grep -qc '^ppg-sched-' ; then
28         echo ERROR: This commit is already scheduled with these tags:
29     echo 
30         (git tag --points-at HEAD && git tag --points-at HEAD) | sort -u
31     echo
32         exit 1
35 # use /usr/bin/date to interpret the date. it is
36 # suprisingly powerful
37 epoch=$(/usr/bin/date -d "$datestr" +%s) || exit 1
38 now=$(/usr/bin/date +%s)
39 if [[ $epoch -lt $now ]]; then
40         echo >&2 $(/usr/bin/date -d "@${epoch}") "is in the past"
41     exit 1
43 ###
44 ### TODO: FIXME: do not asume we are only deploying one commit!
45 ###              should check production branch _and_ tags
46 ###              to spot the log between the latest priorly
47 ###              scheduled commit
48 ###
49 echo 
50 echo Scheduling to deploy commit
51 echo
52 git log --oneline --stat -n1
53 echo
54 echo On the following time/date:
55 echo
56 echo -n "     "
57 /usr/bin/date -d "@${epoch}"
58 echo -n "     "
59 /usr/bin/date --utc -d "@${epoch}"
60 echo 
61 echo -n "is this correct? [Ny] "
62 read correct
63 if [[ "${correct:0:1}" != 'Y' ]] && [[ "${correct:0:1}" != 'y' ]]; then
64      echo Cancelling schedule. You can check your datatestamp with
65      echo /usr/bin/date -d "your datestamp"
66      exit 1
69 # sed: 
70 # - trim the tz (everything after the +)
71 # - replace spaces with '-', ':'' with '.''
72 tagdatestamp=$(date --rfc-3339=seconds --utc\
73         |sed 's/+.*//;s/ /-/g;s/:/./g;')
75 ###
76 ### FIXME - Add support for tag messages and scheduling something other
77 ###         than HEAD while still providing useful sanity checks...
78 ###
80 # validate is not earlier than any existing timestamps
81 if ! ( (git tag -l|grep 'ppg-sched'|sort&&echo "ppg-sched-$tagdatestamp")\
82         |sort --check=quiet ) ; then
83         last_tag=$(git tag -l | grep 'ppg-sched' | sort | tail -n1)
84         echo "Error: your change cannot be scheduled earlier than $last_tag."
86 git tag "ppg-sched-$tagdatestamp" HEAD || exit 1
88 echo 
89 echo 'Checking for scheduled updates to the production branch...'
90 $PPG_EXEC_PATH/ppg-update-production
91 echo
92 echo 'Applied "ppg-sched-$tagdatestamp" tag successfully - you must now use'
93 echo
94 echo '    git push --tags'
95 echo 
96 echo 'to ensure the scheduled changes are published on the gold server.'