Force a non-lazy run if global.ini has changed
[puppet-git.git] / ppg-update-production
blobba3ddcad7ce8a86b044927d84dbe51bab28ad1a2
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 production_sha1=$(git rev-parse --revs-only refs/heads/production 2>/dev/null)
17 if [ -z "$production_sha1" ]; then
18 # no production branch, nothing to do
19 exit 0
22 orig_production_sha1=$(git rev-parse --revs-only origin/production)
23 # default target
24 target_sha1=$orig_production_sha1
26 nowepoch=$(date --utc +%s)
27 for tag in $(git tag -l | grep '^ppg-sched-' | sort -r); do
28 # Sneaky sed: 's/-/ /3g' replaces the 3rd dash only
29 datestamp=$(echo "$tag"|sed 's/^ppg-sched-//;s/-/ /3g;s/\./:/g;')
30 tagepoch=$(date -d "$datestamp" +%s)
31 if [[ $tagepoch -lt $nowepoch ]]; then
32 targettag=$tag
34 done
36 if [ -n "$targettag" ]; then
37 target_sha1=$(git rev-parse --revs-only ${targettag}^{commit} ) || exit 1
39 # perhaps origin/production is ahead of scheduled tags,
40 # if so, it wins...
42 if [ -n "$orig_production_sha1" ]; then
43 if $PPG_EXEC_PATH/ppg-is-ancestor $targettag $orig_production_sha1 ; then
44 target_sha1=$orig_production_sha1
49 if [ "$production_sha1" = "$target_sha1" ]; then
50 # nothing to do
51 exit 0
54 if ! $PPG_EXEC_PATH/ppg-is-ancestor $production_sha1 $target_sha1 ; then
55 echo "ERROR: production branch and $targettag have diverged!"
56 exit 1
59 headname=$(git rev-parse --symbolic-full-name --revs-only HEAD)
61 if [ "$headname" = 'refs/heads/production' ]; then
62 # sanity checks when on production
63 if [ $(git diff --name-status HEAD | wc -l) -gt 0 ]; then
64 echo >&2 'ERROR: Currently on "production" branch and with dirty state.'
65 echo >&2 " Refusing to update with scheduled changes."
66 exit 1
70 echo "About to update production with scheduled changes:"
71 git --no-pager log --oneline -n 100 refs/heads/production..$target_sha1
73 # and finally
74 if [ "$headname" = 'refs/heads/production' ]; then
75 echo "Updating current production checkout"
76 git merge --ff-only $target_sha1
77 exit $?
78 else
79 git push . $target_sha1:refs/heads/production
80 exit $?