|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +#Put your github username here, while testing performing new releases |
| 4 | +#GITHUB_USER=jeanlaurent |
| 5 | +GITHUB_USER=docker |
| 6 | +GITHUB_REPO=machine |
| 7 | + |
| 8 | +function usage { |
| 9 | + echo "Usage: " |
| 10 | + echo " GITHUB_TOKEN=XXXXX release/release.sh 0.5.x" |
| 11 | +} |
| 12 | + |
| 13 | +function display { |
| 14 | + echo "🐳 $1" |
| 15 | + echo "" |
| 16 | +} |
| 17 | + |
| 18 | +function checkError { |
| 19 | + if [[ "$?" -ne 0 ]]; then |
| 20 | + echo "😡 $1" |
| 21 | + if [[ "$2" == "showUsage" ]]; then |
| 22 | + usage |
| 23 | + fi |
| 24 | + exit 1 |
| 25 | + fi |
| 26 | +} |
| 27 | + |
| 28 | +function createMachine { |
| 29 | + docker-machine rm -f release 2> /dev/null |
| 30 | + docker-machine create -d virtualbox --virtualbox-cpu-count=2 --virtualbox-memory=2048 release |
| 31 | +} |
| 32 | + |
| 33 | +VERSION=$1 |
| 34 | +GITHUB_VERSION="v${VERSION}" |
| 35 | +PROJECT_URL="git@github.com:${GITHUB_USER}/${GITHUB_REPO}" |
| 36 | + |
| 37 | +RELEASE_DIR="$(git rev-parse --show-toplevel)/../release-${VERSION}" |
| 38 | +GITHUB_RELEASE_FILE="github-release-${VERSION}.md" |
| 39 | + |
| 40 | +if [[ -z "${VERSION}" ]]; then |
| 41 | + #TODO: Check version is well formed |
| 42 | + echo "Missing version argument" |
| 43 | + usage |
| 44 | + exit 1 |
| 45 | +fi |
| 46 | + |
| 47 | +if [[ -z "${GITHUB_TOKEN}" ]]; then |
| 48 | + echo "GITHUB_TOKEN missing" |
| 49 | + usage |
| 50 | + exit 1 |
| 51 | +fi |
| 52 | + |
| 53 | +command -v git > /dev/null 2>&1 |
| 54 | +checkError "You obviously need git, please consider installing it..." "showUsage" |
| 55 | + |
| 56 | +command -v github-release > /dev/null 2>&1 |
| 57 | +checkError "github-release is not installed, go get -u github.com/aktau/github-release or check https://github.com/aktau/github-release, aborting." "showUsage" |
| 58 | + |
| 59 | +command -v openssl > /dev/null 2>&1 |
| 60 | +checkError "You need openssl to generate binaries signature, brew install it, aborting." "showUsage" |
| 61 | + |
| 62 | +command -v docker-machine > /dev/null 2>&1 |
| 63 | +checkError "You must have a docker-machine in your path" "showUsage" |
| 64 | + |
| 65 | +LAST_RELEASE_VERSION=$(git describe --abbrev=0 --tags) |
| 66 | +#TODO: ABORT if not found (very unlikely but could happen if two tags are on the same commits ) |
| 67 | +# this is tag search is done on master not on the clone... |
| 68 | + |
| 69 | +display "Starting release from ${LAST_RELEASE_VERSION} to ${GITHUB_VERSION} on ${PROJECT_URL} with token ${GITHUB_TOKEN}" |
| 70 | +while true; do |
| 71 | + read -p "Do you want to proceed with this release? (y/n) > " yn |
| 72 | + case $yn in |
| 73 | + [Yy]* ) break;; |
| 74 | + [Nn]* ) exit;; |
| 75 | + * ) echo "Please answer yes or no.";; |
| 76 | + esac |
| 77 | +done |
| 78 | + |
| 79 | +display "Checking machine 'release' status" |
| 80 | +MACHINE_STATUS=$(docker-machine status release) |
| 81 | +if [[ "$?" -ne 0 ]]; then |
| 82 | + display "Machine 'release' does not exist, creating it" |
| 83 | + createMachine |
| 84 | +else |
| 85 | + if [[ "${MACHINE_STATUS}" != "Running" ]]; then |
| 86 | + display "Machine 'release' is not running, trying to start it." |
| 87 | + docker-machine start release |
| 88 | + if [[ "$?" -ne 0 ]]; then |
| 89 | + display "Machine 'release' could not be started, removing and creating a fresh new one." |
| 90 | + createMachine |
| 91 | + fi |
| 92 | + display "Loosing 5 seconds to the virtualbox gods." |
| 93 | + sleep 5 |
| 94 | + fi |
| 95 | +fi |
| 96 | + |
| 97 | +eval $(docker-machine env release) |
| 98 | +checkError "Machine 'release' is in a weird state, aborting." |
| 99 | + |
| 100 | +if [[ -d "${RELEASE_DIR}" ]]; then |
| 101 | + display "Cleaning up ${RELEASE_DIR}" |
| 102 | + rm -rdf "${RELEASE_DIR}" |
| 103 | + checkError "Can't clean up ${RELEASE_DIR}. You should do it manually and retry." |
| 104 | +fi |
| 105 | + |
| 106 | +display "Cloning into ${RELEASE_DIR} from ${PROJECT_URL}" |
| 107 | + |
| 108 | +mkdir -p "${RELEASE_DIR}" |
| 109 | +checkError "Can't create ${RELEASE_DIR}, aborting." |
| 110 | +git clone -q "${PROJECT_URL}" "${RELEASE_DIR}" |
| 111 | +checkError "Can't clone into ${RELEASE_DIR}, aborting." |
| 112 | + |
| 113 | +cd "${RELEASE_DIR}" |
| 114 | + |
| 115 | +display "Bump version number to ${VERSION}" |
| 116 | +#TODO: This only works with the version written in the version.go file |
| 117 | +sed -i.bak s/"${VERSION}-dev"/"${VERSION}"/g version/version.go |
| 118 | +checkError "Sed borkage..., aborting." |
| 119 | + |
| 120 | +git add version/version.go |
| 121 | +git commit -q -m"Bump version to ${VERSION}" -s |
| 122 | +checkError "Can't git commit the version upgrade, aborting." |
| 123 | +rm version/version.go.bak |
| 124 | + |
| 125 | +display "Building in-container style" |
| 126 | +USE_CONTAINER=true make clean validate build-x |
| 127 | +checkError "Build error, aborting." |
| 128 | + |
| 129 | +# this is temporary -> Remove following two lines once merged |
| 130 | +mkdir -p script/release |
| 131 | +cp ../machine/script/release/github-release-template.md script/release/github-release-template.md |
| 132 | + |
| 133 | +display "Generating github release" |
| 134 | +cp -f script/release/github-release-template.md "${GITHUB_RELEASE_FILE}" |
| 135 | +checkError "Can't find github release template" |
| 136 | +CONTRIBUTORS=$(git log "${LAST_RELEASE_VERSION}".. --format="%aN" --reverse | sort | uniq | awk '{printf "- %s\n", $0 }') |
| 137 | +CHANGELOG=$(git log "${LAST_RELEASE_VERSION}".. --oneline) |
| 138 | + |
| 139 | +CHECKSUM="" |
| 140 | +cd bin/ |
| 141 | +for file in $(ls docker-machine*); do |
| 142 | + SHA256=$(openssl dgst -sha256 < "${file}") |
| 143 | + MD5=$(openssl dgst -md5 < "${file}") |
| 144 | + LINE=$(printf "\n * **%s**\n * sha256 \`%s\`\n * md5 \`%s\`\n\n" "${file}" "${SHA256}" "${MD5}") |
| 145 | + CHECKSUM="${CHECKSUM}${LINE}" |
| 146 | +done |
| 147 | +cd .. |
| 148 | + |
| 149 | +TEMPLATE=$(cat "${GITHUB_RELEASE_FILE}") |
| 150 | +echo "${TEMPLATE//\{\{VERSION\}\}/$GITHUB_VERSION}" > "${GITHUB_RELEASE_FILE}" |
| 151 | +checkError "Couldn't replace [ ${GITHUB_VERSION} ]" |
| 152 | + |
| 153 | +TEMPLATE=$(cat "${GITHUB_RELEASE_FILE}") |
| 154 | +echo "${TEMPLATE//\{\{CHANGELOG\}\}/$CHANGELOG}" > "${GITHUB_RELEASE_FILE}" |
| 155 | +checkError "Couldn't replace [ ${CHANGELOG} ]" |
| 156 | + |
| 157 | +TEMPLATE=$(cat "${GITHUB_RELEASE_FILE}") |
| 158 | +echo "${TEMPLATE//\{\{CONTRIBUTORS\}\}/$CONTRIBUTORS}" > "${GITHUB_RELEASE_FILE}" |
| 159 | +checkError "Couldn't replace [ ${CONTRIBUTORS} ]" |
| 160 | + |
| 161 | +TEMPLATE=$(cat "${GITHUB_RELEASE_FILE}") |
| 162 | +echo "${TEMPLATE//\{\{CHECKSUM\}\}/$CHECKSUM}" > "${GITHUB_RELEASE_FILE}" |
| 163 | +checkError "Couldn't replace [ ${CHECKSUM} ]" |
| 164 | + |
| 165 | + |
| 166 | +RELEASE_DOCUMENTATION="$(cat ${GITHUB_RELEASE_FILE})" |
| 167 | + |
| 168 | +display "Tagging and pushing tags" |
| 169 | +git remote | grep -q remote.prod.url |
| 170 | +if [[ "$?" -ne 0 ]]; then |
| 171 | + display "Adding 'remote.prod.url' remote git url" |
| 172 | + git remote add remote.prod.url "${PROJECT_URL}" |
| 173 | +fi |
| 174 | + |
| 175 | +display "Checking if remote tag ${GITHUB_VERSION} already exists." |
| 176 | +git ls-remote --tags 2> /dev/null | grep -q "${GITHUB_VERSION}" # returns 0 if found, 1 if not |
| 177 | +if [[ "$?" -ne 1 ]]; then |
| 178 | + display "Deleting previous tag ${GITHUB_VERSION}" |
| 179 | + git tag -d "${GITHUB_VERSION}" |
| 180 | + git push origin :refs/tags/"${GITHUB_VERSION}" |
| 181 | +else |
| 182 | + echo "Tag ${GITHUB_VERSION} does not exist... yet" |
| 183 | +fi |
| 184 | + |
| 185 | +display "Tagging release on github" |
| 186 | +git tag "${GITHUB_VERSION}" |
| 187 | +git push remote.prod.url "${GITHUB_VERSION}" |
| 188 | +checkError "Could not push to remote url" |
| 189 | + |
| 190 | +display "Checking if release already exists" |
| 191 | +github-release info \ |
| 192 | + --security-token "${GITHUB_TOKEN}" \ |
| 193 | + --user "${GITHUB_USER}" \ |
| 194 | + --repo "${GITHUB_REPO}" \ |
| 195 | + --tag "${GITHUB_VERSION}" > /dev/null 2>&1 |
| 196 | + |
| 197 | +if [[ "$?" -ne 1 ]]; then |
| 198 | + display "Release already exists, cleaning it up." |
| 199 | + github-release delete \ |
| 200 | + --security-token "${GITHUB_TOKEN}" \ |
| 201 | + --user "${GITHUB_USER}" \ |
| 202 | + --repo "${GITHUB_REPO}" \ |
| 203 | + --tag "${GITHUB_VERSION}" |
| 204 | + checkError "Could not delete release, aborting." |
| 205 | +fi |
| 206 | + |
| 207 | +display "Creating release on github" |
| 208 | +github-release release \ |
| 209 | + --security-token "${GITHUB_TOKEN}" \ |
| 210 | + --user "${GITHUB_USER}" \ |
| 211 | + --repo "${GITHUB_REPO}" \ |
| 212 | + --tag "${GITHUB_VERSION}" \ |
| 213 | + --name "${GITHUB_VERSION}" \ |
| 214 | + --description "${RELEASE_DOCUMENTATION}" \ |
| 215 | + --pre-release |
| 216 | +checkError "Could not create release, aborting." |
| 217 | + |
| 218 | + |
| 219 | +display "Uploading binaries" |
| 220 | +cd bin/ |
| 221 | +for file in $(ls docker-machine*); do |
| 222 | + display "Uploading ${file}..." |
| 223 | + github-release upload \ |
| 224 | + --security-token "${GITHUB_TOKEN}" \ |
| 225 | + --user "${GITHUB_USER}" \ |
| 226 | + --repo "${GITHUB_REPO}" \ |
| 227 | + --tag "${GITHUB_VERSION}" \ |
| 228 | + --name "${file}" \ |
| 229 | + --file "${file}" |
| 230 | + if [[ "$?" -ne 0 ]]; then |
| 231 | + display "Could not upload ${file}, continuing with others." |
| 232 | + fi |
| 233 | +done |
| 234 | +cd .. |
| 235 | + |
| 236 | +git remote rm remote.prod.url |
| 237 | + |
| 238 | +rm ${GITHUB_RELEASE_FILE} |
| 239 | + |
| 240 | +echo "There is a couple of tasks your still need to do manually, either until this script if updated or because this is a manual thing." |
| 241 | +echo " 1 Head over to the release note created for you on github https://github.com/docker/machine/releases/tag/${GITHUB_VERSION}, you'll have a chance to enhance commit details a bit." |
| 242 | +echo " 2 Once you're happy with your release note on github, add the revelant part to the CHANGELOG.md" |
| 243 | +echo " 3 Update the documentation branch" |
| 244 | +echo " 4 Test the binaries linked from the github release page" |
| 245 | +echo " 6 Change version/version.go to the next version" |
| 246 | +echo " 7 Party !!" |
| 247 | +echo " The full details of these tasks are described in the RELEASE.md document, available at https://github.com/docker/machine/blob/master/docs/RELEASE.md" |
0 commit comments