+++ /dev/null
-#!/bin/bash
-set -e
-
-confdir=$(dirname $0)
-start_point="$1"
-version="$2"
-first_act="$3"
-distmaker_tgt=all
-
-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 "$start_point" -o -z "$version" -o -z "$first_act" ]; then
- echo
- echo "Usage:"
- echo " $0 <start_point> <version> --build"
- echo " $0 <start_point> <version> --publish"
- echo " $0 <start_point> <version> --update"
- echo " $0 <start_point> <version> --clean"
- echo " $0 <start_point> <version> --build --publish --update --clean [[ORDER SIGNIFICANT]]"
- echo "Arguments:"
- echo " <start_point> is a branch name (e.g. \"master\")"
- echo " <version> is Civi release (e.g. \"4.3.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
-
-#################################################
-## Prompt user for input, and set the named global variable to the selected value.
-## usage: prompt variable_name [prompt message] [option][option][...]
-## example:
-## prompt your_name "What's your name?" Bob Sally John Mary
-function prompt() {
-
- local variable_name=$1
- shift
-
- local prompt
- local option_key
- local input
- local is_answered
-
- prompt=$1
- shift
-
- # Initialize a counter for the options array.
- option_key=1
- # Add all options to the options array.
- for option in "$@"; do
- prompt="${prompt}\n${option_key}: ${option}";
- options[$option_key]=$option
- let "option_key=option_key+1"
- done
-
- # As long as we don't have a valid selection, keep prompting.
- while [[ -z "$input" ]]; do
- echo -e $prompt
- # If this is a second attempt, remind the user to select a valid value.
- if [ $is_answered ]; then
- echo "Please enter one of the provided integer values."
- fi
- read input
- is_answered=1
- if [[ "$input" > "$option_key" || "$input" < "1" ]]; then
- # Unset any invalid input.
- unset input
- fi
- done
- # Set the named global variable to the selected string value.
- eval $variable_name=\${options[$input]}
-}
-
-#################################################
-## 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 --branch "$start_point" --skip-gencode
-}
-
-#################################################
-## 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
- DM_REF_CORE=${start_point}
- DM_REF_DRUPAL=7.x-${start_point}
- DM_REF_DRUPAL6=6.x-${start_point}
- DM_REF_JOOMLA=${start_point}
- DM_REF_WORDPRESS=${start_point}
- DM_REF_PACKAGES=${start_point}
- " > $workdir/$version/export/distmaker/distmaker.conf
-
- # create a minimal civicrm.settings.php file
- mkdir -p $workdir/$version/export/default
- 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
-
- # create a minimal settings_location.php file
- echo "<?php define('CIVICRM_CONFDIR', '$workdir/$version/export'); ?>" > $workdir/$version/export/settings_location.php
-
- # run the exported distmaker
- cd $workdir/$version/export/distmaker
- ./distmaker.sh $distmaker_tgt > $workdir/$version/build.log
-}
-
-#################################################
-## Publish files
-function do_publish() {
- # publish to sf.net
- pushd $workdir/$version/tarballs
-
- $cmd_md5sum *.tar.gz *.tgz *.zip > civicrm-$version.MD5SUMS
- echo $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 *.tgz *.zip *MD5SUMS* $build_dest
-
- popd
-}
-
-#################################################
-## Publish version data to versions.json
-function do_publish_versions() {
- # Turn off command echoing, because it makes input prompts hard to read.
- set +x
-
- # Quit if versions.json is missing.
- if [ ! -f $latest/versions.json ]; then
- echo "Cannot find $latest/versions.json, so not updating it."
- return 0;
- fi
-
- major_version=`echo $version | awk -F '.' '{print $1"."$2}'`
- json=`cat $latest/versions.json`
-
- # Ask for the status of this release.
- prompt status "What is the status of the major version for this release?" testing stable lts
-
- # Rather complex steps to reconcile new release status with previous releases.
- if [[ "$status" == "lts" ]]; then
- # If it's LTS, ask what status to use for the current LTS, if any.
- older_lts_version=$(php -r "
- require 'releaser_json.php';
- print_previous_status_version('$json', 'lts', '$major_version');
- ")
- if [[ -n "$older_lts_version" ]]; then
- prompt new_status_for_older_lts "Since this release is lts, what should be the new status for the current lts version ($older_lts_version)?" lts eol
- # Assign the selected status to the current LTS version.
- json=$(php -r "
- require 'releaser_json.php';
- update_version_status('$json', '$older_lts_version', '$new_status_for_older_lts');
- ")
- fi
- elif [[ "$status" == "stable" ]]; then
- # If it's stable, ask what status to use for the current stable, if any.
- older_stable_version=$(php -r "
- require 'releaser_json.php';
- print_previous_status_version('$json', 'stable', '$major_version');
- ")
- if [[ -n "$older_stable_version" ]]; then
- prompt new_status_for_older_stable "Since this release is stable, what should be the new status for the current stable version ($older_stable_version)?" stable lts eol
- # Assign the selected status to the current stable version.
- json=$(php -r "
- require 'releaser_json.php';
- update_version_status('$json', '$older_stable_version', '$new_status_for_older_stable');
- ")
- if [[ "$new_status_for_older_stable" == "lts" ]]; then
- # But now, if we've bumped 'stable' to 'lts', we have to ask what status
- # to use for an older existing LTS release, if any.
- older_lts_version=$(php -r "
- require 'releaser_json.php';
- print_previous_status_version('$json', 'lts', '$older_stable_version');
- ")
- if [[ -n "$older_lts_version" ]]; then
- prompt new_status_for_older_lts "Since $older_stable_version is now lts, what should be the new status for the current lts version ($older_lts_version)?" lts eol
- # Assign the selected status to the older existing LTS release.
- json=$(php -r "
- require 'releaser_json.php';
- update_version_status('$json', '$older_lts_version', '$new_status_for_older_lts');
- ")
- fi
- fi
- fi
- fi
-
- # Ask if this is a security release.
- prompt is_security "Is this a security release?" Yes No
- if [[ "$is_security" == "Yes" ]]; then
- is_security="true"
- else
- is_security="false"
- fi
-
- # Update status for this release's major version.
- json=$(php -r "
- require 'releaser_json.php';
- update_version_status('$json', '$major_version', '$status');
- ")
-
- # Add the new release to JSON data.
- release_date=$(date +%Y-%m-%d);
- # Create json string for release properties; `tr` is just to let us use
- # (json-invalid) single quotes, which are easier to read in bash.
- release_json=$(echo "{'version':'$version','date':'$release_date','security':'$is_security'}" | tr \' \")
- json=$(php -r"
- require 'releaser_json.php';
- add_release('$json', '$major_version', '$release_json');
- ")
-
- # Write modified JSON data to versions.json.
- echo $json > $latest/versions.json
-}
-
-#################################################
-## Update Version Info
-function do_update() {
- echo "VERSION UPDATE: Enter the version that comes after $version (or enter nothing to abort)"
- read new_ver
- if [ -n "$new_ver" ]; then
- cd $workdir/$version/export
- # create sql upgrade file
- tpl="CRM/Upgrade/Incremental/sql/$new_ver.mysql.tpl"
- if [ ! -f $tpl ]; then
- echo "{* file to handle db changes in $new_ver during upgrade *}" > $tpl
- fi
- # escape regex special chars
- arg=`echo "$version" | sed 's:[]\[\^\$\.\*\/]:\\\\&:g'`
- for file in xml/version.xml sql/civicrm_generated.mysql; do
- set -ex
- git checkout $file
- sed "s/$arg/$new_ver/" < $file > $file.tmp
- mv $file.tmp $file
- set +x
- done
- # print the diff directly to the screen
- git diff | cat
- echo "Push these changes? y/n"
- read input
- if [ "$input" = "y" ]; then
- set -ex
- git add xml/version.xml sql/civicrm_generated.mysql $tpl
- git commit -m "Update version to $new_ver"
- git push origin "$start_point"
- set +x
- else
- do_update
- fi
- else
- echo "No version entered. Aborting version update."
- fi
-}
-
-#################################################
-## Cleanup
-function do_cleanup() {
- cd $workdir/$version
- rm -rf export gen tmp tarballs tmp
-}
-
-#################################################
-## Main
-
-## Refactoring note: this used to be one monolithic script
-
-shift ## start point
-shift ## version
-for ACT in "$@" ; do
- case "$ACT" in
- --build)
- set -ex
- do_git_config
- do_mk_project
- do_git_tag
- do_distmaker
- set +x
- ;;
- --publish)
- set -ex
- do_git_tag_push
- do_publish
- do_publish_versions
- set +x
- ;;
- --update)
- set +x
- do_update
- ;;
- --clean)
- set -ex
- do_cleanup
- set +x
- ;;
- *)
- echo "unrecognized: $ACT"
- ;;
- esac
-done
-
+++ /dev/null
-<?php
-/**
- * JSON handling functions for use by releaser script.
- */
-
-
-/**
- * Analyze the given json data to find the latest major version which a) has the
- * given status, and b) is older than the given major version, and print that
- * major version string to STDOUT.
- *
- * @param string $json JSON string from latest.civicrm.org/versions.json
- * @param string $status A status to search for, e.g., 'stable', 'lts'
- * @param string $compare_version A version string, which must be newer than
- * any matching version string.
- *
- * @return void
- */
-function print_previous_status_version($json, $status, $compare_version) {
- $versions = json_decode($json, TRUE);
- $major_versions = array_keys($versions);
- usort($major_versions, 'version_compare');
- $sorted_major_versions = array_reverse($major_versions);
- foreach ($sorted_major_versions as $major_version) {
- if (version_compare($major_version, $compare_version) == -1) {
- if ($versions[$major_version]['status'] == $status) {
- echo $major_version;
- return;
- }
- }
- }
-}
-
-/**
- * Add a new release to the given JSON data,
- * and print the modified JSON string to STDOUT.
- *
- * @param string $json JSON string from latest.civicrm.org/versions.json
- * @param string $major_version A major version string, e.g. 1.1
- * @param string $release_properties_json JSON string containing properties
- * for the new release, as seen in latest.civicrm.org/versions.json
- * {$major_version:{'releases':[$release_properties_json]}}
- *
- * @return Void
- */
-function add_release($json, $major_version, $release_properties_json) {
- $versions = json_decode($json, TRUE);
- $release_properties = json_decode($release_properties_json, TRUE);
- if (array_key_exists('security', $release_properties)) {
- if ($release_properties['security'] == 'false') {
- unset($release_properties['security']);
- }
- }
- $versions[$major_version]['releases'][] = $release_properties;
- echo json_encode($versions);
-}
-
-/**
- * Modify the status for a given major version in the given JSON data,
- * and print the modified JSON string to STDOUT.
- *
- * @param string $json JSON string from latest.civicrm.org/versions.json
- * @param string $major_version A major version string, e.g. 1.1
- * @param string $status The correct status for the major version, e.g.,
- * 'stable', 'eol'
- *
- * @return Void
- */
-function update_version_status($json, $major_version, $status) {
- $versions = json_decode($json, TRUE);
- $versions[$major_version]['status'] = $status;
- echo json_encode($versions);
-}