|
| 1 | +#!/bin/bash -e |
| 2 | + |
| 3 | +#################################################################################################### |
| 4 | +# Check for required env vars |
| 5 | +#################################################################################################### |
| 6 | +if [[ "${CI}" != "true" ]] ; then |
| 7 | + echo "Exiting: $0 can only be run from the CI system." |
| 8 | + exit 1 |
| 9 | +fi |
| 10 | +if [[ -z "${GITLAB_HOST}" ]] ; then |
| 11 | + echo "GITLAB_HOST must be set, exiting ..." |
| 12 | + exit 1 |
| 13 | +fi |
| 14 | +if [[ -z "${GITLAB_TOKEN}" ]] ; then |
| 15 | + echo "GITLAB_TOKEN must be set, exiting ..." |
| 16 | + exit 1 |
| 17 | +fi |
| 18 | + |
| 19 | +#################################################################################################### |
| 20 | +# Set platform-specific sed extended syntax flag |
| 21 | +#################################################################################################### |
| 22 | +if [[ "$(uname)" == "Darwin" ]] ; then |
| 23 | + # MacOS |
| 24 | + SED_FLG="-E" |
| 25 | +else |
| 26 | + # Linux |
| 27 | + SED_FLG="-r" |
| 28 | +fi |
| 29 | + |
| 30 | +#################################################################################################### |
| 31 | +# Convert the release tag (e.g. v1.0.0) -> NEW_RELEASE (e.g. 1.0.0) |
| 32 | +#################################################################################################### |
| 33 | +NEW_VERSION=$(echo "${CI_COMMIT_REF_NAME}" | sed "${SED_FLG}" -n 's/^v([0-9]+\.[0-9]+\.[0-9]+)$/\1/p') |
| 34 | +if [[ -z "${NEW_VERSION}" ]] ; then |
| 35 | + echo "error setting NEW_VERSION, the release tag must match this pattern: \"^v([0-9]+\.[0-9]+\.[0-9]+)$\" (e.g. v1.0.0) but tag is: ${CI_COMMIT_REF_NAME} ..." |
| 36 | + exit 1 |
| 37 | +fi |
| 38 | + |
| 39 | +################################################################################################################ |
| 40 | +# Checkout latest version of Gitlab code to prepare for release (Checkout develop and create new release branch) |
| 41 | +################################################################################################################ |
| 42 | +OWNER=devplat-pr-32 |
| 43 | +PROJECT=splunk-cloud-sdk-python |
| 44 | +BRANCH_NAME=develop |
| 45 | +RELEASE_BRANCH_NAME=release/v${NEW_VERSION} |
| 46 | +set +x |
| 47 | +git remote set-url origin "https://oauth2:${GITLAB_TOKEN}@${GITLAB_HOST}/${OWNER}/${PROJECT}.git" |
| 48 | +set -x |
| 49 | +git config user.email "srv-dev-platform@splunk.com" |
| 50 | +git config user.name "srv-dev-platform" |
| 51 | +echo "Running \"git checkout ${BRANCH_NAME}\" ..." |
| 52 | +git checkout "${BRANCH_NAME}" |
| 53 | +echo "Running \"git fetch --all && git pull --all\" ..." |
| 54 | +git fetch --all && git pull --all |
| 55 | +echo "Running \"git checkout -b ${RELEASE_BRANCH_NAME}\" ..." |
| 56 | +git checkout -b ${RELEASE_BRANCH_NAME} |
| 57 | +echo "Showing changes with 'git status' ..." |
| 58 | +git status |
| 59 | + |
| 60 | +#################################################################################################### |
| 61 | +# Update splunk_sdk/__version__.py using the pre-release tag e.g. 1.0.0 for v1.0.0 |
| 62 | +#################################################################################################### |
| 63 | +echo "Updating Version in splunk_sdk/__version__.py using sed \"${SED_FLG}\" -i '' -e \"s/\\"[0-9]+\.[0-9]+\.[0-9]+\\"/\\"${NEW_VERSION}\\"/g\" splunk_sdk/__version__.py ..." |
| 64 | +sed "${SED_FLG}" -i -e "s/\"[0-9]+\.[0-9]+\.[0-9]+\"/\"${NEW_VERSION}\"/g" splunk_sdk/__version__.py |
| 65 | +git add splunk_sdk/__version__.py |
| 66 | + |
| 67 | +#################################################################################################### |
| 68 | +# Append the message from the pre-release tag to the top of the CHANGELOG.md under ## Version x.y.z |
| 69 | +#################################################################################################### |
| 70 | +echo "Adding tag message to changelog ..." |
| 71 | +set +x |
| 72 | +TAG_MESSAGE=$(git cat-file -p "${CI_COMMIT_REF_NAME}" | tail -n +6) |
| 73 | +set -x |
| 74 | +printf "Adding release notes to top of CHANGELOG.md:\n\n${TAG_MESSAGE}\n\n" |
| 75 | +set +x |
| 76 | +CL_HEADER=$(head -n 1 CHANGELOG.md) |
| 77 | +CL_CONTENTS=$(tail -n +2 CHANGELOG.md) |
| 78 | +rm CHANGELOG.md |
| 79 | +printf "${CL_HEADER}\n\n## Version ${NEW_VERSION}\n${TAG_MESSAGE}\n${CL_CONTENTS}" > CHANGELOG.md |
| 80 | +set -x |
| 81 | +git add CHANGELOG.md |
| 82 | + |
| 83 | +#################################################################################################### |
| 84 | +# Adding/pushing changed files to release branch (__version__.py and CHANGELOG.md) |
| 85 | +#################################################################################################### |
| 86 | +echo "Showing changes with \"git status\" ..." |
| 87 | +git status |
| 88 | +echo "Creating commit for __version__.py and CHANGELOG.md ..." |
| 89 | +git commit -m "Prepare v${NEW_VERSION} for release" |
| 90 | +echo "Pushing branch ${RELEASE_BRANCH_NAME} ..." |
| 91 | +git push --set-upstream origin "${RELEASE_BRANCH_NAME}" |
0 commit comments