Skip to content

Commit 90426f6

Browse files
committed
Merge pull request #154 from ajkannan/version-update-script
Script to update version in pom.xml and README docs
2 parents 9d3b525 + fd59e79 commit 90426f6

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

utilities/after_success.sh

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ if [ "${TRAVIS_JDK_VERSION}" == "oraclejdk7" -a "${TRAVIS_BRANCH}" == "master" -
2727
git commit -m "Added a new site for version $SITE_VERSION and updated the root directory's redirect."
2828
git config --global push.default simple
2929
git push --quiet "https://${CI_DEPLOY_USERNAME}:${CI_DEPLOY_PASSWORD}@github.com/GoogleCloudPlatform/gcloud-java.git" > /dev/null 2>&1
30+
31+
# Update versions README and pom.xml in master branch
32+
cd ..
33+
utilities/update_docs_version.sh
3034
else
3135
mvn deploy -DskipTests=true -Dgpg.skip=true --settings target/travis/settings.xml
3236
fi

utilities/update_docs_version.sh

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
# This script updates the READMEs with the latest non-SNAPSHOT version number.
4+
# Example: Suppose that before running this script, the pom.xml reads 7.8.9. This script will replace
5+
# all occurrences of <version>#.#.#</version> with <version>7.8.9</version> in the README files.
6+
7+
# Get the current maven project version.
8+
RELEASED_VERSION=$(mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version | grep -Ev '(^\[|\w+:)')
9+
10+
if [ "${RELEASED_VERSION##*-}" != "SNAPSHOT" ]; then
11+
echo "Changing version to $RELEASED_VERSION in README files"
12+
# Get list of directories for which README.md must be updated
13+
module_folders=($(find . -maxdepth 1 -name 'gcloud-java*' -type d) .)
14+
for item in ${module_folders[*]}
15+
do
16+
sed -ri "s/<version>[0-9]+\.[0-9]+\.[0-9]+<\/version>/<version>${RELEASED_VERSION}<\/version>/g" ${item}/README.md
17+
done
18+
19+
git add README.md */README.md
20+
git config --global user.name "travis-ci"
21+
git config --global user.email "[email protected]"
22+
git commit -m "Updating version in README files."
23+
git push --quiet "https://${CI_DEPLOY_USERNAME}:${CI_DEPLOY_PASSWORD}@github.com/GoogleCloudPlatform/gcloud-java.git" HEAD:master > /dev/null 2>&1
24+
fi

utilities/update_pom_version.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
# This script updates the pom.xml files to the next version number.
4+
# This script is meant to be run manually (not by Travis)
5+
6+
# Argument (optional): new version number for pom.xml files
7+
# Providing no argument defaults to incrementing revision number to
8+
# x.y.z+1-SNAPSHOT if the current version is x.y.z OR to x.y.z if the
9+
# current version is x.y.z-SNAPSHOT.
10+
11+
# Get the previous maven project version.
12+
CURRENT_VERSION=$(mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version | grep -Ev '(^\[|\w+:)')
13+
# Get list of directories for which pom.xml must be updated
14+
module_folders=($(find . -maxdepth 1 -name 'gcloud-java*' -type d) .)
15+
16+
if [ $# -eq 1 ]; then
17+
NEW_VERSION=$1
18+
elif [ "${CURRENT_VERSION##*-}" != "SNAPSHOT" ]; then
19+
NEW_VERSION="${CURRENT_VERSION%.*}.$((${CURRENT_VERSION##*.}+1))-SNAPSHOT"
20+
else
21+
NEW_VERSION=${CURRENT_VERSION%%-*}
22+
fi
23+
24+
echo "Changing version from $CURRENT_VERSION to $NEW_VERSION in pom.xml files"
25+
for item in ${module_folders[*]}
26+
do
27+
sed -i "0,/<version>$CURRENT_VERSION/s/<version>$CURRENT_VERSION/<version>$NEW_VERSION/" ${item}/pom.xml
28+
done

0 commit comments

Comments
 (0)