~percona-toolkit-dev/percona-toolkit/docu-ptc-rbr-limitation

« back to all changes in this revision

Viewing changes to util/build-snapshot

  • Committer: Daniel Nichter
  • Date: 2012-07-10 19:16:27 UTC
  • mto: This revision was merged to the branch mainline in revision 307.
  • Revision ID: daniel@percona.com-20120710191627-qkw4lt0ipdh04t43
Create util/build-snapshot and ignore /snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env bash
 
2
 
 
3
# This script builds a snapshot: a lightweight tarball of the current
 
4
# bzr branch _without_ updating the changelog, docs, etc.  Snapshots
 
5
# are meant to allow early access and real-world testing by Percona
 
6
# support staff.  They're fetched from percona.com/trunk/.
 
7
#
 
8
# The current version of the tools is used plus "-snapshot-YYYY.MM.DD"
 
9
# to indicate that it's a snapshot, not a full release.
 
10
 
 
11
# ############################################################################
 
12
# Standard startup, find the branch's root directory
 
13
# ############################################################################
 
14
 
 
15
set -ue # bail out on errors, be strict
 
16
 
 
17
EXIT_STATUS=0
 
18
 
 
19
die() {
 
20
   echo "$1" >&2
 
21
   exit 1
 
22
}
 
23
 
 
24
warn() {
 
25
   echo "$1" >&2
 
26
   EXIT_STATUS=1
 
27
}
 
28
 
 
29
CWD=$PWD
 
30
PERCONA_TOOLKIT_BRANCH=${PERCONA_TOOLKIT_BRANCH:-""}
 
31
if [ -n "$PERCONA_TOOLKIT_BRANCH" ]; then
 
32
   BRANCH=$PERCONA_TOOLKIT_BRANCH
 
33
   cd $BRANCH
 
34
else
 
35
   while [ ! -f Makefile.PL ] && [ $PWD != "/" ]; do
 
36
      cd ..
 
37
   done
 
38
   if [ ! -f Makefile.PL ]; then
 
39
      die "Cannot find the root directory of the Percona Toolkit branch"
 
40
   fi
 
41
   BRANCH=`pwd`
 
42
fi
 
43
cd $CWD
 
44
 
 
45
# ############################################################################
 
46
# Paths
 
47
# ############################################################################
 
48
 
 
49
SNAPSHOT_DIR=$BRANCH/snapshot
 
50
 
 
51
# ############################################################################
 
52
# Programs and their options
 
53
# ############################################################################
 
54
 
 
55
TAR=${TAR:-tar}
 
56
 
 
57
# ############################################################################
 
58
# Subroutines
 
59
# ############################################################################
 
