3 if [[ -n "${PPG_DEBUG}" ]]; then
7 PPG_EXEC_PATH=$( dirname $(realpath "${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"
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!"
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:
30 (git tag --points-at HEAD && git tag --points-at HEAD) | sort -u
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"
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
50 echo Scheduling to deploy commit
52 git log --oneline --stat -n1
54 echo On the following time/date:
57 /usr/bin/date -d "@${epoch}"
59 /usr/bin/date --utc -d "@${epoch}"
61 echo -n "is this correct? [Ny] "
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"
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;')
76 ### FIXME - Add support for tag messages and scheduling something other
77 ### than HEAD while still providing useful sanity checks...
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
89 echo 'Checking for scheduled updates to the production branch...'
90 $PPG_EXEC_PATH/ppg-update-production
92 echo 'Applied "ppg-sched-$tagdatestamp" tag successfully - you must now use'
94 echo ' git push --tags'
96 echo 'to ensure the scheduled changes are published on the gold server.'