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() {
## Publish files
function do_publish() {
# publish to sf.net
- cd $workdir/$version/tarballs
+ 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
+ $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
+ 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() {
+ # FIXME: Is this racy when doing concurrent security releases?
+
+ # 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
- mv *.tar.gz *.tgz *.zip *MD5SUMS* $build_dest
+ 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 eol
- # publish to latest.civicrm.org
- # FIXME: isn't this racy when doing concurrent security releases
- if [ "$is_stable" ]; then
- echo $version > $latest/stable.txt
+ # If this is a stable release, check for another existing stable release, and
+ # if one is found, ask what status to assign to that other release.
+ if [[ "$status" == "stable" ]]; then
+ current_stable_version=$(php -r "
+ require 'releaser_json.php';
+ print_current_stable_version('$json');
+ ")
+
+ if [[ "$major_version" != "$current_stable_version" ]]; then
+ prompt new_status_for_previous_stable "Since this release is stable, what should be the new status for the current stable version ($current_stable_version)?" testing lts eol
+
+ json=$(php -r "
+ require 'releaser_json.php';
+ update_version_status('$json', '4.2', '$new_status_for_previous_stable');
+ ")
+ 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
- echo $version > $latest/latest.txt
+
+ # Add 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
}
#################################################
set -ex
do_git_tag_push
do_publish
+ do_publish_versions
set +x
;;
--update)
--- /dev/null
+<?php
+/**
+ * JSON handling functions for use by releaser script.
+ */
+
+
+/**
+ * Analyze the given json data to find the current stable major version string,
+ * and print that major version string to STDOUT.
+ *
+ * @param string $json JSON string from latest.civicrm.org/versions.json
+ * @return void
+ */
+function print_current_stable_version($json) {
+ $versions = json_decode($json, TRUE);
+ foreach ($versions as $major_version => $version) {
+ if ($version['status'] == 'stable') {
+ 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]}}
+ */
+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)) {
+ mylog($release_properties, '$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'
+ */
+function update_version_status($json, $major_version, $status) {
+ $versions = json_decode($json, TRUE);
+ $versions[$major_version]['status'] = $status;
+ echo json_encode($versions);
+}