|
| 1 | + |
| 2 | +#!/bin/bash |
| 3 | + |
| 4 | +# Copyright 2020 Google Inc. |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | + |
| 18 | + |
| 19 | +###################################### Outputs ##################################### |
| 20 | + |
| 21 | +# 1. version: The version of this release including the 'v' prefix (e.g. v1.2.3). |
| 22 | +# 2. changelog: Formatted changelog text for this release. |
| 23 | + |
| 24 | +#################################################################################### |
| 25 | + |
| 26 | +set -e |
| 27 | +set -u |
| 28 | + |
| 29 | +function echo_info() { |
| 30 | + local MESSAGE=$1 |
| 31 | + echo "[INFO] ${MESSAGE}" |
| 32 | +} |
| 33 | + |
| 34 | +function echo_warn() { |
| 35 | + local MESSAGE=$1 |
| 36 | + echo "[WARN] ${MESSAGE}" |
| 37 | +} |
| 38 | + |
| 39 | +function terminate() { |
| 40 | + echo "" |
| 41 | + echo_warn "--------------------------------------------" |
| 42 | + echo_warn "POST CHECK FAILED" |
| 43 | + echo_warn "--------------------------------------------" |
| 44 | + exit 1 |
| 45 | +} |
| 46 | + |
| 47 | + |
| 48 | +echo_info "Starting publish post check..." |
| 49 | +echo_info "Git revision : ${GITHUB_SHA}" |
| 50 | +echo_info "Git ref : ${GITHUB_REF}" |
| 51 | +echo_info "Workflow triggered by : ${GITHUB_ACTOR}" |
| 52 | +echo_info "GitHub event : ${GITHUB_EVENT_NAME}" |
| 53 | + |
| 54 | + |
| 55 | +echo_info "" |
| 56 | +echo_info "--------------------------------------------" |
| 57 | +echo_info "Extracting release version" |
| 58 | +echo_info "--------------------------------------------" |
| 59 | +echo_info "" |
| 60 | + |
| 61 | +echo_info "Loading version from: firebase.go" |
| 62 | + |
| 63 | +readonly RELEASE_VERSION=`grep "const Version" firebase.go | awk '{print $4}' | tr -d \"` || true |
| 64 | +if [[ -z "${RELEASE_VERSION}" ]]; then |
| 65 | + echo_warn "Failed to extract release version from: firebase.go" |
| 66 | + terminate |
| 67 | +fi |
| 68 | + |
| 69 | +if [[ ! "${RELEASE_VERSION}" =~ ^([0-9]*)\.([0-9]*)\.([0-9]*)$ ]]; then |
| 70 | + echo_warn "Malformed release version string: ${RELEASE_VERSION}. Exiting." |
| 71 | + terminate |
| 72 | +fi |
| 73 | + |
| 74 | +echo_info "Extracted release version: ${RELEASE_VERSION}" |
| 75 | +echo "::set-output name=version::v${RELEASE_VERSION}" |
| 76 | + |
| 77 | + |
| 78 | +echo_info "" |
| 79 | +echo_info "--------------------------------------------" |
| 80 | +echo_info "Generating changelog" |
| 81 | +echo_info "--------------------------------------------" |
| 82 | +echo_info "" |
| 83 | + |
| 84 | +echo_info "---< git fetch origin master --prune --unshallow >---" |
| 85 | +git fetch origin master --prune --unshallow |
| 86 | +echo "" |
| 87 | + |
| 88 | +echo_info "Generating changelog from history..." |
| 89 | +readonly CURRENT_DIR=$(dirname "$0") |
| 90 | +readonly CHANGELOG=`${CURRENT_DIR}/generate_changelog.sh` |
| 91 | +echo "$CHANGELOG" |
| 92 | + |
| 93 | +# Parse and preformat the text to handle multi-line output. |
| 94 | +# See https://github.202132.xyzmunity/t5/GitHub-Actions/set-output-Truncates-Multiline-Strings/td-p/37870 |
| 95 | +FILTERED_CHANGELOG=`echo "$CHANGELOG" | grep -v "\\[INFO\\]"` |
| 96 | +FILTERED_CHANGELOG="${FILTERED_CHANGELOG//'%'/'%25'}" |
| 97 | +FILTERED_CHANGELOG="${FILTERED_CHANGELOG//$'\n'/'%0A'}" |
| 98 | +FILTERED_CHANGELOG="${FILTERED_CHANGELOG//$'\r'/'%0D'}" |
| 99 | +echo "::set-output name=changelog::${FILTERED_CHANGELOG}" |
| 100 | + |
| 101 | + |
| 102 | +echo "" |
| 103 | +echo_info "--------------------------------------------" |
| 104 | +echo_info "POST CHECK SUCCESSFUL" |
| 105 | +echo_info "--------------------------------------------" |
0 commit comments