Merge remote-tracking branch 'upstream/4.3' into 4.3-master-2013-04-23-15-17-29
[civicrm-core.git] / tools / scripts / releaser / releaser
1 #!/bin/bash
2 set -e
3
4 confdir=$(dirname $0)
5 start_point="$1"
6 version="$2"
7 first_act="$3"
8 distmaker_tgt=all
9
10 if [ ! -f "$confdir/releaser.conf" ]; then
11 echo
12 echo "Missing configuration file. Please copy $confdir/releaser.conf.txt to $confdir/releaser.conf and edit it."
13 exit 1
14 fi
15 source "$confdir/releaser.conf"
16
17 if [ -z "$start_point" -o -z "$version" -o -z "$first_act" ]; then
18 echo
19 echo "Usage:"
20 echo " $0 <start_point> <version> --build"
21 echo " $0 <start_point> <version> --publish"
22 echo " $0 <start_point> <version> --update"
23 echo " $0 <start_point> <version> --clean"
24 echo " $0 <start_point> <version> --build --publish --update --clean [[ORDER SIGNIFICANT]]"
25 echo "Arguments:"
26 echo " <start_point> is a branch name (e.g. \"master\")"
27 echo " <version> is Civi release (e.g. \"4.3.beta2\"); it will become a tag name"
28 exit 2
29 fi
30
31 if [ "`echo -n $version | tr -d 0-9.`" = '' ]; then
32 is_stable=1
33 else
34 is_stable=
35 fi
36
37 #################################################
38 ## Git setup
39 function do_git_config() {
40 git config --global user.name "$git_author_name"
41 git config --global user.email "$git_author_email"
42 }
43
44 #################################################
45 ## Create build directories; checkout repos
46 function do_mk_project() {
47 for dir in \
48 "$workdir" \
49 "$workdir/$version" \
50 "$workdir/$version/export" \
51 "$workdir/$version/gen" \
52 "$workdir/$version/tarballs" \
53 "$workdir/$version/tmp"
54 do
55 if [ ! -d "$dir" ]; then
56 mkdir -p "$dir"
57 fi
58 done
59
60 $cmd_gitify all "$git_base_url" "$workdir/$version/export" --l10n
61 }
62
63 #################################################
64 ## Tag all repos
65 function do_git_tag() {
66 cd $workdir/$version
67 for dir in export export/joomla export/WordPress export/packages ; do
68 pushd $dir
69 git checkout "$start_point"
70 git tag "$version"
71 popd
72 done
73
74 for drupal_ver in 6.x 7.x ; do
75 pushd export/drupal
76 git checkout "${drupal_ver}-${start_point}"
77 git tag "${drupal_ver}-${version}"
78 popd
79 done
80 }
81
82 #################################################
83 ## Publish tags via git
84 function do_git_tag_push() {
85 cd $workdir/$version
86 for dir in export export/joomla export/WordPress export/packages ; do
87 pushd $dir
88 git push -f origin "$version"
89 popd
90 done
91
92 for drupal_ver in 6.x 7.x ; do
93 pushd export/drupal
94 git push -f origin "${drupal_ver}-${version}"
95 popd
96 done
97 }
98
99 #################################################
100 ## Build
101 function do_distmaker() {
102 cd $workdir/$version
103
104 ## Determine SCM revision of main codebase
105 pushd "export"
106 rev=$(git rev-parse HEAD | head -c10)
107 popd
108
109 # create the distmaker.conf file
110 echo "
111 DM_SOURCEDIR=$workdir/$version/export
112 DM_GENFILESDIR=$workdir/$version/gen
113 DM_TMPDIR=$workdir/$version/tmp
114 DM_TARGETDIR=$workdir/$version/tarballs
115 DM_PHP=$cmd_php
116 DM_RSYNC=$cmd_rsync
117 DM_VERSION=$version
118 DM_REVISION=$rev
119 DM_ZIP=$cmd_zip
120 DM_REF_CORE=${start_point}
121 DM_REF_DRUPAL=7.x-${start_point}
122 DM_REF_DRUPAL6=6.x-${start_point}
123 DM_REF_JOOMLA=${start_point}
124 DM_REF_WORDPRESS=${start_point}
125 DM_REF_PACKAGES=${start_point}
126 " > $workdir/$version/export/distmaker/distmaker.conf
127
128 # create a minimal civicrm.settings.php file
129 mkdir -p $workdir/$version/export/default
130 echo "<?php define('CIVICRM_GETTEXT_RESOURCEDIR', '$workdir/$version/export/l10n/'); define('CIVICRM_UF', 'Drupal'); global \$civicrm_root; \$civicrm_root = '$workdir/$version/export'; ?>" > $workdir/$version/export/default/civicrm.settings.php
131
132 # create a minimal settings_location.php file
133 echo "<?php define('CIVICRM_CONFDIR', '$workdir/$version/export'); ?>" > $workdir/$version/export/settings_location.php
134
135 # run the exported distmaker
136 cd $workdir/$version/export/distmaker
137 ./distmaker.sh $distmaker_tgt > $workdir/$version/build.log
138 }
139
140 #################################################
141 ## Publish files
142 function do_publish() {
143 # publish to sf.net
144 cd $workdir/$version/tarballs
145
146 $cmd_md5sum *.tar.gz *.tgz *.zip > civicrm-$version.MD5SUMS
147 echo $gpg_pass | $cmd_gpg --armor --batch --passphrase-fd 0 --sign civicrm-$version.MD5SUMS
148
149 if [ "$is_stable" ]; then
150 echo mkdir ${publish_stable_dir}/$version | $cmd_sftp ${publish_ssh}
151 $cmd_rsync -aP --exclude='*starterkit.tgz' *.tar.gz *.zip *MD5SUMS* ${publish_ssh}:${publish_stable_dir}/$version
152 else
153 echo mkdir ${publish_latest_dir}/$version | $cmd_sftp ${publish_ssh}
154 $cmd_rsync -aP --exclude='*starterkit.tgz' *.tar.gz *.zip *MD5SUMS* ${publish_ssh}:${publish_latest_dir}/$version
155 fi
156
157 mv *.tar.gz *.tgz *.zip *MD5SUMS* $build_dest
158
159 # publish to latest.civicrm.org
160 # FIXME: isn't this racy when doing concurrent security releases
161 if [ "$is_stable" ]; then
162 echo $version > $latest/stable.txt
163 fi
164 echo $version > $latest/latest.txt
165 }
166
167 #################################################
168 ## Update Version Info
169 function do_update() {
170 echo "VERSION UPDATE: Enter the version that comes after $version (or enter nothing to abort)"
171 read new_ver
172 if [ -n "$new_ver" ]; then
173 cd $workdir/$version/export
174 # escape regex special chars
175 arg=`echo "$version" | sed 's:[]\[\^\$\.\*\/]:\\\\&:g'`
176 for file in xml/version.xml sql/civicrm_generated.mysql; do
177 set -ex
178 git checkout $file
179 sed "s/$arg/$new_ver/" < $file > $file.tmp
180 mv $file.tmp $file
181 set +x
182 done
183 # print the diff directly to the screen
184 git diff | cat
185 echo "Push these changes? y/n"
186 read input
187 if [ "$input" = "y" ]; then
188 set -ex
189 git add xml/version.xml sql/civicrm_generated.mysql
190 git commit -m "Update version to $new_ver"
191 git push origin "$start_point"
192 set +x
193 else
194 do_update
195 fi
196 else
197 echo "No version entered. Aborting version update."
198 fi
199 }
200
201 #################################################
202 ## Cleanup
203 function do_cleanup() {
204 cd $workdir/$version
205 rm -rf export gen tmp tarballs tmp
206 }
207
208 #################################################
209 ## Main
210
211 ## Refactoring note: this used to be one monolithic script
212
213 shift ## start point
214 shift ## version
215 for ACT in "$@" ; do
216 case "$ACT" in
217 --build)
218 set -ex
219 do_git_config
220 do_mk_project
221 do_git_tag
222 do_distmaker
223 set +x
224 ;;
225 --publish)
226 set -ex
227 do_git_tag_push
228 do_publish
229 set +x
230 ;;
231 --update)
232 set +x
233 do_update
234 ;;
235 --clean)
236 set -ex
237 do_cleanup
238 set +x
239 ;;
240 *)
241 echo "unrecognized: $ACT"
242 ;;
243 esac
244 done
245