|
| 1 | +#!/usr/bin/env bash |
| 2 | +RELEASE_VERSION="${1}" |
| 3 | +COMMITS="${2}" |
| 4 | + |
| 5 | +UPSTREAM_REMOTE=upstream |
| 6 | +MASTER_BRANCH="master" |
| 7 | +TARGET_NAMESPACE="release" |
| 8 | +SECRET_NAME=bot-token-github |
| 9 | +PUSH_REMOTE="${PUSH_REMOTE:-${UPSTREAM_REMOTE}}" # export PUSH_REMOTE to your own for testing |
| 10 | + |
| 11 | +CATALOG_TASKS="lint build tests" |
| 12 | + |
| 13 | +set -e |
| 14 | + |
| 15 | +[[ -z ${RELEASE_VERSION} ]] && { |
| 16 | + read -e -p "Enter a target release (i.e: v0.1.2): " RELEASE_VERSION |
| 17 | + [[ -z ${RELEASE_VERSION} ]] && { echo "no target release"; exit 1 ;} |
| 18 | +} |
| 19 | + |
| 20 | +[[ ${RELEASE_VERSION} =~ v[0-9]+\.[0-9]*\.[0-9]+ ]] || { echo "invalid version provided, need to match v\d+\.\d+\.\d+"; exit 1 ;} |
| 21 | +lasttag=$(git describe --abbrev=0 --tags) |
| 22 | +echo ${lasttag}|sed 's/\.[0-9]*$//'|grep -q ${RELEASE_VERSION%.*} && { echo "Minor version of ${RELEASE_VERSION%.*} detected"; minor_version=true ; } |
| 23 | + |
| 24 | +cd ${GOPATH}/src/github.com/tektoncd/cli |
| 25 | + |
| 26 | +git fetch -a ${UPSTREAM_REMOTE} >/dev/null |
| 27 | +git checkout ${MASTER_BRANCH} |
| 28 | +git reset --hard ${UPSTREAM_REMOTE}/${MASTER_BRANCH} |
| 29 | +git checkout -B release-${RELEASE_VERSION} ${MASTER_BRANCH} >/dev/null |
| 30 | + |
| 31 | +if [[ -n ${minor_version} ]];then |
| 32 | + git reset --hard ${lasttag} >/dev/null |
| 33 | + |
| 34 | + if [[ -z ${COMMITS} ]];then |
| 35 | + echo "Showing commit between last minor tag '${lasttag} to '${MASTER_BRANCH}'" |
| 36 | + echo |
| 37 | + git log --reverse --no-merges --pretty=format:"%h | %s | %cd | %ae" ${lasttag}..${MASTER_BRANCH} |
| 38 | + echo |
| 39 | + read -e -p "Pick a list of ordered commits to cherry-pick space separated (* mean all of them): " COMMITS |
| 40 | + fi |
| 41 | + [[ -z ${COMMITS} ]] && { echo "no commits picked"; exit 1;} |
| 42 | + if [[ ${COMMITS} == "*" ]];then |
| 43 | + COMMITS=$(git log --reverse --no-merges --pretty=format:"%h" ${lasttag}..${MASTER_BRANCH}) |
| 44 | + fi |
| 45 | + for commit in ${COMMITS};do |
| 46 | + git branch --contains ${commit} >/dev/null || { echo "Invalid commit ${commit}" ; exit 1;} |
| 47 | + echo "Cherry-picking commit: ${commit}" |
| 48 | + git cherry-pick ${commit} >/dev/null |
| 49 | + done |
| 50 | + |
| 51 | +else |
| 52 | + echo "Major release ${RELEASE_VERSION%.*} detected: picking up ${UPSTREAM_REMOTE}/${MASTER_BRANCH}" |
| 53 | + git reset --hard ${UPSTREAM_REMOTE}/${MASTER_BRANCH} |
| 54 | +fi |
| 55 | + |
| 56 | +# TODO: toremove! this is temporary to disable the upload to homebrew |
| 57 | +# need to find a way how to do this automatically (push to upstream/revert and |
| 58 | +# then being able to cherry-pick if $PUSH_REMOTE != 'upstream/origin'?) |
| 59 | +# git cherry-pick 052b0b4ce989fe9aee01027e67e61538b48e1179 |
| 60 | + |
| 61 | +# Add our VERSION so Makefile will pick it up when compiling |
| 62 | +echo ${RELEASE_VERSION} > VERSION |
| 63 | +git add VERSION |
| 64 | +git commit -sm "New version ${RELEASE_VERSION}" -m "${COMMITS}" VERSION |
| 65 | +git tag --sign -m \ |
| 66 | + "New version ${RELEASE_VERSION} |
| 67 | +COMMITS: |
| 68 | +$(git log --reverse --no-merges --pretty=format:"%h | %s | %cd | %ae" ${lasttag}..${MASTER_BRANCH})" \ |
| 69 | + --force ${RELEASE_VERSION} |
| 70 | + |
| 71 | +git push --force ${PUSH_REMOTE} ${RELEASE_VERSION} |
| 72 | + |
| 73 | +kubectl version 2>/dev/null >/dev/null || { |
| 74 | + echo "you need to have access to a kubernetes cluster" |
| 75 | + exit 1 |
| 76 | +} |
| 77 | + |
| 78 | +kubectl get pipelineresource 2>/dev/null >/dev/null || { |
| 79 | + echo "you need to have tekton install onto the cluster" |
| 80 | + exit 1 |
| 81 | +} |
| 82 | + |
| 83 | +kubectl create ${TARGET_NAMESPACE} 2>/dev/null || true |
| 84 | + |
| 85 | +for task in ${CATALOG_TASKS};do |
| 86 | + kubectl -n ${TARGET_NAMESPACE} apply -f https://raw.githubusercontent.com/tektoncd/catalog/master/golang/${task}.yaml |
| 87 | +done |
| 88 | + |
| 89 | +kubectl -n ${TARGET_NAMESPACE} apply -f ./tekton/goreleaser.yml |
| 90 | + |
| 91 | +if ! kubectl get secret ${SECRET_NAME} -o name >/dev/null 2>/dev/null;then |
| 92 | + github_token=$(git config --get github.oauth-token || true) |
| 93 | + |
| 94 | + [[ -z ${github_token} ]] && { |
| 95 | + read -e -p "Enter your Github Token: " github_token |
| 96 | + [[ -z ${github_token} ]] && { echo "no token provided"; exit 1;} |
| 97 | + } |
| 98 | + |
| 99 | + kubectl -n ${TARGET_NAMESPACE} create secret generic ${SECRET_NAME} --from-literal=bot-token=${github_token} |
| 100 | +fi |
| 101 | + |
| 102 | +kubectl -n ${TARGET_NAMESPACE} apply -f ./tekton/release-pipeline.yml |
| 103 | + |
| 104 | +# Until tkn supports tkn create with parameters we do like this, |
| 105 | +cat <<EOF | kubectl -n ${TARGET_NAMESPACE} apply -f- |
| 106 | +apiVersion: tekton.dev/v1alpha1 |
| 107 | +kind: PipelineResource |
| 108 | +metadata: |
| 109 | + name: tektoncd-cli-git |
| 110 | +spec: |
| 111 | + type: git |
| 112 | + params: |
| 113 | + - name: revision |
| 114 | + value: ${RELEASE_VERSION} |
| 115 | + - name: url |
| 116 | + value: $(git remote get-url ${PUSH_REMOTE}|sed 's,git@github.com:,https://github.com/,') |
| 117 | +EOF |
| 118 | + |
| 119 | +# Start the pipeline, We can't use tkn start because until #272 and #262 are imp/fixed |
| 120 | +cat <<EOF | kubectl -n ${TARGET_NAMESPACE} create -f- |
| 121 | +apiVersion: tekton.dev/v1alpha1 |
| 122 | +kind: PipelineRun |
| 123 | +metadata: |
| 124 | + generateName: cli-release-pipeline-run |
| 125 | +spec: |
| 126 | + pipelineRef: |
| 127 | + name: cli-release-pipeline |
| 128 | + resources: |
| 129 | + - name: source-repo |
| 130 | + resourceRef: |
| 131 | + name: tektoncd-cli-git |
| 132 | +EOF |
| 133 | + |
| 134 | +type -p tkn >/dev/null 2>/dev/null || { echo "Could not find the 'tkn' binary, you are on your own buddy"; exit 0 ;} |
| 135 | + |
| 136 | +tkn pipeline logs cli-release-pipeline -f |
0 commit comments