Add 'update' to releaser script
[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 # FIXME: This assumes one-digit point versions
171 point=(${version: -1})
172 point=`expr $point + 1`
173 new_ver=(${version:0:4})
174 new_ver=$new_ver$point
175 cd $workdir/$version/export
176 sed -i -e "s/$version/$new_ver/g" xml/version.xml
177 sed -i -e "s/$version/$new_ver/g" sql/civicrm_generated.mysql
178 git add xml/version.xml sql/civicrm_generated.mysql
179 git commit -m "Update version to $new_ver"
180 git push origin "$version"
181 }
182
183 #################################################
184 ## Cleanup
185 function do_cleanup() {
186 cd $workdir/$version
187 rm -rf export gen tmp tarballs tmp
188 }
189
190 #################################################
191 ## Main
192
193 ## Refactoring note: this used to be one monolithic script
194
195 shift ## start point
196 shift ## version
197 for ACT in "$@" ; do
198 case "$ACT" in
199 --build)
200 set -ex
201 do_git_config
202 do_mk_project
203 do_git_tag
204 do_distmaker
205 set +x
206 ;;
207 --publish)
208 set -ex
209 do_git_tag_push
210 do_publish
211 set +x
212 ;;
213 --update)
214 set -ex
215 do_update
216 set +x
217 ;;
218 --clean)
219 set -ex
220 do_cleanup
221 set +x
222 ;;
223 *)
224 echo "unrecognized: $ACT"
225 ;;
226 esac
227 done
228