github.com/verrazzano/verrazzano@v1.7.0/release/scripts/create_github_release.sh (about) 1 #!/usr/bin/env bash 2 # 3 # Copyright (c) 2021, 2022, 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 # Creates a Github release. 7 set -e 8 9 SCRIPT_DIR=$(cd $(dirname "$0"); pwd -P) 10 . $SCRIPT_DIR/common.sh 11 . $SCRIPT_DIR/common-release.sh 12 13 usage() { 14 cat <<EOM 15 Creates a Github release. 16 17 Usage: 18 $(basename $0) <hash of commit to release> <directory containing the release binaries> <a boolean to indicate test run, defaults to true> 19 20 Example: 21 $(basename $0) v1.0.1 aa94949a4e8e9b50bc0674035898f2579f2519cb ~/go/src/github.com/verrazzano/verrazzano/release 22 23 The script assumes Github CLI is installed and login is performed to authenticate the Github account. 24 25 EOM 26 exit 0 27 } 28 29 [ -z "$1" ] || [ -z "$2" ] || [ "$1" == "-h" ] && { usage; } 30 31 if [ -z "${RELEASE_VERSION}" ] ; then 32 echo "The script requires environment variable RELEASE_VERSION, in the format major.minor.patch (for example, 1.0.3)" 33 exit 1 34 fi 35 36 RELEASE_COMMIT=${1} 37 RELEASE_BINARIES_DIR=${2} 38 TEST_RUN=${3:-true} 39 40 VERSION=${RELEASE_VERSION} 41 42 if [[ $VERSION != v* ]] ; then 43 VERSION="v${RELEASE_VERSION}" 44 fi 45 46 function verify_release_binaries_exist() { 47 for i in "${releaseArtifacts[@]}" 48 do 49 if [ ! -f $i ];then 50 echo "Release artifact $i not found!" 51 return 1 52 fi 53 done 54 return 0 55 } 56 57 cd ${RELEASE_BINARIES_DIR} 58 59 # Validate the expected release artifacts are available under current directory 60 verify_release_binaries_exist || exit 1 61 62 # Validate Github CLI 63 validate_github_cli || exit 1 64 65 if [ $TEST_RUN == true ] ; then 66 echo "TEST_RUN is set to true, NOT doing a github release. This is the command that would be executed:" 67 echo "" 68 echo gh release create \"${VERSION}\" \ 69 --draft \ 70 --target \"${RELEASE_COMMIT}\" \ 71 --notes \"\" \ 72 --title \"Verrazzano release ${VERSION}\" \ 73 ${releaseArtifacts[*]} 74 else 75 echo "TEST_RUN is set to false, doing a github release now." 76 # Setting an empty string for notes, as the release notes will be prepared separately 77 gh release create "${VERSION}" \ 78 --draft \ 79 --target "${RELEASE_COMMIT}" \ 80 --notes "" \ 81 --title "Verrazzano release ${VERSION}" \ 82 ${releaseArtifacts[*]} 83 fi