From 60a4043130404dc230bcce0685019ae96620a489 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 6 Mar 2013 04:22:59 -0500 Subject: [PATCH] CRM-11658 - "releaser" for git - Changes from old "build-tarballs": * Fetch code with "gitify" * Make coordinated tags and push them (instead of using post-commit hook on single repo) * Extract hard-coded references to sf.net * Split into smaller functions (which are more explanatory and easier to toggle for testing) * Document configuration file format * Rename executable variables (e.g. $php => $cmd_php) * Use "set -ex" to catch errors --- .gitignore | 1 + tools/scripts/releaser/releaser | 171 +++++++++++++++++++++++ tools/scripts/releaser/releaser.conf.txt | 35 +++++ 3 files changed, 207 insertions(+) create mode 100755 tools/scripts/releaser/releaser create mode 100644 tools/scripts/releaser/releaser.conf.txt diff --git a/.gitignore b/.gitignore index c212ce4d64..0a73c2646e 100644 --- a/.gitignore +++ b/.gitignore @@ -137,6 +137,7 @@ WordPress joomla packages/ tests/phpunit/CiviTest/civicrm.settings.local.php +tools/scripts/releaser/releaser.conf l10n vendor civicrm.settings.php diff --git a/tools/scripts/releaser/releaser b/tools/scripts/releaser/releaser new file mode 100755 index 0000000000..599b609567 --- /dev/null +++ b/tools/scripts/releaser/releaser @@ -0,0 +1,171 @@ +#!/bin/bash +set -ex + +confdir=$(dirname $0) +start_point="$1" +version="$2" + +if [ ! -f "$confdir/releaser.conf" ]; then + echo + echo "Missing configuration file. Please copy $confdir/releaser.conf.txt to $confdir/releaser.conf and edit it." + exit 1 +fi +source "$confdir/releaser.conf" + +if [ -z "$version" -o -z "$start_point" ]; then + echo + echo "Usage: $0 " + echo " is a branch name (e.g. \"master\")" + echo " is Civi release (e.g. \"4.2.beta2\"); it will become a tag name" + exit 2 +fi + +if [ "`echo -n $version | tr -d 0-9.`" = '' ]; then + is_stable=1 +else + is_stable= +fi + +################################################# +## Git setup +function do_git_config() { + git config --global user.name "$git_author_name" + git config --global user.email "$git_author_email" +} + +################################################# +## Create build directories; checkout repos +function do_mk_project() { + for dir in \ + "$workdir" \ + "$workdir/$version" \ + "$workdir/$version/export" \ + "$workdir/$version/gen" \ + "$workdir/$version/tarballs" \ + "$workdir/$version/tmp" + do + if [ ! -d "$dir" ]; then + mkdir -p "$dir" + fi + done + + $cmd_gitify all "$git_base_url" "$workdir/$version/export" --l10n +} + +################################################# +## Tag all repos +function do_git_tag() { + cd $workdir/$version + for dir in export export/joomla export/WordPress export/packages ; do + pushd $dir + git checkout "$start_point" + git tag "$version" + popd + done + + for drupal_ver in 6.x 7.x ; do + pushd export/drupal + git checkout "${drupal_ver}-${start_point}" + git tag "${drupal_ver}-${version}" + popd + done +} + +################################################# +## Publish tags via git +function do_git_tag_push() { + cd $workdir/$version + for dir in export export/joomla export/WordPress export/packages ; do + pushd $dir + git push -f origin "$version" + popd + done + + for drupal_ver in 6.x 7.x ; do + pushd export/drupal + git push -f origin "${drupal_ver}-${version}" + popd + done +} + +################################################# +## Build +function do_distmaker() { + cd $workdir/$version + + ## Determine SCM revision of main codebase + pushd "export" + rev=$(git rev-parse HEAD | head -c10) + popd + + # create the distmaker.conf file + echo " + DM_SOURCEDIR=$workdir/$version/export + DM_GENFILESDIR=$workdir/$version/gen + DM_TMPDIR=$workdir/$version/tmp + DM_TARGETDIR=$workdir/$version/tarballs + DM_PHP=$cmd_php + DM_RSYNC=$cmd_rsync + DM_VERSION=$version + DM_REVISION=$rev + DM_ZIP=$cmd_zip + " > $workdir/$version/export/distmaker/distmaker.conf + + # create a minimal civicrm.settings.php file + mkdir -p $workdir/$version/export/default + echo "" > $workdir/$version/export/default/civicrm.settings.php + + # create a minimal settings_location.php file + echo "" > $workdir/$version/export/settings_location.php + + # run the exported distmaker + cd $workdir/$version/export/distmaker + ./distmaker.sh all > $workdir/$version/build.log +} + +################################################# +## Publish files +function do_publish() { + # publish to sf.net + cd $workdir/$version/tarballs + + $cmd_md5sum *.tar.gz *.zip > civicrm-$version.MD5SUMS + echo $cmd_gpg_pass | $cmd_gpg --armor --batch --passphrase-fd 0 --sign civicrm-$version.MD5SUMS + + if [ "$is_stable" ]; then + echo mkdir ${publish_stable_dir}/$version | $cmd_sftp ${publish_ssh} + $cmd_rsync -aP --exclude='*starterkit.tgz' *.tar.gz *.zip *MD5SUMS* ${publish_ssh}:${publish_stable_dir}/$version + else + echo mkdir ${publish_latest_dir}/$version | $cmd_sftp ${publish_ssh} + $cmd_rsync -aP --exclude='*starterkit.tgz' *.tar.gz *.zip *MD5SUMS* ${publish_ssh}:${publish_latest_dir}/$version + fi + + mv *.tar.gz *.zip *MD5SUMS* $build_dest + + # publish to latest.civicrm.org + # FIXME: isn't this racy when doing concurrent security releases + if [ "$is_stable" ]; then + echo $version > $latest/stable.txt + fi + echo $version > $latest/latest.txt +} + +################################################# +## Cleanup +function do_cleanup() { + cd $workdir/$version + rm -rf export gen tmp tarballs tmp +} + +################################################# +## Main + +## Refactoring note: this used to be one monolithic script + +do_git_config +do_mk_project +do_git_tag +do_distmaker +do_git_tag_push +do_publish +do_cleanup diff --git a/tools/scripts/releaser/releaser.conf.txt b/tools/scripts/releaser/releaser.conf.txt new file mode 100644 index 0000000000..0c3239e721 --- /dev/null +++ b/tools/scripts/releaser/releaser.conf.txt @@ -0,0 +1,35 @@ +#!/bin/bash + +## The GIT repo where we can find branches and create tags +#git_base_url=https://github.com/civicrm +#git_base_url=git@github.com:civicrm + +## Warning: This will be saved to the current user's ~/.gitconfig; should match gpg key +git_author_name="CiviCRM" +git_author_email="info@civicrm.org" + +## Local web directory for publishing tarballs, md5sums, etc +build_dest='/tmp/www/download.civicrm.org/public' + +## Local web directory for publishing the latest version number +latest='/tmp/www/latest.civicrm.org/public' + +## Local directory for build operations +workdir='/tmp/www/download.civicrm.org/workdir' + +## Passphrase for gpg signing key +gpg_pass="top-secret" + +## Remote web directory for publishing tarballs, md5sums, etc +publish_ssh="localhost" +publish_stable_dir=/tmp/www/publish/stable +publish_latest_dir=/tmp/www/publish/latest + +## Paths to miscellaneous executables +cmd_gitify=/Applications/MAMP/htdocs/sites/all/modules/civicrm/bin/gitify +cmd_gpg=gpg +cmd_md5sum=md5sum +cmd_php=php +cmd_rsync=rsync +cmd_sftp=sftp +cmd_zip=zip -- 2.25.1