|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright 2020 Google Inc. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | + |
| 18 | +###################################### Outputs ##################################### |
| 19 | + |
| 20 | +# 1. version: The version of this release including the 'v' prefix (e.g. v1.2.3). |
| 21 | +# 2. changelog: Formatted changelog text for this release. |
| 22 | + |
| 23 | +#################################################################################### |
| 24 | + |
| 25 | +set -e |
| 26 | +set -u |
| 27 | + |
| 28 | +function echo_info() { |
| 29 | + local MESSAGE=$1 |
| 30 | + echo "[INFO] ${MESSAGE}" |
| 31 | +} |
| 32 | + |
| 33 | +function echo_warn() { |
| 34 | + local MESSAGE=$1 |
| 35 | + echo "[WARN] ${MESSAGE}" |
| 36 | +} |
| 37 | + |
| 38 | +function terminate() { |
| 39 | + echo "" |
| 40 | + echo_warn "--------------------------------------------" |
| 41 | + echo_warn "PREFLIGHT FAILED" |
| 42 | + echo_warn "--------------------------------------------" |
| 43 | + exit 1 |
| 44 | +} |
| 45 | + |
| 46 | + |
| 47 | +echo_info "Starting publish preflight check..." |
| 48 | +echo_info "Git revision : ${GITHUB_SHA}" |
| 49 | +echo_info "Workflow triggered by : ${GITHUB_ACTOR}" |
| 50 | +echo_info "GitHub event : ${GITHUB_EVENT_NAME}" |
| 51 | + |
| 52 | + |
| 53 | +echo_info "" |
| 54 | +echo_info "--------------------------------------------" |
| 55 | +echo_info "Extracting release version" |
| 56 | +echo_info "--------------------------------------------" |
| 57 | +echo_info "" |
| 58 | + |
| 59 | +readonly ABOUT_FILE="firebase_admin/__about__.py" |
| 60 | +echo_info "Loading version from: ${ABOUT_FILE}" |
| 61 | + |
| 62 | +readonly RELEASE_VERSION=`grep "__version__" ${ABOUT_FILE} | awk '{print $3}' | tr -d \'` || true |
| 63 | +if [[ -z "${RELEASE_VERSION}" ]]; then |
| 64 | + echo_warn "Failed to extract release version from: ${ABOUT_FILE}" |
| 65 | + terminate |
| 66 | +fi |
| 67 | + |
| 68 | +if [[ ! "${RELEASE_VERSION}" =~ ^([0-9]*)\.([0-9]*)\.([0-9]*)$ ]]; then |
| 69 | + echo_warn "Malformed release version string: ${RELEASE_VERSION}. Exiting." |
| 70 | + terminate |
| 71 | +fi |
| 72 | + |
| 73 | +echo_info "Extracted release version: ${RELEASE_VERSION}" |
| 74 | +echo "::set-output name=version::v${RELEASE_VERSION}" |
| 75 | + |
| 76 | + |
| 77 | +echo_info "" |
| 78 | +echo_info "--------------------------------------------" |
| 79 | +echo_info "Check release artifacts" |
| 80 | +echo_info "--------------------------------------------" |
| 81 | +echo_info "" |
| 82 | + |
| 83 | +if [[ ! -d dist ]]; then |
| 84 | + echo_warn "dist directory does not exist." |
| 85 | + terminate |
| 86 | +fi |
| 87 | + |
| 88 | +readonly BIN_DIST="dist/firebase_admin-${RELEASE_VERSION}-py3-none-any.whl" |
| 89 | +if [[ -f "${BIN_DIST}" ]]; then |
| 90 | + echo_info "Found binary distribution (bdist_wheel): ${BIN_DIST}" |
| 91 | +else |
| 92 | + echo_warn "Binary distribution ${BIN_DIST} not found." |
| 93 | + terminate |
| 94 | +fi |
| 95 | + |
| 96 | +readonly SRC_DIST="dist/firebase_admin-${RELEASE_VERSION}.tar.gz" |
| 97 | +if [[ -f "${SRC_DIST}" ]]; then |
| 98 | + echo_info "Found source distribution (sdist): ${SRC_DIST}" |
| 99 | +else |
| 100 | + echo_warn "Source distribution ${SRC_DIST} not found." |
| 101 | + terminate |
| 102 | +fi |
| 103 | + |
| 104 | +readonly ARTIFACT_COUNT=`ls dist/ | wc -l` |
| 105 | +if [[ $ARTIFACT_COUNT -ne 2 ]]; then |
| 106 | + echo_warn "Unexpected artifacts in the distribution directory." |
| 107 | + ls -l dist |
| 108 | + terminate |
| 109 | +fi |
| 110 | + |
| 111 | + |
| 112 | +echo_info "" |
| 113 | +echo_info "--------------------------------------------" |
| 114 | +echo_info "Checking previous releases" |
| 115 | +echo_info "--------------------------------------------" |
| 116 | +echo_info "" |
| 117 | + |
| 118 | +readonly PYPI_URL="https://pypi.org/pypi/firebase-admin/${RELEASE_VERSION}/json" |
| 119 | +readonly PYPI_STATUS=`curl -s -o /dev/null -L -w "%{http_code}" ${PYPI_URL}` |
| 120 | +if [[ $PYPI_STATUS -eq 404 ]]; then |
| 121 | + echo_info "Release version ${RELEASE_VERSION} not found in Pypi." |
| 122 | +elif [[ $PYPI_STATUS -eq 200 ]]; then |
| 123 | + echo_warn "Release version ${RELEASE_VERSION} already present in Pypi." |
| 124 | + terminate |
| 125 | +else |
| 126 | + echo_warn "Unexpected ${PYPI_STATUS} response from Pypi. Exiting." |
| 127 | + terminate |
| 128 | +fi |
| 129 | + |
| 130 | + |
| 131 | +echo_info "" |
| 132 | +echo_info "--------------------------------------------" |
| 133 | +echo_info "Checking release tag" |
| 134 | +echo_info "--------------------------------------------" |
| 135 | +echo_info "" |
| 136 | + |
| 137 | +echo_info "---< git fetch --depth=1 origin +refs/tags/*:refs/tags/* >---" |
| 138 | +git fetch --depth=1 origin +refs/tags/*:refs/tags/* |
| 139 | +echo "" |
| 140 | + |
| 141 | +readonly EXISTING_TAG=`git rev-parse -q --verify "refs/tags/v${RELEASE_VERSION}"` || true |
| 142 | +if [[ -n "${EXISTING_TAG}" ]]; then |
| 143 | + echo_warn "Tag v${RELEASE_VERSION} already exists. Exiting." |
| 144 | + echo_warn "If the tag was created in a previous unsuccessful attempt, delete it and try again." |
| 145 | + echo_warn " $ git tag -d v${RELEASE_VERSION}" |
| 146 | + echo_warn " $ git push --delete origin v${RELEASE_VERSION}" |
| 147 | + |
| 148 | + readonly RELEASE_URL="https://github.com/firebase/firebase-admin-python/releases/tag/v${RELEASE_VERSION}" |
| 149 | + echo_warn "Delete any corresponding releases at ${RELEASE_URL}." |
| 150 | + terminate |
| 151 | +fi |
| 152 | + |
| 153 | +echo_info "Tag v${RELEASE_VERSION} does not exist." |
| 154 | + |
| 155 | + |
| 156 | +echo_info "" |
| 157 | +echo_info "--------------------------------------------" |
| 158 | +echo_info "Generating changelog" |
| 159 | +echo_info "--------------------------------------------" |
| 160 | +echo_info "" |
| 161 | + |
| 162 | +echo_info "---< git fetch origin master --prune --unshallow >---" |
| 163 | +git fetch origin master --prune --unshallow |
| 164 | +echo "" |
| 165 | + |
| 166 | +echo_info "Generating changelog from history..." |
| 167 | +readonly CURRENT_DIR=$(dirname "$0") |
| 168 | +readonly CHANGELOG=`${CURRENT_DIR}/generate_changelog.sh` |
| 169 | +echo "$CHANGELOG" |
| 170 | + |
| 171 | +# Parse and preformat the text to handle multi-line output. |
| 172 | +# See https://github.community/t5/GitHub-Actions/set-output-Truncates-Multiline-Strings/td-p/37870 |
| 173 | +FILTERED_CHANGELOG=`echo "$CHANGELOG" | grep -v "\\[INFO\\]"` |
| 174 | +FILTERED_CHANGELOG="${FILTERED_CHANGELOG//'%'/'%25'}" |
| 175 | +FILTERED_CHANGELOG="${FILTERED_CHANGELOG//$'\n'/'%0A'}" |
| 176 | +FILTERED_CHANGELOG="${FILTERED_CHANGELOG//$'\r'/'%0D'}" |
| 177 | +echo "::set-output name=changelog::${FILTERED_CHANGELOG}" |
| 178 | + |
| 179 | + |
| 180 | +echo "" |
| 181 | +echo_info "--------------------------------------------" |
| 182 | +echo_info "PREFLIGHT SUCCESSFUL" |
| 183 | +echo_info "--------------------------------------------" |
0 commit comments