github.com/argoproj/argo-cd@v1.8.7/hack/trigger-release.sh (about) 1 #!/usr/bin/env bash 2 3 # This script requires bash shell - sorry. 4 5 NEW_TAG="${1}" 6 GIT_REMOTE="${2}" 7 COMMIT_MSG="${3}" 8 origToken="" 9 10 set -ue 11 12 restoreToken() { 13 if test "$origToken" != ""; then 14 echo ">> Restoring original Git comment char" 15 git config core.commentChar "$origToken" 16 fi 17 } 18 19 cleanLocalTriggerTag() { 20 if test "$TRIGGER_TAG" != ""; then 21 echo ">> Remove trigger tag '${TRIGGER_TAG}' from local repository." 22 git tag -d $TRIGGER_TAG 23 fi 24 } 25 26 cleanup() { 27 restoreToken 28 cleanLocalTriggerTag 29 } 30 31 if test "${NEW_TAG}" = "" -o "${GIT_REMOTE}" = ""; then 32 echo "!! Usage: $0 <release tag> <remote> [path to release notes file]" >&2 33 exit 1 34 fi 35 36 # Target (version) tag must match version scheme vMAJOR.MINOR.PATCH with an 37 # optional pre-release tag. 38 if ! echo "${NEW_TAG}" | egrep -q '^v[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)*$'; then 39 echo "!! Malformed version tag: '${NEW_TAG}', must match 'vMAJOR.MINOR.PATCH(-rcX)'" >&2 40 exit 1 41 fi 42 43 TRIGGER_TAG="release-${NEW_TAG}" 44 45 # Check whether we are in correct branch of local repository 46 RELEASE_BRANCH="${NEW_TAG%\.[0-9]*}" 47 RELEASE_BRANCH="release-${RELEASE_BRANCH#*v}" 48 49 currentBranch=$(git branch --show-current) 50 if test "$currentBranch" != "${RELEASE_BRANCH}"; then 51 echo "!! Please checkout branch '${RELEASE_BRANCH}' (currently in branch: '${currentBranch}')" >&2 52 exit 1 53 fi 54 55 echo ">> Working in release branch '${RELEASE_BRANCH}'" 56 57 # Check for trigger tag existing in local repo 58 if git tag -l | grep -q -E "^${TRIGGER_TAG}$"; then 59 echo "!! Release tag '${TRIGGER_TAG}' already exists in local repository" >&2 60 exit 1 61 fi 62 63 # Check for trigger tag existing in remote repo 64 if git ls-remote ${GIT_REMOTE} refs/tags/${TRIGGER_TAG} | grep -q -E "^${NEW_TAG}$"; then 65 echo "!! Target trigger tag '${TRIGGER_TAG}' already exists in remote '${GIT_REMOTE}'" >&2 66 echo "!! Another operation currently in progress?" >&2 67 exit 1 68 fi 69 70 # Check for target (version) tag in local repo 71 if git tag -l | grep -q -E "^${NEW_TAG}$"; then 72 echo "!! Target version tag '${NEW_TAG}' already exists in local repository" >&2 73 exit 1 74 fi 75 76 # Check for target (version) tag in remote repo 77 if git ls-remote ${GIT_REMOTE} refs/tags/${NEW_TAG} | grep -q -E "^${NEW_TAG}$"; then 78 echo "!! Target version tag '${NEW_TAG}' already exists in remote '${GIT_REMOTE}'" >&2 79 exit 1 80 fi 81 82 echo ">> Creating new release '${NEW_TAG}' by pushing '${TRIGGER_TAG}' to '${GIT_REMOTE}'" 83 84 GIT_ARGS="" 85 if test "${COMMIT_MSG}" != ""; then 86 if ! test -f "${COMMIT_MSG}"; then 87 echo "!! Release notes at '${COMMIT_MSG}' do not exist or are not readable." >&2 88 exit 1 89 fi 90 GIT_ARGS="-F ${COMMIT_MSG}" 91 fi 92 93 # We need different git comment char than '#', because markdown makes extensive 94 # use of '#' - we chose ';' for our operation. 95 origToken=$(git config core.commentChar || echo '#') 96 echo ">> Saving original Git comment char '${origToken}' and setting it to ';' for this run" 97 if ! git config core.commentChar ';'; then 98 echo "!! Could not set git config commentChar ';'" >&2 99 exit 1 100 fi 101 102 trap cleanup SIGINT EXIT 103 104 # Create trigger tag in local repository 105 git tag -a ${GIT_ARGS} ${TRIGGER_TAG} 106 107 # Push the trigger tag to remote repository 108 git push ${GIT_REMOTE} ${TRIGGER_TAG}