Skip to content

Commit

Permalink
New script to update version in pom.xml and README docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajay Kannan committed Sep 2, 2015
1 parent 9d3b525 commit bcb7e86
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions utilities/after_success.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ if [ "${TRAVIS_JDK_VERSION}" == "oraclejdk7" -a "${TRAVIS_BRANCH}" == "master" -
git commit -m "Added a new site for version $SITE_VERSION and updated the root directory's redirect."
git config --global push.default simple
git push --quiet "https://${CI_DEPLOY_USERNAME}:${CI_DEPLOY_PASSWORD}@github.com/GoogleCloudPlatform/gcloud-java.git" > /dev/null 2>&1

# Update versions README and pom.xml in master branch
cd ..
utilities/update_version.sh
else
mvn deploy -DskipTests=true -Dgpg.skip=true --settings target/travis/settings.xml
fi
Expand Down
52 changes: 52 additions & 0 deletions utilities/update_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

# This script updates the READMEs with the latest non-SNAPSHOT version number and increments the SNAPSHOT
# version number in the pom.xml files.

# Precondition: the version in pom.xml does not contain "SNAPSHOT" before running this script.
# Argument (optional):
# $1: new version number for pom.xml files (do not include -SNAPSHOT, that is done automatically).
# Providing no argument defaults to incrementing revision number from x.y.z-SNAPSHOT to x.y.z+1-SNAPSHOT

# Example: Suppose that before running this script, the pom reads 7.8.9-SNAPSHOT. This script will replace
# all occurrences of #.#.# with 7.8.9 in the README files and the first occurrence of 7.8.9-SNAPSHOT with
# 7.8.10-SNAPSHOT in the pom.xml files.

# Get the previous maven project version.
RELEASED_VERSION=$(mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version | grep -Ev '(^\[|\w+:)')
DEFAULT_UPDATE="${RELEASED_VERSION%.*}.$((${RELEASED_VERSION##*.}+1))"
NEW_SNAPSHOT_VERSION=${1:-$DEFAULT_UPDATE}-SNAPSHOT

echo "Changing version to $RELEASED_VERSION in README files"
echo "Changing version to $NEW_SNAPSHOT_VERSION in pom.xml files"

sed -ri "s/<version>[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*<\/version>/<version>${RELEASED_VERSION}<\/version>/g" README.md
sed -ri "s/<version>[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*<\/version>/<version>${RELEASED_VERSION}<\/version>/g" gcloud-java/README.md
sed -ri "s/<version>[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*<\/version>/<version>${RELEASED_VERSION}<\/version>/g" gcloud-java-core/README.md
sed -ri "s/<version>[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*<\/version>/<version>${RELEASED_VERSION}<\/version>/g" gcloud-java-datastore/README.md
sed -ri "s/<version>[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*<\/version>/<version>${RELEASED_VERSION}<\/version>/g" gcloud-java-examples/README.md
sed -ri "s/<version>[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*<\/version>/<version>${RELEASED_VERSION}<\/version>/g" gcloud-java-storage/README.md

sed -i "0,/$RELEASED_VERSION/s/$RELEASED_VERSION/$NEW_SNAPSHOT_VERSION/g" pom.xml
sed -i "0,/$RELEASED_VERSION/s/$RELEASED_VERSION/$NEW_SNAPSHOT_VERSION/g" gcloud-java/pom.xml
sed -i "0,/$RELEASED_VERSION/s/$RELEASED_VERSION/$NEW_SNAPSHOT_VERSION/g" gcloud-java-core/pom.xml
sed -i "0,/$RELEASED_VERSION/s/$RELEASED_VERSION/$NEW_SNAPSHOT_VERSION/g" gcloud-java-datastore/pom.xml
sed -i "0,/$RELEASED_VERSION/s/$RELEASED_VERSION/$NEW_SNAPSHOT_VERSION/g" gcloud-java-examples/pom.xml
sed -i "0,/$RELEASED_VERSION/s/$RELEASED_VERSION/$NEW_SNAPSHOT_VERSION/g" gcloud-java-storage/pom.xml

git add README.md
git add gcloud-java/README.md
git add gcloud-java-core/README.md
git add gcloud-java-datastore/README.md
git add gcloud-java-examples/README.md
git add gcloud-java-storage/README.md
git add pom.xml
git add gcloud-java/pom.xml
git add gcloud-java-core/pom.xml
git add gcloud-java-datastore/pom.xml
git add gcloud-java-examples/pom.xml
git add gcloud-java-storage/pom.xml
git config --global user.name "travis-ci"
git config --global user.email "[email protected]"
git commit -m "Updating version in README and pom.xml files."
git push --quiet "https://${CI_DEPLOY_USERNAME}:${CI_DEPLOY_PASSWORD}@github.com/GoogleCloudPlatform/gcloud-java.git" HEAD:master > /dev/null 2>&1

0 comments on commit bcb7e86

Please sign in to comment.