Merge pull request #54 from pratik-joshi/CRM-11960
[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
8 if [ ! -f "$confdir/releaser.conf" ]; then
9 echo
10 echo "Missing configuration file. Please copy $confdir/releaser.conf.txt to $confdir/releaser.conf and edit it."
11 exit 1
12 fi
13 source "$confdir/releaser.conf"
14
15 if [ -z "$version" -o -z "$start_point" ]; then
16 echo
17 echo "Usage: $0 <start_point> <version>"
18 echo " <start_point> is a branch name (e.g. \"master\")"
19 echo " <version> is Civi release (e.g. \"4.2.beta2\"); it will become a tag name"
20 exit 2
21 fi
22
23 if [ "`echo -n $version | tr -d 0-9.`" = '' ]; then
24 is_stable=1
25 else
26 is_stable=
27 fi
28
29 set -ex
30
31 #################################################
32 ## Git setup
33 function do_git_config() {
34 git config --global user.name "$git_author_name"
35 git config --global user.email "$git_author_email"
36 }
37
38 #################################################
39 ## Create build directories; checkout repos
40 function do_mk_project() {
41 for dir in \
42 "$workdir" \
43 "$workdir/$version" \
44 "$workdir/$version/export" \
45 "$workdir/$version/gen" \
46 "$workdir/$version/tarballs" \
47 "$workdir/$version/tmp"
48 do
49 if [ ! -d "$dir" ]; then
50 mkdir -p "$dir"
51 fi
52 done
53
54 $cmd_gitify all "$git_base_url" "$workdir/$version/export" --l10n
55 }
56
57 #################################################
58 ## Tag all repos
59 function do_git_tag() {
60 cd $workdir/$version
61 for dir in export export/joomla export/WordPress export/packages ; do
62 pushd $dir
63 git checkout "$start_point"
64 git tag "$version"
65 popd
66 done
67
68 for drupal_ver in 6.x 7.x ; do
69 pushd export/drupal
70 git checkout "${drupal_ver}-${start_point}"
71 git tag "${drupal_ver}-${version}"
72 popd
73 done
74 }
75
76 #################################################
77 ## Publish tags via git
78 function do_git_tag_push() {
79 cd $workdir/$version
80 for dir in export export/joomla export/WordPress export/packages ; do
81 pushd $dir
82 git push -f origin "$version"
83 popd
84 done
85
86 for drupal_ver in 6.x 7.x ; do
87 pushd export/drupal
88 git push -f origin "${drupal_ver}-${version}"
89 popd
90 done
91 }
92
93 #################################################
94 ## Build
95 function do_distmaker() {
96 cd $workdir/$version
97
98 ## Determine SCM revision of main codebase
99 pushd "export"
100 rev=$(git rev-parse HEAD | head -c10)
101 popd
102
103 # create the distmaker.conf file
104 echo "
105 DM_SOURCEDIR=$workdir/$version/export
106 DM_GENFILESDIR=$workdir/$version/gen
107 DM_TMPDIR=$workdir/$version/tmp
108 DM_TARGETDIR=$workdir/$version/tarballs
109 DM_PHP=$cmd_php
110 DM_RSYNC=$cmd_rsync
111 DM_VERSION=$version
112 DM_REVISION=$rev
113 DM_ZIP=$cmd_zip
114 " > $workdir/$version/export/distmaker/distmaker.conf
115
116 # create a minimal civicrm.settings.php file
117 mkdir -p $workdir/$version/export/default
118 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
119
120 # create a minimal settings_location.php file
121 echo "<?php define('CIVICRM_CONFDIR', '$workdir/$version/export'); ?>" > $workdir/$version/export/settings_location.php
122
123 # run the exported distmaker
124 cd $workdir/$version/export/distmaker
125 ./distmaker.sh all > $workdir/$version/build.log
126 }
127
128 #################################################
129 ## Publish files
130 function do_publish() {
131 # publish to sf.net
132 cd $workdir/$version/tarballs
133
134 $cmd_md5sum *.tar.gz *.zip > civicrm-$version.MD5SUMS
135 echo $cmd_gpg_pass | $cmd_gpg --armor --batch --passphrase-fd 0 --sign civicrm-$version.MD5SUMS
136
137 if [ "$is_stable" ]; then
138 echo mkdir ${publish_stable_dir}/$version | $cmd_sftp ${publish_ssh}
139 $cmd_rsync -aP --exclude='*starterkit.tgz' *.tar.gz *.zip *MD5SUMS* ${publish_ssh}:${publish_stable_dir}/$version
140 else
141 echo mkdir ${publish_latest_dir}/$version | $cmd_sftp ${publish_ssh}
142 $cmd_rsync -aP --exclude='*starterkit.tgz' *.tar.gz *.zip *MD5SUMS* ${publish_ssh}:${publish_latest_dir}/$version
143 fi
144
145 mv *.tar.gz *.zip *MD5SUMS* $build_dest
146
147 # publish to latest.civicrm.org
148 # FIXME: isn't this racy when doing concurrent security releases
149 if [ "$is_stable" ]; then
150 echo $version > $latest/stable.txt
151 fi
152 echo $version > $latest/latest.txt
153 }
154
155 #################################################
156 ## Cleanup
157 function do_cleanup() {
158 cd $workdir/$version
159 rm -rf export gen tmp tarballs tmp
160 }
161
162 #################################################
163 ## Main
164
165 ## Refactoring note: this used to be one monolithic script
166
167 do_git_config
168 do_mk_project
169 do_git_tag
170 do_distmaker
171 do_git_tag_push
172 do_publish
173 do_cleanup