|
| 1 | +####################################################################### |
| 2 | +## Copyright (c) 2016-2017 Contributors to the Eclipse Foundation |
| 3 | +## |
| 4 | +## See the NOTICE file(s) distributed with this work for additional |
| 5 | +## information regarding copyright ownership. |
| 6 | +## |
| 7 | +## Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +## you may not use this file except in compliance with the License. |
| 9 | +## You may obtain a copy of the License at |
| 10 | +## |
| 11 | +## http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +## |
| 13 | +## Unless required by applicable law or agreed to in writing, software |
| 14 | +## distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +## See the License for the specific language governing permissions and |
| 17 | +## limitations under the License. |
| 18 | +####################################################################### |
| 19 | +#set -v |
| 20 | + |
| 21 | +################################## |
| 22 | +# Specify the following variables |
| 23 | +################################## |
| 24 | + |
| 25 | +# requirements for versions: |
| 26 | +# - for BND: dash must come before a classifier, such as RC1 (e.g. 1.0-RC1 is valid while 1.0RC1 is invalid) |
| 27 | +#RELEASE_VERSION=1.0-RC1 |
| 28 | +#DEV_VERSION=1.0-SNAPSHOT |
| 29 | +#GIT_USER='Ondrej Mihalyi' |
| 30 | + |
| 31 | +ORIGIN_REMOTE_REPO=origin # - the name of the upstream repository to push changes to. It should be the main repository, not a fork |
| 32 | +BASE_REVISION=master # branch, tag or revision to make release from |
| 33 | + |
| 34 | +# try to read in these variables from a release.conf file |
| 35 | +if [ -e release.conf ]; then |
| 36 | + source release.conf |
| 37 | +fi |
| 38 | + |
| 39 | +# check that we have all variables, noting each one that is missing |
| 40 | +declare -a release_vars=("RELEASE_VERSION" "DEV_VERSION" "GIT_USER" "GIT_EMAIL" "ORIGIN_REMOTE_REPO" "BASE_REVISION") |
| 41 | +declare -a missing_vars=() |
| 42 | +for v in "${release_vars[@]}" |
| 43 | +do |
| 44 | + # echo "Checking ${v}=${!v}" |
| 45 | + if [ "X${!v}" = "X" ]; then |
| 46 | + echo "${v} is not defined" |
| 47 | + missing_vars+=("${v}") |
| 48 | + fi |
| 49 | +done |
| 50 | +if [ ${#missing_vars[@]} != 0 ]; then |
| 51 | + echo "ERROR: the following required variables are not defined: ${missing_vars[@]}" |
| 52 | + exit 1 |
| 53 | +fi |
| 54 | + |
| 55 | +# Specify derived variables |
| 56 | + |
| 57 | +BRANCH=branch_$RELEASE_VERSION |
| 58 | +TAG=$RELEASE_VERSION |
| 59 | + |
| 60 | +# set git identity |
| 61 | + |
| 62 | +git config user.name "$GIT_USER" |
| 63 | +git config user.email "$GIT_EMAIL" |
| 64 | + |
| 65 | +# delete release branch and tag |
| 66 | + |
| 67 | +git checkout "$BASE_REVISION" |
| 68 | +git reset --hard |
| 69 | +git clean -f |
| 70 | +git branch -D "$BRANCH" |
| 71 | +git tag -d "$TAG" ## it's OK if tag cannot be found |
| 72 | +# create and checkout release branch |
| 73 | + |
| 74 | +git branch "$BRANCH" |
| 75 | +git checkout "$BRANCH" |
| 76 | + |
| 77 | +# prepare release |
| 78 | + |
| 79 | +mvn --batch-mode -DreleaseVersion=$RELEASE_VERSION -DdevelopmentVersion=$DEV_VERSION -Dtag=$TAG release:clean release:prepare |
| 80 | + |
| 81 | +# don't continue if the mvn command fails or aborted |
| 82 | +if [[ x$? != x0 ]] |
| 83 | + then |
| 84 | + echo ERROR, aborting |
| 85 | + exit |
| 86 | +fi |
| 87 | + |
| 88 | +# publish the release TAG |
| 89 | +### If this fails because the tag already exists in the remote repo, |
| 90 | +### you can delete the tag with `git tag -d "$TAG" && git push origin :refs/tags/"$TAG"` |
| 91 | + |
| 92 | +git push "$ORIGIN_REMOTE_REPO" "$TAG" |
| 93 | + |
| 94 | +# revert git identity |
| 95 | + |
| 96 | +git config --unset user.name |
| 97 | +git config --unset user.email |
0 commit comments