60
 
 
61
prep_release_dir() {
 
62
   echo -n "Preparing $SNAPSHOT_DIR... "
 
63
   cd $BRANCH
 
64
 
 
65
   # Make temp snapshot dir so we can copy and modify files in it
 
66
   # without affecting the underlying bzr branch because, unlike
 
67
   # a release, we don't want to commit anything, but we do want
 
68
   # to modify stuff, namely the tools' version. 
 
69
   if [ ! -d $SNAPSHOT_DIR ]; then
 
70
      mkdir $SNAPSHOT_DIR
 
71
   elif [ -d $SNAPSHOT_DIR/$PKG ]; then
 
72
      rm -rf $SNAPSHOT_DIR/$PKG/*
 
73
   fi
 
74
 
 
75
   # Copy the tools, of course.   
 
76
   mkdir -p $SNAPSHOT_DIR/$PKG/bin
 
77
   cp bin/* $SNAPSHOT_DIR/$PKG/bin
 
78
 
 
79
   # Copy the originals of these files for reference.
 
80
   for file in Changelog COPYING README; do
 
81
      cp $file $SNAPSHOT_DIR/$PKG
 
82
   done
 
83
 
 
84
   # Pretend that someone will actually read this special readme
 
85
   # and discover that this isn't a full release.
 
86
   echo >$SNAPSHOT_DIR/$PKG/README.SNAPSHOT <<README
 
87
This is a snapshot of Percona Toolkit created on $DATE, based on the full $VERSION release.  Snapshots are previews of the current code and should only be used for testing.  The code in this snapshot can change or be removed in later snapshots and is no guarantee of what will be included in the next full release.  Contact Percona (http://www.percona.com/) if you have any questions.
 
88
 
 
89
The README and Changelog from the full $VERSION release are included for reference.  See DIFF for a diff of all changes since the $VERSION release.
 
90
README
 
91
   
 
92
   echo "OK"
 
93
 
 
94
   # Make a diff of all changes since the last full release.
 
95
   # This may be long, but it shows what actually has changed
 
96
   # in this snapshot (otherwise one needs access to lp/bzr).
 
97
   # This can take a few seconds, so it gets its own status line.
 
98
   local last_release_rev=$(bzr tags | tail -n 1 | awk '{print $2 + 1}')
 
99
   local cmd="bzr log -r$last_release_rev.. --show-diff"
 
100
   echo -n "Creating DIFF ($cmd)... "
 
101
   $cmd > $SNAPSHOT_DIR/$PKG/DIFF
 
102
   echo "OK"
 
103
}
 
104
 
 
105
update_manifest() {
 
106
   echo -n "Updating MANIFEST... "
 
107
   # Just in case someone actually uses/trusts the manifest.
 
108
   cd $SNAPSHOT_DIR/$PKG
 
109
   echo -n > MANIFEST
 
110
   for file in * bin/*; do
 
111
      if [ -f $file ]; then
 
112
         echo $file >> MANIFEST
 
113
      fi
 
114
   done
 
115
   echo "OK"
 
116
}
 
117
 
 
118
update_version() {
 
119
   echo -n "Updating version in tools... "
 
120
   cd $SNAPSHOT_DIR/$PKG/bin
 
121
   for tool_file in *; do
 
122
      sed -i'.bak' -e "s/^$tool_file [0-9]\.[0-9][^ ]\+/$tool_file $SNAPSHOT_VERSION/" $tool_file
 
123
      if [ $? -ne 0 ]; then
 
124
         die "Error updating version in $tool_file"
 
125
      fi
 
126
      rm "$tool_file.bak"
 
127
   done
 
128
 
 
129
   local new_versions=$(grep --no-filename '^pt-[^ ]\+ [0-9]\.' * | cut -d' ' -f2 | sort -u)
 
130
   if [ "$new_versions" != "$SNAPSHOT_VERSION" ]; then
 
131
      die "The version in some tools did not update correctly"
 
132
   fi
 
133
   echo "OK"
 
134
}
 
135
 
 
136
build_tar() {
 
137
   echo -n "Building $PKG.tar.gz... "
 
138
   cd $SNAPSHOT_DIR
 
139
   $TAR czf "$PKG.tar.gz" $PKG
 
140
   echo "OK"
 
141
}
 
142
 
 
143
# ############################################################################
 
144
# Script starts here
 
145
# ############################################################################
 
146
 
 
147
if [ $# -gt 0 ]; then
 
148
   die "Usage: $0"
 
149
fi
 
150
 
 
151
VERSION=$(awk '/VERSION/ {print $3; exit;}' $BRANCH/Makefile.PL | sed -e "s/[',]//g")
 
152
DATE=$(date -u +'%Y.%m.%d')
 
153
SNAPSHOT_VERSION="$VERSION-snapshot-$DATE"
 
154
PKG="percona-toolkit-$SNAPSHOT_VERSION"
 
155
 
 
156
prep_release_dir
 
157
update_manifest
 
158
update_version
 
159
build_tar
 
160
 
 
161
if [ -d $SNAPSHOT_DIR/$PKG ]; then
 
162
   rm -rf  $SNAPSHOT_DIR/$PKG
 
163
fi
 
164
 
 
165
if [ $EXIT_STATUS -eq 0 ] && [ -f "$SNAPSHOT_DIR/$PKG.tar.gz" ]; then
 
166
   echo "Snapshot built successfully:"
 
167
   echo "$SNAPSHOT_DIR/$PKG.tar.gz"
 
168
else
 
169
   warn "Error building snapshot"
 
170
fi
 
171
 
 
172
exit $EXIT_STATUS