|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -o errexit |
| 4 | +set -o nounset |
| 5 | +set -o pipefail |
| 6 | + |
| 7 | +function die() { echo "$*" 1>&2 ; exit 1; } |
| 8 | + |
| 9 | +# Example usage |
| 10 | +# ./scripts/trigger_release.sh --upstream upstream --release 2.0.0 --snapshot 2.1.0-SNAPSHOT |
| 11 | + |
| 12 | +# In order to start the release the script: |
| 13 | +# * Performs a dump of the release using the release version |
| 14 | +# * Updates all the *.md containing the release version |
| 15 | +# * Commits all the above changes and eventually push them to the provided remote |
| 16 | +# * Performs a dump of the version back to the provided snapshot version |
| 17 | +# * Commits all the above changes and eventually push them to the provided remote |
| 18 | + |
| 19 | +THIS_BRANCH=$(git rev-parse --abbrev-ref HEAD) |
| 20 | +REMOTE="" |
| 21 | +NEW_SNAPSHOT="" |
| 22 | +NEW_VERSION="" |
| 23 | + |
| 24 | +# Loop through arguments and process them |
| 25 | +while (( "$#" )); do |
| 26 | + case $1 in |
| 27 | + -u|--upstream) |
| 28 | + if [[ -n $2 ]]; then |
| 29 | + REMOTE=$2 |
| 30 | + shift |
| 31 | + else |
| 32 | + die 'ERROR: "--upstream" requires a non-empty option argument.' |
| 33 | + fi |
| 34 | + ;; |
| 35 | + -r|--release) |
| 36 | + if [[ -n $2 ]]; then |
| 37 | + NEW_VERSION=$2 |
| 38 | + shift |
| 39 | + else |
| 40 | + die 'ERROR: "--version" requires a non-empty option argument.' |
| 41 | + fi |
| 42 | + ;; |
| 43 | + -s|--snapshot) |
| 44 | + if [[ -n $2 ]]; then |
| 45 | + NEW_SNAPSHOT=$2 |
| 46 | + shift |
| 47 | + else |
| 48 | + die 'ERROR: "--snapshot" requires a non-empty option argument.' |
| 49 | + fi |
| 50 | + ;; |
| 51 | + esac |
| 52 | + shift |
| 53 | +done |
| 54 | + |
| 55 | +if [ -z "$REMOTE" ]; then |
| 56 | + echo "Remote is not specified, I'm gonna perform the changes only locally" |
| 57 | +else |
| 58 | + echo "Going to release on remote $REMOTE" |
| 59 | +fi |
| 60 | + |
| 61 | +if [ -z "$NEW_VERSION" ]; then |
| 62 | + die 'ERROR: version is not specified' |
| 63 | +fi |
| 64 | + |
| 65 | +if [ -z "$NEW_SNAPSHOT" ]; then |
| 66 | + die 'ERROR: new snapshot is not specified' |
| 67 | +fi |
| 68 | + |
| 69 | +echo "Dumping to release $NEW_VERSION" |
| 70 | + |
| 71 | +mvn versions:set -DnewVersion="$NEW_VERSION" |
| 72 | +find . -name "pom.xml" -exec git add {} \; |
| 73 | +sed -i -e "s+<version>[a-zA-Z0-9.-]*<\/version>+<version>$NEW_VERSION</version>+g" ***/*.md |
| 74 | +find . -name "*.md" -exec git add {} \; |
| 75 | + |
| 76 | +git commit --signoff -m "Release $NEW_VERSION" |
| 77 | +git tag $NEW_VERSION |
| 78 | + |
| 79 | +if [ -n "$REMOTE" ]; then |
| 80 | + git push --follow-tags -u $REMOTE $THIS_BRANCH |
| 81 | +fi |
| 82 | + |
| 83 | +echo "Dumping to snapshot $NEW_SNAPSHOT" |
| 84 | + |
| 85 | +mvn versions:set -DnewVersion="$NEW_SNAPSHOT" |
| 86 | +find . -name "pom.xml" -exec git add {} \; |
| 87 | + |
| 88 | +git commit --signoff -m "Release $NEW_SNAPSHOT" |
| 89 | + |
| 90 | +if [ -n "$REMOTE" ]; then |
| 91 | + git push -u $REMOTE $THIS_BRANCH |
| 92 | +fi |
| 93 | + |
| 94 | +echo "Done! Now you can create the release on GitHub!" |
0 commit comments