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