|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright OpenSearch Contributors |
| 4 | +# SPDX-License-Identifier: Apache-2.0 |
| 5 | +# |
| 6 | +# The OpenSearch Contributors require contributions made to |
| 7 | +# this file be licensed under the Apache-2.0 license or a |
| 8 | +# compatible open source license. |
| 9 | + |
| 10 | +# This script is to automate the opensearch-build consolidated release notes generation |
| 11 | + |
| 12 | +# On darwin and bsd the given grep/sed is lacking functionalities in gnu grep/gnu sed |
| 13 | +# Will exit if no ggrep/gsed found on the host |
| 14 | + |
| 15 | +### Variables ### |
| 16 | +shopt -s expand_aliases |
| 17 | +ROOT=`dirname "$(realpath $0)"`; echo $ROOT |
| 18 | +INPUT_MANIFEST=$1 |
| 19 | +SKIP_ORIG_URLS=$2 |
| 20 | +ORIG_URLS_TXT="$ROOT/release-notes-orig-urls.txt" |
| 21 | +ORIG_URLS_ARRAY=() |
| 22 | +RELEASE_NOTE_MD="$ROOT/release-notes-draft.md" |
| 23 | +OLD_IFS=$IFS |
| 24 | +RELEASENOTES_CATEGORIES="BREAKING,FEATURE#ADD,ENHANCE,BUG FIX,INFRASTRUCTURE,DOCUMENT,MAINT,REFACTOR" |
| 25 | + |
| 26 | +### Pre-steps ### |
| 27 | + |
| 28 | +if echo $OSTYPE | grep -qi darwin || echo $OSTYPE | grep -qi bsd; then |
| 29 | + echo "System is $OSTYPE" |
| 30 | + |
| 31 | + if ! command -v ggrep > /dev/null; then |
| 32 | + echo "No ggrep found for darwin/bsd system, exit 1" |
| 33 | + exit 1 |
| 34 | + fi |
| 35 | + |
| 36 | + if ! command -v gsed > /dev/null; then |
| 37 | + echo "No gsed found for darwin/bsd system, exit 1" |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | + |
| 41 | + alias grep='ggrep' |
| 42 | + alias sed='gsed' |
| 43 | + |
| 44 | + echo "Switch grep to ggrep, sed to gsed on macOS / BSD servers" |
| 45 | + |
| 46 | +fi |
| 47 | + |
| 48 | +if ! command -v yq > /dev/null; then |
| 49 | + echo "No yq found on the system, exit 1" |
| 50 | + exit 1 |
| 51 | +else |
| 52 | + yq_version=`yq --version | grep -Eo 'v[0-9.]+' | cut -d. -f1` |
| 53 | + if [ "$yq_version" != "v4" ]; then |
| 54 | + echo "You must install v4+ version of yq to run this script, exit 1" |
| 55 | + exit 1 |
| 56 | + else |
| 57 | + echo "yq verified: $yq_version" |
| 58 | + fi |
| 59 | +fi |
| 60 | + |
| 61 | +if [ -z "$INPUT_MANIFEST" ]; then |
| 62 | + echo "User should provide manifest file as the input, e.g. ../../manifests/2.7.0/opensearch-2.7.0.yml, exit 1" |
| 63 | + exit 1 |
| 64 | +fi |
| 65 | + |
| 66 | +if ! yq -v "$INPUT_MANIFEST" > /dev/null 2>&1; then |
| 67 | + echo "$INPUT_MANIFEST is either not found, or is not a valid yaml file, exit 1" |
| 68 | + exit 1 |
| 69 | +fi |
| 70 | + |
| 71 | + |
| 72 | +### Main Steps: Get Links ### |
| 73 | + |
| 74 | +# Get all release notes links for all repos |
| 75 | +REPO_NAMES_ARRAY=( `yq -r '.components.[].repository' $INPUT_MANIFEST` ) |
| 76 | +REPO_REFS_ARRAY=( `yq -r '.components.[].ref' $INPUT_MANIFEST` ) |
| 77 | +COMPONENT_NAMES_ARRAY=( `yq -r '.components.[].name' $INPUT_MANIFEST` ) |
| 78 | +BUILD_VERSION=`yq -r '.build.version' $INPUT_MANIFEST` |
| 79 | +NOT_FOUND=0 |
| 80 | + |
| 81 | + |
| 82 | +if [ "$SKIP_ORIG_URLS" != 'true' ]; then |
| 83 | + |
| 84 | + echo -e "\nRetrieve release notes links for all components\n" |
| 85 | + echo -n > $ORIG_URLS_TXT |
| 86 | + |
| 87 | + for index in "${!REPO_NAMES_ARRAY[@]}"; do |
| 88 | + repo_name=`echo ${REPO_NAMES_ARRAY[$index]} | rev | cut -d/ -f1 | rev | sed 's/.git//g'` |
| 89 | + repo_ref=`echo ${REPO_REFS_ARRAY[$index]} | sed 's/tags\///g'` |
| 90 | + component_name=`echo ${COMPONENT_NAMES_ARRAY[$index]} | tr '[:upper:]' '[:lower:]'` |
| 91 | + component_name_prefix="" |
| 92 | + build_version="$BUILD_VERSION.0" |
| 93 | + |
| 94 | + # OS / OSD core |
| 95 | + if [ "$component_name" = "opensearch" ] || [ "$component_name" = "opensearch-dashboards" ]; then |
| 96 | + build_version=$BUILD_VERSION |
| 97 | + continue |
| 98 | + fi |
| 99 | + |
| 100 | + # OS defaults |
| 101 | + if (echo $INPUT_MANIFEST | grep -q "opensearch-$BUILD_VERSION") && ( ! echo $component_name | grep -q "opensearch-"); then |
| 102 | + component_name_prefix="opensearch-" |
| 103 | + fi |
| 104 | + |
| 105 | + # OSD defaults |
| 106 | + if (echo $INPUT_MANIFEST | grep -q "opensearch-dashboards-$BUILD_VERSION") && [ "$component_name" != "opensearch-dashboards" ]; then |
| 107 | + component_name="opensearch-${repo_name}" |
| 108 | + fi |
| 109 | + |
| 110 | + # OS plugins |
| 111 | + if [ "$component_name" = "opensearch" ]; then |
| 112 | + component_name_prefix="" |
| 113 | + fi |
| 114 | + if [ "$component_name" = "job-scheduler" ]; then |
| 115 | + component_name_prefix="opensearch." |
| 116 | + fi |
| 117 | + if [ "$component_name" = "k-nn" ]; then |
| 118 | + component_name="knn" |
| 119 | + fi |
| 120 | + if [ "$component_name" = "ml-commons" ]; then |
| 121 | + component_name="ml-common" |
| 122 | + fi |
| 123 | + if [ "$component_name" = "opensearch-reports" ]; then |
| 124 | + component_name="opensearch-reporting" |
| 125 | + fi |
| 126 | + if [ "$repo_name" = "opensearch-dashboards-functional-test" ] || [ "$component_name" = "notifications-core" ]; then |
| 127 | + continue |
| 128 | + fi |
| 129 | + |
| 130 | + # OSD plugins |
| 131 | + if [ "$repo_name" = "dashboards-observability" ]; then |
| 132 | + component_name=$repo_name |
| 133 | + if [ "$BUILD_VERSION" = "2.8.0" ]; then |
| 134 | + component_name=${repo_name//dashboards/opensearch} |
| 135 | + fi |
| 136 | + fi |
| 137 | + if [ "$repo_name" = "dashboards-query-workbench" ] || [ "$repo_name" = "index-management-dashboards-plugin" ]; then |
| 138 | + component_name="${repo_name//dashboards/opensearch}" |
| 139 | + fi |
| 140 | + if [ "$repo_name" = "anomaly-detection-dashboards-plugin" ] || [ "$repo_name" = "security-analytics-dashboards-plugin" ]; then |
| 141 | + component_name="opensearch-${repo_name//-plugin/}" |
| 142 | + fi |
| 143 | + if [ "$repo_name" = "index-management-dashboards-plugin" ]; then |
| 144 | + component_name="opensearch-$repo_name" |
| 145 | + fi |
| 146 | + |
| 147 | + release_note_url="https://raw.githubusercontent.com/opensearch-project/$repo_name/$repo_ref/release-notes/$component_name_prefix$component_name.release-notes-$build_version.md" |
| 148 | + |
| 149 | + if curl --output /dev/null --silent --fail -r 0-0 "$release_note_url"; then |
| 150 | + echo "Release notes found: $release_note_url" |
| 151 | + ORIG_URLS_ARRAY+=("$release_note_url") |
| 152 | + else |
| 153 | + NOT_FOUND=$(( NOT_FOUND + 1 )) |
| 154 | + echo "Release notes NOT found: $release_note_url" |
| 155 | + fi |
| 156 | + |
| 157 | + |
| 158 | + done |
| 159 | + |
| 160 | + |
| 161 | + # Results |
| 162 | + if [ "$NOT_FOUND" -eq 0 ]; then |
| 163 | + echo -e "\nRelease Note found for all components" |
| 164 | + echo "Write all linkes to local file: $ORIG_URLS_TXT" |
| 165 | + echo "${ORIG_URLS_ARRAY[@]}" | tr ' ' '\n' > $ORIG_URLS_TXT |
| 166 | + else |
| 167 | + echo -e "\nRelease Note NOT FOUND for $NOT_FOUND components, exit 1" |
| 168 | + exit 1 |
| 169 | + fi |
| 170 | + |
| 171 | +else |
| 172 | + echo -e "\nSkip release notes link retrieval and use the existing links in $ORIG_URLS_TXT\n" |
| 173 | + |
| 174 | +fi |
| 175 | + |
| 176 | +### Main Stage: Analyze and Re-order the Release Notes ### |
| 177 | + |
| 178 | +echo -e "Clean up urls in the file\n" |
| 179 | +# Removen empty space and newlines here and sort |
| 180 | +sed -e 's/^[ \t]*//' -e '/^$/d' $ORIG_URLS_TXT | sort | uniq > $ORIG_URLS_TXT.tweaks |
| 181 | +echo -e "Release Notes $BUILD_VERSION\n\n" > $RELEASE_NOTE_MD |
| 182 | + |
| 183 | +IFS="," |
| 184 | +for category in $RELEASENOTES_CATEGORIES; do |
| 185 | + echo $category |
| 186 | + cat_main=`echo $category | cut -d '#' -f 1` |
| 187 | + echo "## $cat_main" >> $RELEASE_NOTE_MD |
| 188 | + echo "" >> $RELEASE_NOTE_MD |
| 189 | + |
| 190 | + IFS="#" |
| 191 | + cat_temp_complete=0 |
| 192 | + for cat_temp in $category; do |
| 193 | + echo $cat_temp |
| 194 | + if [ "$cat_temp_complete" -eq 1 ]; then |
| 195 | + continue |
| 196 | + fi |
| 197 | + |
| 198 | + while read -r url; do |
| 199 | + if [ "${url::1}" != "#" ]; then |
| 200 | + echo $url |
| 201 | + curl -sSLo $ORIG_URLS_TXT.plugin_temp $url |
| 202 | + cat_temp_num=`grep -ni "### $cat_temp" $ORIG_URLS_TXT.plugin_temp | cut -d: -f1` |
| 203 | + if [ -n "$cat_temp_num" ]; then |
| 204 | + # Upper Case every word of the line |
| 205 | + echo -e "\n### `echo $url | cut -d/ -f5 | sed -e 's/\b\(.\)/\u\1/g;s/-Plugin//g'`" >> $RELEASE_NOTE_MD |
| 206 | + # Upper Case first letter of each line |
| 207 | + sed -n "$(( cat_temp_num + 1)),/^$/p" $ORIG_URLS_TXT.plugin_temp | sed 's/\w/\u&/' >> $RELEASE_NOTE_MD |
| 208 | + echo "" >> $RELEASE_NOTE_MD |
| 209 | + #cat_temp_complete=1 |
| 210 | + fi |
| 211 | + fi |
| 212 | + done < $ORIG_URLS_TXT.tweaks |
| 213 | + |
| 214 | + done |
| 215 | + IFS="," |
| 216 | +done |
| 217 | + |
| 218 | + |
| 219 | + |
| 220 | + |
| 221 | + |
| 222 | + |
| 223 | + |
| 224 | + |
| 225 | + |
| 226 | + |
| 227 | + |
| 228 | + |
| 229 | + |
| 230 | + |
| 231 | + |
| 232 | + |
| 233 | + |
| 234 | + |
0 commit comments