github.com/verrazzano/verrazzano@v1.7.0/release/scripts/create_branch.sh (about) 1 #!/usr/bin/env bash 2 # 3 # Copyright (c) 2021, Oracle and/or its affiliates. 4 # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 5 # 6 7 function usage { 8 echo 9 echo "usage: $0 [-v release_version] [-c source_commit]" 10 echo " -v release_version The release version in major_version.minor_version.patch_version format (e.g. 1.1.0). Required" 11 echo " -c source_commit The commit hash for the source commit. Required." 12 echo " -h Help" 13 echo 14 exit 1 15 } 16 17 function is_in_remote_repo() { 18 local branch=${1} 19 local exists=$(git ls-remote --heads origin ${branch}) 20 21 if [[ ! -z ${exists} ]]; then 22 return 0 23 else 24 return 1 25 fi 26 } 27 28 VERSION="" 29 RELEASE_COMMIT="" 30 EXPECTED_SOURCE_BRANCH="origin/master" 31 RELEASE_BRANCH="" 32 33 while getopts v:c:h flag 34 do 35 case "${flag}" in 36 v) VERSION=${OPTARG};; 37 c) RELEASE_COMMIT=${OPTARG};; 38 h) usage;; 39 *) usage;; 40 esac 41 done 42 43 parts=( ${VERSION//./ } ) 44 MAJOR="${parts[0]}" 45 MINOR="${parts[1]}" 46 PATCH="${parts[2]}" 47 48 if [ "${TEST_RUN:-false}" == "false" ]; then 49 RELEASE_BRANCH=release-${MAJOR}.${MINOR} 50 else 51 RELEASE_BRANCH=mock-release-${MAJOR}.${MINOR} 52 fi 53 54 echo "Release Branch: ${RELEASE_BRANCH}" 55 56 # if this is a patch release skip branch creation 57 if [ "${PATCH}" != "0" ]; then 58 echo "This is a patch release. No branch creation required" 59 exit 0 60 else 61 if ! is_in_remote_repo ${RELEASE_BRANCH} ; then 62 echo "creating branch" 63 # ensure we are branching off of a verrazzano master branch 64 65 # check remote repo 66 COMMIT_REPO=$(basename `git config --get remote.origin.url`) 67 echo "Commit Repo: ${COMMIT_REPO}" 68 COMMIT_BRANCH=$(git branch -r --contains ${RELEASE_COMMIT} | tr -d '[:space:]') 69 echo "Remote commit branch: ${COMMIT_BRANCH}" 70 71 if ! [[ "${COMMIT_REPO}" =~ ^(verrazzano|verrazzano.git)$ ]]; then 72 echo "Not in the correct repo" 73 exit 1 74 fi 75 76 # for testing purposes skip branch check 77 if [ "${TEST_RUN}" == 'false' ]; then 78 if [ "${COMMIT_BRANCH}" != "${EXPECTED_SOURCE_BRANCH}" ]; then 79 echo "Not using the master branch as the source branch. Please checkout the master branch and make sure to pull the latest code" 80 exit 1 81 fi 82 fi 83 84 git checkout -b ${RELEASE_BRANCH} ${RELEASE_COMMIT} 85 git push origin ${RELEASE_BRANCH} 86 else 87 echo "Release branch exists" 88 CREATION_COMMIT=$(git rev-parse --verify origin/${RELEASE_BRANCH}) 89 if [ "${CREATION_COMMIT}" != "${RELEASE_COMMIT}" ]; then 90 echo "Release branch found but commits do not match: Branch HEAD commit=${CREATION_COMMIT}, Requested commit=${RELEASE_COMMIT}" 91 exit 1 92 fi 93 exit 0 94 fi 95 fi 96 97 98 99