|
| 1 | +#!/bin/bash |
| 2 | +# Copyright 2019 Google Inc. All Rights Reserved. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS-IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +# Publishes a new version of the firebaseui NPM package. The release notes is |
| 17 | +# generated from CHANGELOG.md. You need to login to npm using |
| 18 | +# `npm login --registry https://wombat-dressing-room.appspot.com` before running |
| 19 | +# this script. The twitter and hub credentials have to be set up. |
| 20 | +# |
| 21 | +# Usage: |
| 22 | +# $ buildtools/publish.sh <major|minor|patch> |
| 23 | + |
| 24 | +# CD to the root FirebaseUI directory, which should be the parent directory of |
| 25 | +# buildtools/. |
| 26 | +set -e |
| 27 | + |
| 28 | +printusage() { |
| 29 | + echo "publish.sh <version>" |
| 30 | + echo "REPOSITORY_ORG and REPOSITORY_NAME should be set in the environment." |
| 31 | + echo "e.g. REPOSITORY_ORG=user, REPOSITORY_NAME=repo" |
| 32 | + echo "" |
| 33 | + echo "Arguments:" |
| 34 | + echo " version: 'patch', 'minor', or 'major'." |
| 35 | +} |
| 36 | + |
| 37 | +VERSION=$1 |
| 38 | +if [[ $VERSION == "" ]]; then |
| 39 | + printusage |
| 40 | + exit 1 |
| 41 | +elif [[ ! ($VERSION == "patch" || \ |
| 42 | + $VERSION == "minor" || \ |
| 43 | + $VERSION == "major") ]]; then |
| 44 | + printusage |
| 45 | + exit 1 |
| 46 | +fi |
| 47 | + |
| 48 | +if [[ $REPOSITORY_ORG == "" ]]; then |
| 49 | + printusage |
| 50 | + exit 1 |
| 51 | +fi |
| 52 | +if [[ $REPOSITORY_NAME == "" ]]; then |
| 53 | + printusage |
| 54 | + exit 1 |
| 55 | +fi |
| 56 | + |
| 57 | +WDIR=$(pwd) |
| 58 | + |
| 59 | +echo "Checking for commands..." |
| 60 | +trap "echo 'Missing hub.'; exit 1" ERR |
| 61 | +which hub &> /dev/null |
| 62 | +trap - ERR |
| 63 | + |
| 64 | +trap "echo 'Missing node.'; exit 1" ERR |
| 65 | +which node &> /dev/null |
| 66 | +trap - ERR |
| 67 | + |
| 68 | +trap "echo 'Missing jq.'; exit 1" ERR |
| 69 | +which jq &> /dev/null |
| 70 | +trap - ERR |
| 71 | + |
| 72 | +trap "echo 'Missing JRE.'; exit 1" ERR |
| 73 | +which java &> /dev/null |
| 74 | +trap - ERR |
| 75 | + |
| 76 | +trap "echo 'Missing python2.'; exit 1" ERR |
| 77 | +which python &> /dev/null |
| 78 | +trap - ERR |
| 79 | + |
| 80 | +trap "echo 'Missing Chrome.'; exit 1" ERR |
| 81 | +which google-chrome &> /dev/null |
| 82 | +trap - ERR |
| 83 | +echo "Chrome version:" |
| 84 | +google-chrome --version |
| 85 | +echo "Checked for commands." |
| 86 | + |
| 87 | +echo "Checking for Twitter credentials..." |
| 88 | +trap "echo 'Missing Twitter credentials.'; exit 1" ERR |
| 89 | +test -f "${WDIR}/buildtools/twitter.json" |
| 90 | +trap - ERR |
| 91 | +echo "Checked for Twitter credentials..." |
| 92 | + |
| 93 | +echo "Checking for logged-in npm user..." |
| 94 | +trap "echo 'Please login to npm using \`npm login --registry https://wombat-dressing-room.appspot.com\`'; exit 1" ERR |
| 95 | +npm whoami --registry https://wombat-dressing-room.appspot.com |
| 96 | +trap - ERR |
| 97 | +echo "Checked for logged-in npm user." |
| 98 | + |
| 99 | +echo "Moving to temporary directory..." |
| 100 | +TEMPDIR=$(mktemp -d) |
| 101 | +echo "[DEBUG] ${TEMPDIR}" |
| 102 | +cd "${TEMPDIR}" |
| 103 | +echo "Moved to temporary directory." |
| 104 | + |
| 105 | +echo "Cloning repository..." |
| 106 | +git clone "[email protected]:${REPOSITORY_ORG}/${REPOSITORY_NAME}.git" |
| 107 | +cd "${REPOSITORY_NAME}" |
| 108 | +echo "Cloned repository." |
| 109 | + |
| 110 | +echo "Making sure there is a changelog..." |
| 111 | +if [ ! -s CHANGELOG.md ]; then |
| 112 | + echo "CHANGELOG.md is empty. Aborting." |
| 113 | + exit 1 |
| 114 | +fi |
| 115 | +echo "Made sure there is a changelog." |
| 116 | + |
| 117 | +echo "Running npm install..." |
| 118 | +npm install |
| 119 | +echo "Ran npm install." |
| 120 | + |
| 121 | +echo "Making a $VERSION version..." |
| 122 | +npm version $VERSION |
| 123 | +NEW_VERSION=$(jq -r ".version" package.json) |
| 124 | +echo "Made a $VERSION version." |
| 125 | + |
| 126 | +echo "Making the release notes..." |
| 127 | +RELEASE_NOTES_FILE=$(mktemp) |
| 128 | +echo "[DEBUG] ${RELEASE_NOTES_FILE}" |
| 129 | +echo "v${NEW_VERSION}" >> "${RELEASE_NOTES_FILE}" |
| 130 | +echo "" >> "${RELEASE_NOTES_FILE}" |
| 131 | +cat CHANGELOG.md >> "${RELEASE_NOTES_FILE}" |
| 132 | +echo "Made the release notes." |
| 133 | + |
| 134 | +echo "Publishing to npm..." |
| 135 | +npm publish |
| 136 | +echo "Published to npm." |
| 137 | + |
| 138 | +echo "Cleaning up release notes..." |
| 139 | +rm CHANGELOG.md |
| 140 | +touch CHANGELOG.md |
| 141 | +git commit -m "[firebase-release] Removed change log and reset repo after ${NEW_VERSION} release" CHANGELOG.md |
| 142 | +echo "Cleaned up release notes." |
| 143 | + |
| 144 | +echo "Pushing to GitHub..." |
| 145 | +git push origin master --tags |
| 146 | +echo "Pushed to GitHub." |
| 147 | + |
| 148 | +echo "Publishing release notes..." |
| 149 | +hub release create --file "${RELEASE_NOTES_FILE}" "v${NEW_VERSION}" |
| 150 | +echo "Published release notes." |
| 151 | + |
| 152 | +echo "Making the tweet..." |
| 153 | +npm install --no-save [email protected] |
| 154 | +cp -v "${WDIR}/buildtools/twitter.json" "${TEMPDIR}/${REPOSITORY_NAME}/buildtools/" |
| 155 | +node ./buildtools/tweet.js ${NEW_VERSION} |
| 156 | +echo "Made the tweet." |
0 commit comments