|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# This script updates the READMEs with the latest non-SNAPSHOT version number and increments the SNAPSHOT |
| 4 | +# version number in the pom.xml files. |
| 5 | + |
| 6 | +# Precondition: the version in pom.xml does not contain "SNAPSHOT" before running this script. |
| 7 | +# Argument (optional): |
| 8 | +# $1: new version number for pom.xml files (do not include -SNAPSHOT, that is done automatically). |
| 9 | +# Providing no argument defaults to incrementing revision number from x.y.z-SNAPSHOT to x.y.z+1-SNAPSHOT |
| 10 | + |
| 11 | +# Example: Suppose that before running this script, the pom reads 7.8.9-SNAPSHOT. This script will replace |
| 12 | +# all occurrences of #.#.# with 7.8.9 in the README files and the first occurrence of 7.8.9-SNAPSHOT with |
| 13 | +# 7.8.10-SNAPSHOT in the pom.xml files. |
| 14 | + |
| 15 | +# Get the previous maven project version. |
| 16 | +RELEASED_VERSION=$(mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version | grep -Ev '(^\[|\w+:)') |
| 17 | +DEFAULT_UPDATE="${RELEASED_VERSION%.*}.$((${RELEASED_VERSION##*.}+1))" |
| 18 | +NEW_SNAPSHOT_VERSION=${1:-$DEFAULT_UPDATE}-SNAPSHOT |
| 19 | + |
| 20 | +echo "Changing version to $RELEASED_VERSION in README files" |
| 21 | +echo "Changing version to $NEW_SNAPSHOT_VERSION in pom.xml files" |
| 22 | + |
| 23 | +sed -ri "s/<version>[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*<\/version>/<version>${RELEASED_VERSION}<\/version>/g" README.md |
| 24 | +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 |
| 25 | +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 |
| 26 | +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 |
| 27 | +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 |
| 28 | +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 |
| 29 | + |
| 30 | +sed -i "0,/$RELEASED_VERSION/s/$RELEASED_VERSION/$NEW_SNAPSHOT_VERSION/g" pom.xml |
| 31 | +sed -i "0,/$RELEASED_VERSION/s/$RELEASED_VERSION/$NEW_SNAPSHOT_VERSION/g" gcloud-java/pom.xml |
| 32 | +sed -i "0,/$RELEASED_VERSION/s/$RELEASED_VERSION/$NEW_SNAPSHOT_VERSION/g" gcloud-java-core/pom.xml |
| 33 | +sed -i "0,/$RELEASED_VERSION/s/$RELEASED_VERSION/$NEW_SNAPSHOT_VERSION/g" gcloud-java-datastore/pom.xml |
| 34 | +sed -i "0,/$RELEASED_VERSION/s/$RELEASED_VERSION/$NEW_SNAPSHOT_VERSION/g" gcloud-java-examples/pom.xml |
| 35 | +sed -i "0,/$RELEASED_VERSION/s/$RELEASED_VERSION/$NEW_SNAPSHOT_VERSION/g" gcloud-java-storage/pom.xml |
| 36 | + |
| 37 | +git add README.md |
| 38 | +git add gcloud-java/README.md |
| 39 | +git add gcloud-java-core/README.md |
| 40 | +git add gcloud-java-datastore/README.md |
| 41 | +git add gcloud-java-examples/README.md |
| 42 | +git add gcloud-java-storage/README.md |
| 43 | +git add pom.xml |
| 44 | +git add gcloud-java/pom.xml |
| 45 | +git add gcloud-java-core/pom.xml |
| 46 | +git add gcloud-java-datastore/pom.xml |
| 47 | +git add gcloud-java-examples/pom.xml |
| 48 | +git add gcloud-java-storage/pom.xml |
| 49 | +git config --global user.name "travis-ci" |
| 50 | +git config --global user.email "[email protected]" |
| 51 | +git commit -m "Updating version in README and pom.xml files." |
| 52 | +git push --quiet "https://${CI_DEPLOY_USERNAME}:${CI_DEPLOY_PASSWORD}@github.com/GoogleCloudPlatform/gcloud-java.git" HEAD:master > /dev/null 2>&1 |
0 commit comments