Repository: incubator-brooklyn Updated Branches: refs/heads/master a7b3d8e99 -> f2ba610ae
Add various release helpers Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/1aa1ba18 Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/1aa1ba18 Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/1aa1ba18 Branch: refs/heads/master Commit: 1aa1ba18156b3e592952eced98299d6b79e2ffc0 Parents: 69714b9 Author: Richard Downer <[email protected]> Authored: Tue Jun 23 13:10:21 2015 +0100 Committer: Richard Downer <[email protected]> Committed: Tue Jul 28 11:14:43 2015 +0100 ---------------------------------------------------------------------- parent/pom.xml | 2 + release/.gitignore | 1 + release/Gemfile | 5 + release/Gemfile.lock | 38 ++++++ release/README.md | 49 ++++++++ release/Vagrantfile | 66 ++++++++++ release/change-version.sh | 70 +++++++++++ release/gpg-agent.conf | 2 + release/make-release-artifacts.sh | 213 +++++++++++++++++++++++++++++++++ release/pr_report.rb | 12 ++ release/settings.xml | 29 +++++ usage/scripts/change-version.sh | 70 ----------- 12 files changed, 487 insertions(+), 70 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1aa1ba18/parent/pom.xml ---------------------------------------------------------------------- diff --git a/parent/pom.xml b/parent/pom.xml index c32477f..2673402 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -777,6 +777,8 @@ <excludes combine.children="append"> <!-- Exclude sandbox because not part of distribution: not in tgz, and not uploaded to maven-central --> <exclude>sandbox/**</exclude> + <!-- Exclude release because not part of distribution: not in tgz, and not uploaded to maven-central --> + <exclude>release/**</exclude> <!-- Exclude netbeans config files (not part of the project, but often on users' drives --> <exclude>**/nbactions.xml</exclude> <exclude>**/nb-configuration.xml</exclude> http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1aa1ba18/release/.gitignore ---------------------------------------------------------------------- diff --git a/release/.gitignore b/release/.gitignore new file mode 100644 index 0000000..8000dd9 --- /dev/null +++ b/release/.gitignore @@ -0,0 +1 @@ +.vagrant http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1aa1ba18/release/Gemfile ---------------------------------------------------------------------- diff --git a/release/Gemfile b/release/Gemfile new file mode 100644 index 0000000..8ab84b5 --- /dev/null +++ b/release/Gemfile @@ -0,0 +1,5 @@ +#ruby=ruby-2.1.2 +#ruby-gemset=brooklyn-release-helpers + +source 'https://rubygems.org' +gem 'github_api' http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1aa1ba18/release/Gemfile.lock ---------------------------------------------------------------------- diff --git a/release/Gemfile.lock b/release/Gemfile.lock new file mode 100644 index 0000000..859202a --- /dev/null +++ b/release/Gemfile.lock @@ -0,0 +1,38 @@ +GEM + remote: https://rubygems.org/ + specs: + addressable (2.3.8) + descendants_tracker (0.0.4) + thread_safe (~> 0.3, >= 0.3.1) + faraday (0.9.1) + multipart-post (>= 1.2, < 3) + github_api (0.12.3) + addressable (~> 2.3) + descendants_tracker (~> 0.0.4) + faraday (~> 0.8, < 0.10) + hashie (>= 3.3) + multi_json (>= 1.7.5, < 2.0) + nokogiri (~> 1.6.3) + oauth2 + hashie (3.4.2) + jwt (1.5.1) + mini_portile (0.6.2) + multi_json (1.11.1) + multi_xml (0.5.5) + multipart-post (2.0.0) + nokogiri (1.6.6.2) + mini_portile (~> 0.6.0) + oauth2 (1.0.0) + faraday (>= 0.8, < 0.10) + jwt (~> 1.0) + multi_json (~> 1.3) + multi_xml (~> 0.5) + rack (~> 1.2) + rack (1.6.4) + thread_safe (0.3.5) + +PLATFORMS + ruby + +DEPENDENCIES + github_api http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1aa1ba18/release/README.md ---------------------------------------------------------------------- diff --git a/release/README.md b/release/README.md new file mode 100644 index 0000000..f1976f6 --- /dev/null +++ b/release/README.md @@ -0,0 +1,49 @@ +Release Scripts and Helpers +=========================== + +This folder contains a number of items that will assist in the production of Brooklyn releases. + + +Release scripts - change-version.sh and make-release-artifacts.sh +----------------------------------------------------------------- + +`change-version.sh` will update version numbers across the whole distribution. It is recommended to use this script +rather than "rolling your own" or using a manual process, as you risk missing out some version numbers (and +accidentally changing some that should not be changed). + +`make-release-artifacts.sh` will produce the release artifacts with appropriate signatures. It is recommended to use +this script rather than "rolling your own" or using a manual process, as this script codifies several Apache +requirements about the release artifacts. + +These scripts are fully documented in **Release Process** pages on the website. + + +Vagrant configuration +--------------------- + +The `Vagrantfile` and associated files `settings.xml` and `gpg-agent.conf` are for setting up a virtual machine hosting +a complete and clean development environment. You may benefit from using this environment when making the release, but +it is not required that you do so. + +The environment is a single VM that configured with all the tools needed to make the release. It also configures GnuPG +by copying your `gpg.conf`, `secring.gpg` and `pubring.gpg` into the VM; also copied is your `.gitconfig`. The +GnuPG agent is configured to assist with the release signing by caching your passphrase, so you will only need to enter +it once during the build process. A Maven `settings.xml` is provided to assist with the upload to Apache's Nexus server. +Finally the canonical Git repository for Apache Brooklyn is cloned into the home directory. + +You should edit `settings.xml` before deployment, or `~/.m2/settings.xml` inside the VM after deployment, to include +your Apache credentials. + +Assuming you have VirtualBox and Vagrant already installed, you should simply be able to run `vagrant up` to create the +VM, and then `vagrant ssh` to get a shell prompt inside the VM. Finally run `vagrant destroy` to clean up afterwards. + +This folder is mounted at `/vagrant` inside the VM - this means the release helpers are close to hand, so you can +run for example `/vagrant/make-release/artifacts.sh`. + + +Pull request reporting +---------------------- + +`pr_report.rb` (and associated files `Gemfile` and `Gemfile.lock`) uses the GitHub API to extract a list of open pull +requests, and writes a summary into `pr_report.tsv`. This could then be imported into Google Sheets to provide a handy +way of classifying and managing outstanding PRs ahead of making a release. http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1aa1ba18/release/Vagrantfile ---------------------------------------------------------------------- diff --git a/release/Vagrantfile b/release/Vagrantfile new file mode 100644 index 0000000..016c48f --- /dev/null +++ b/release/Vagrantfile @@ -0,0 +1,66 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Vagrantfile that creates a basic workstation for compiling Brooklyn and +# running tests. Particularly useful for running integration tests, as you +# can clean up any failed tests simply by destroying and rebuilding the +# Vagrant instance. + +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. +Vagrant.configure(2) do |config| + + # Base on Ubuntu 14.04 LTS + config.vm.box = "ubuntu/trusty64" + + # Provider-specific configuration so you can fine-tune various + # backing providers for Vagrant. These expose provider-specific options. + config.vm.provider "virtualbox" do |vb| + vb.memory = "2048" + end + + config.vm.network "forwarded_port", guest: 8008, host: 8008 + + config.vm.provision "file", source: "~/.gitconfig", destination: ".gitconfig" + config.vm.provision "file", source: "~/.gnupg/gpg.conf", destination: ".gnupg/gpg.conf" + config.vm.provision "file", source: "~/.gnupg/pubring.gpg", destination: ".gnupg/pubring.gpg" + config.vm.provision "file", source: "~/.gnupg/secring.gpg", destination: ".gnupg/secring.gpg" + config.vm.provision "file", source: "gpg-agent.conf", destination: ".gnupg/gpg-agent.conf" + config.vm.provision "file", source: "settings.xml", destination: ".m2/settings.xml" + + # Update the VM, install Java and Maven, enable passwordless-ssh-to-localhost, + # clone the canonical repository + config.vm.provision "shell", inline: <<-SHELL + apt-get update + apt-get upgrade -y + apt-get install -y default-jdk maven git xmlstarlet zip unzip language-pack-en vim-nox gnupg2 gnupg-agent pinentry-curses + wget -q -O /tmp/artifactory.zip http://bit.ly/Hqv9aj + mkdir -p /opt + unzip /tmp/artifactory.zip -d /opt + sudo sed -i -e '/Connector port=/ s/=\".*\"/=\"'"8008"'\"/' /opt/artifactory*/tomcat/conf/server.xml + /opt/artifactory*/bin/installService.sh + service artifactory start + chmod -R go= ~vagrant/.gnupg + cat /etc/ssh/ssh_host_*_key.pub | awk '{print "localhost,127.0.0.1 "$0}' >> /etc/ssh/ssh_known_hosts + su -c 'ssh-keygen -t rsa -b 2048 -N "" -f ~/.ssh/id_rsa; cat ~/.ssh/*.pub >> ~/.ssh/authorized_keys' vagrant + su -c 'git clone https://git-wip-us.apache.org/repos/asf/incubator-brooklyn.git apache-brooklyn-git' vagrant + SHELL +end http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1aa1ba18/release/change-version.sh ---------------------------------------------------------------------- diff --git a/release/change-version.sh b/release/change-version.sh new file mode 100755 index 0000000..280c245 --- /dev/null +++ b/release/change-version.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +set -e + +# changes the version everywhere +# usage, e.g.: change-version.sh 0.3.0-SNAPSHOT 0.3.0-RC1 +# or: change-version.sh MARKER 0.3.0-SNAPSHOT 0.3.0-RC1 + +[ -d .git ] || { + echo "Must run in brooklyn project root directory" + exit 1 +} + +if [ "$#" -eq 2 ]; then + VERSION_MARKER=BROOKLYN_VERSION +elif [ "$#" -eq 3 ]; then + VERSION_MARKER=$1_VERSION + shift; +else + echo "Usage: "$0" [VERSION_MARKER] CURRENT_VERSION NEW_VERSION" + echo " e.g.: "$0" BROOKLYN 0.3.0-SNAPSHOT 0.3.0-RC1" + exit 1 +fi + +# remove binaries and stuff +if [ -f pom.xml ] && [ -d target ] ; then mvn clean ; fi + +VERSION_MARKER_NL=${VERSION_MARKER}_BELOW +CURRENT_VERSION=$1 +NEW_VERSION=$2 + +# grep --exclude-dir working only in recent versions, not on all platforms, replace with find; +# skip folders named "ignored" or .xxx (but not the current folder "."); +# exclude log, war, etc. files; +# use null delimiters so files containing spaces are supported; +#Â pass /dev/null as the first file to search in, so the command doesn't fail if find doesn't match any files; +# add || true for the case where grep doesn't have matches, so the script doesn't halt +# If there's an error "Argument list too long" add -n20 to xargs arguments and loop over $FILE around sed +FILES=`find . -type d \( -name ignored -or -name .?\* \) -prune \ + -o -type f -not \( -name \*.log -or -name '*.war' -or -name '*.min.js' -or -name '*.min.css' \) -print0 | \ + xargs -0 grep -l "${VERSION_MARKER}\|${VERSION_MARKER_NL}" /dev/null || true` + +FILES_COUNT=`echo $FILES | wc | awk '{print $2}'` + +if [ ${FILES_COUNT} -ne 0 ]; then + # search for files containing version markers + sed -i.bak -e "/${VERSION_MARKER}/s/${CURRENT_VERSION}/${NEW_VERSION}/g" $FILES + sed -i.bak -e "/${VERSION_MARKER_NL}/{n;s/${CURRENT_VERSION}/${NEW_VERSION}/g;}" $FILES +fi + +echo "Changed ${CURRENT_VERSION} to ${NEW_VERSION} for "${FILES_COUNT}" files" +echo "(Do a \`find . -name \"*.bak\" -delete\` to delete the backup files.)" http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1aa1ba18/release/gpg-agent.conf ---------------------------------------------------------------------- diff --git a/release/gpg-agent.conf b/release/gpg-agent.conf new file mode 100644 index 0000000..3cd0291 --- /dev/null +++ b/release/gpg-agent.conf @@ -0,0 +1,2 @@ +default-cache-ttl 7200 +max-cache-ttl 86400 http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1aa1ba18/release/make-release-artifacts.sh ---------------------------------------------------------------------- diff --git a/release/make-release-artifacts.sh b/release/make-release-artifacts.sh new file mode 100755 index 0000000..b372560 --- /dev/null +++ b/release/make-release-artifacts.sh @@ -0,0 +1,213 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# creates a source release - this is a .tar.gz file containing all the source code files that are permitted to be released. + +set -e + +############################################################################### +fail() { + echo >&2 "$@" + exit 1 +} + +############################################################################### +show_help() { + cat >&2 <<END +Usage: make-release-artifacts.sh [-v version] [-r rc_number] +Prepares and builds the source and binary distribution artifacts of a Brooklyn +release. + + -vVERSION overrides the name of this version, if detection + from pom.xml is not accurate for any reason. + -rRC_NUMBER specifies the release candidate number. The + produced artifact names include the 'rc' suffix, + but the contents of the archive artifact do *not* + include the suffix. Therefore, turning a release + candidate into a release requires only renaming + the artifacts. + +Specifying the RC number is required. Specifying the version number is +discouraged; if auto detection is not working, then this script is buggy. +END +# ruler -------------------------------------------------- +} + +############################################################################### +confirm() { + # call with a prompt string or use a default + read -r -p "${1:-Are you sure? [y/N]} " response + case $response in + [yY][eE][sS]|[yY]) + true + ;; + *) + false + ;; + esac +} + +############################################################################### +detect_version() { + if [ \! -z "${current_version}" ]; then + return + fi + + set +e + current_version=$( xmlstarlet select -t -v '/_:project/_:version/text()' pom.xml 2>/dev/null ) + success=$? + set -e + if [ "${success}" -ne 0 -o -z "${current_version}" ]; then + fail Could not detect version number + fi +} + +############################################################################### +# Argument parsing +rc_suffix= +OPTIND=1 +while getopts "h?v:r:" opt; do + case "$opt" in + h|\?) + show_help + exit 0 + ;; + v) + current_version=$OPTARG + ;; + r) + rc_suffix=$OPTARG + ;; + *) + show_help + exit 1 + esac +done + +shift $((OPTIND-1)) +[ "$1" = "--" ] && shift + +############################################################################### +# Prerequisite checks +[ -d .git ] || fail Must run in brooklyn project root directory + +detect_version + +############################################################################### +# Determine all filenames and paths, and confirm + +release_name=apache-brooklyn-${current_version} +if [ -z "$rc_suffix" ]; then + fail Specifying the RC number is required +else + artifact_name=${release_name}-rc${rc_suffix} +fi + +release_script_dir=$( cd $( dirname $0 ) && pwd ) +brooklyn_dir=$( pwd ) +staging_dir="${brooklyn_dir}/src-release-tmp/${release_name}-src" +bin_staging_dir="${brooklyn_dir}/bin-release-tmp/${release_name}-bin" +artifact_dir="${release_script_dir}/${artifact_name}" + +echo "The version is ${current_version}" +echo "The rc suffix is rc${rc_suffix}" +echo "The release name is ${release_name}" +echo "The artifact name is ${artifact_name}" +echo "The artifact directory is ${artifact_dir}" +echo "" +confirm "Is this information correct? [y/N]" || exit +echo "" +echo "WARNING! This script will run 'git clean -dxf' to remove ALL files that are not under Git source control." +echo "This includes build artifacts and all uncommitted local files and directories." +echo "If you want to check what will happen, answer no and run 'git clean -dxn' to dry run." +echo "" +confirm || exit +echo "" +echo "This script will cause uploads to be made to a staging repository on the Apache Nexus server." +echo "" +confirm "Shall I continue? [y/N]" || exit + +############################################################################### +# Clean the workspace +git clean -dxf + +############################################################################### +# Source release +echo "Creating source release folder ${release_name}" +set -x +mkdir -p ${staging_dir} +rsync -rtp --exclude src-release-tmp --exclude bin-release-tmp --exclude .git\* --exclude '**/*.[ejw]ar' --exclude docs/ . ${staging_dir} + +mkdir -p ${artifact_dir} +set +x +echo "Creating artifact ${artifact_dir}/${artifact_name}.tar.gz and .zip" +set -x +( cd src-release-tmp && tar czf ${artifact_dir}/${artifact_name}-src.tar.gz apache-brooklyn-${current_version}-src ) +( cd src-release-tmp && zip -qr ${artifact_dir}/${artifact_name}-src.zip apache-brooklyn-${current_version}-src ) + +############################################################################### +# Binary release +set +x +echo "Proceeding to build binary release" +set -x + +# Set up GPG agent +eval $(gpg-agent --daemon --no-grab --write-env-file $HOME/.gpg-agent-info) +GPG_TTY=$(tty) +export GPG_TTY GPG_AGENT_INFO + +# Workaround for bug BROOKLYN-1 +( cd ${staging_dir} && mvn clean --projects :brooklyn-archetype-quickstart ) + +# Perform the build and deploy to Nexus staging repository +( cd ${staging_dir} && mvn deploy -Papache-release ) + +# Re-pack the archive with the correct names +mkdir -p bin-release-tmp +tar xzf ${staging_dir}/usage/dist/target/brooklyn-dist-${current_version}-dist.tar.gz -C bin-release-tmp +mv bin-release-tmp/brooklyn-dist-${current_version} bin-release-tmp/apache-brooklyn-${current_version}-bin + +( cd bin-release-tmp && tar czf ${artifact_dir}/${artifact_name}-bin.tar.gz apache-brooklyn-${current_version}-bin ) +( cd bin-release-tmp && zip -qr ${artifact_dir}/${artifact_name}-bin.zip apache-brooklyn-${current_version}-bin ) + +############################################################################### +# Signatures and checksums + +# OSX doesn't have sha256sum, even if MacPorts md5sha1sum package is installed. +# Easy to fake it though. +which sha256sum >/dev/null || alias sha256sum='shasum -a 256' + +( cd ${artifact_dir} && + for a in *.tar.gz *.zip; do + md5sum -b ${a} > ${a}.md5 + sha1sum -b ${a} > ${a}.sha1 + sha256sum -b ${a} > ${a}.sha256 + gpg2 --armor --output ${a}.asc --detach-sig ${a} + done +) + +############################################################################### +# Conclusion + +set +x +echo "The release is done - here is what has been created:" +ls ${artifact_dir} +echo "You can find these files in: ${artifact_dir}" +echo "The git commit ID for the voting emails is: $( git rev-parse HEAD )" http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1aa1ba18/release/pr_report.rb ---------------------------------------------------------------------- diff --git a/release/pr_report.rb b/release/pr_report.rb new file mode 100644 index 0000000..95b6317 --- /dev/null +++ b/release/pr_report.rb @@ -0,0 +1,12 @@ +#ruby + +require 'CSV' +require 'github_api' + +gh = Github.new + +CSV.open("pr_report.tsv", "wb", { :col_sep => "\t" }) do |csv| + gh.pull_requests.list('apache', 'incubator-brooklyn'). + select { |pr| pr.state == "open" }. + each { |pr| csv << [ pr.number, pr.title, pr.created_at, pr.user.login ] } +end http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1aa1ba18/release/settings.xml ---------------------------------------------------------------------- diff --git a/release/settings.xml b/release/settings.xml new file mode 100644 index 0000000..2b03994 --- /dev/null +++ b/release/settings.xml @@ -0,0 +1,29 @@ +<?xml version="1.0"?> +<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" + xmlns="http://maven.apache.org/SETTINGS/1.1.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <servers> + <!-- Required for uploads to Apache's Nexus instance. These are LDAP credentials - the same credentials you + - would use to log in to Git and Jenkins (but not JIRA) --> + <server> + <id>apache.snapshots.https</id> + <username>xxx</username> + <password>xxx</password> + </server> + <server> + <id>apache.releases.https</id> + <username>xxx</username> + <password>xxx</password> + </server> + + <!-- This is used for deployments to the play Artifactory instance that is provisioned by the Vagrant scripts. + - It may be safely ignored. --> + <server> + <id>vagrant-ubuntu-trusty-64</id> + <username>admin</username> + <password>password</password> + </server> + </servers> + +</settings> http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1aa1ba18/usage/scripts/change-version.sh ---------------------------------------------------------------------- diff --git a/usage/scripts/change-version.sh b/usage/scripts/change-version.sh deleted file mode 100755 index 280c245..0000000 --- a/usage/scripts/change-version.sh +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -set -e - -# changes the version everywhere -# usage, e.g.: change-version.sh 0.3.0-SNAPSHOT 0.3.0-RC1 -# or: change-version.sh MARKER 0.3.0-SNAPSHOT 0.3.0-RC1 - -[ -d .git ] || { - echo "Must run in brooklyn project root directory" - exit 1 -} - -if [ "$#" -eq 2 ]; then - VERSION_MARKER=BROOKLYN_VERSION -elif [ "$#" -eq 3 ]; then - VERSION_MARKER=$1_VERSION - shift; -else - echo "Usage: "$0" [VERSION_MARKER] CURRENT_VERSION NEW_VERSION" - echo " e.g.: "$0" BROOKLYN 0.3.0-SNAPSHOT 0.3.0-RC1" - exit 1 -fi - -# remove binaries and stuff -if [ -f pom.xml ] && [ -d target ] ; then mvn clean ; fi - -VERSION_MARKER_NL=${VERSION_MARKER}_BELOW -CURRENT_VERSION=$1 -NEW_VERSION=$2 - -# grep --exclude-dir working only in recent versions, not on all platforms, replace with find; -# skip folders named "ignored" or .xxx (but not the current folder "."); -# exclude log, war, etc. files; -# use null delimiters so files containing spaces are supported; -#Â pass /dev/null as the first file to search in, so the command doesn't fail if find doesn't match any files; -# add || true for the case where grep doesn't have matches, so the script doesn't halt -# If there's an error "Argument list too long" add -n20 to xargs arguments and loop over $FILE around sed -FILES=`find . -type d \( -name ignored -or -name .?\* \) -prune \ - -o -type f -not \( -name \*.log -or -name '*.war' -or -name '*.min.js' -or -name '*.min.css' \) -print0 | \ - xargs -0 grep -l "${VERSION_MARKER}\|${VERSION_MARKER_NL}" /dev/null || true` - -FILES_COUNT=`echo $FILES | wc | awk '{print $2}'` - -if [ ${FILES_COUNT} -ne 0 ]; then - # search for files containing version markers - sed -i.bak -e "/${VERSION_MARKER}/s/${CURRENT_VERSION}/${NEW_VERSION}/g" $FILES - sed -i.bak -e "/${VERSION_MARKER_NL}/{n;s/${CURRENT_VERSION}/${NEW_VERSION}/g;}" $FILES -fi - -echo "Changed ${CURRENT_VERSION} to ${NEW_VERSION} for "${FILES_COUNT}" files" -echo "(Do a \`find . -name \"*.bak\" -delete\` to delete the backup files.)"
