| James E. King III | ecebd77 | 2018-12-28 08:50:58 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash | 
|  | 2 | # | 
|  | 3 | # Licensed to the Apache Software Foundation (ASF) under one | 
|  | 4 | # or more contributor license agreements.  See the NOTICE file | 
|  | 5 | # distributed with this work for additional information | 
|  | 6 | # regarding copyright ownership.  The ASF licenses this file | 
|  | 7 | # to you under the Apache License, Version 2.0 (the | 
|  | 8 | # "License"); you may not use this file except in compliance | 
|  | 9 | # with the License.  You may obtain a copy of the License at | 
|  | 10 | # | 
|  | 11 | #   http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 12 | # | 
|  | 13 | # Unless required by applicable law or agreed to in writing, | 
|  | 14 | # software distributed under the License is distributed on an | 
|  | 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | 
|  | 16 | # KIND, either express or implied.  See the License for the | 
|  | 17 | # specific language governing permissions and limitations | 
|  | 18 | # under the License. | 
|  | 19 | # | 
|  | 20 |  | 
|  | 21 | # | 
|  | 22 | # The veralign script sets the appropriate versions in all of | 
|  | 23 | # the package configuration files for all of the supported | 
|  | 24 | # languages.  It is used to prepare a release or move master | 
|  | 25 | # forward to the next anticipated version. | 
|  | 26 | # | 
|  | 27 | # USAGE | 
|  | 28 | # ----------------------------------------------------------- | 
|  | 29 | # usage: veralign.sh <oldVersion> <newVersion> | 
|  | 30 | # | 
|  | 31 | # EXAMPLE | 
|  | 32 | # ----------------------------------------------------------- | 
|  | 33 | # $ ./veralign.sh 0.12.0 1.0.0 | 
|  | 34 | # $ ./veralign.sh 1.0.0 1.1.0 | 
|  | 35 | # | 
|  | 36 | # IMPORTANT USAGE NOTE | 
|  | 37 | # ----------------------------------------------------------- | 
|  | 38 | # Define the environment variable DRYRUN to have the script | 
|  | 39 | # print out all matches to the oldVersion hilighted so that | 
|  | 40 | # you can verify it will change the right things. | 
|  | 41 | # | 
|  | 42 |  | 
|  | 43 | declare -A FILES | 
|  | 44 |  | 
|  | 45 | # These files require a manual touch: | 
| James E. King III | e824efc | 2019-01-07 16:50:54 -0500 | [diff] [blame] | 46 | FILES[CHANGES.md]=manual | 
| James E. King III | ecebd77 | 2018-12-28 08:50:58 -0500 | [diff] [blame] | 47 | FILES[debian/changelog]=manual | 
|  | 48 | FILES[doap.rdf]=manual | 
|  | 49 |  | 
|  | 50 | # These files can be updated automatically: | 
|  | 51 | FILES[ApacheThrift.nuspec]=simpleReplace | 
| James E. King III | c9ac8d2 | 2019-01-07 16:46:45 -0500 | [diff] [blame] | 52 | FILES[CMakeLists.txt]=simpleReplace | 
| James E. King III | ecebd77 | 2018-12-28 08:50:58 -0500 | [diff] [blame] | 53 | FILES[Thrift-swift3.podspec]=simpleReplace | 
|  | 54 | FILES[Thrift.podspec]=simpleReplace | 
|  | 55 | FILES[appveyor.yml]=simpleReplace | 
|  | 56 | FILES[bower.json]=jsonReplace | 
| James E. King III | ecebd77 | 2018-12-28 08:50:58 -0500 | [diff] [blame] | 57 | FILES[configure.ac]=configureReplace | 
|  | 58 | FILES[contrib/thrift.spec]=simpleReplace | 
|  | 59 | FILES[lib/cocoa/src/Thrift.h]=simpleReplace | 
|  | 60 | FILES[lib/csharp/ThriftMSBuildTask/Properties/AssemblyInfo.cs]=simpleReplace | 
|  | 61 | FILES[lib/csharp/ThriftMSBuildTask/ThriftMSBuildTask.csproj]=simpleReplace | 
|  | 62 | FILES[lib/csharp/src/Properties/AssemblyInfo.cs]=simpleReplace | 
|  | 63 | FILES[lib/csharp/src/Thrift.csproj]=simpleReplace | 
|  | 64 | FILES[lib/csharp/test/Multiplex/Client/MultiplexClient.csproj]=simpleReplace | 
|  | 65 | FILES[lib/csharp/test/Multiplex/Client/Properties/AssemblyInfo.cs]=simpleReplace | 
|  | 66 | FILES[lib/csharp/test/Multiplex/Server/MultiplexServer.csproj]=simpleReplace | 
|  | 67 | FILES[lib/csharp/test/Multiplex/Server/Properties/AssemblyInfo.cs]=simpleReplace | 
|  | 68 | FILES[lib/csharp/test/ThriftMVCTest/Properties/AssemblyInfo.cs]=simpleReplace | 
|  | 69 | FILES[lib/d/src/thrift/base.d]=simpleReplace | 
|  | 70 | FILES[lib/dart/pubspec.yaml]=pubspecReplace | 
|  | 71 | FILES[lib/delphi/src/Thrift.pas]=simpleReplace | 
|  | 72 | FILES[lib/erl/src/thrift.app.src]=simpleReplace | 
|  | 73 | FILES[lib/haxe/haxelib.json]=simpleReplace | 
|  | 74 | FILES[lib/hs/thrift.cabal]=simpleReplace | 
|  | 75 | FILES[lib/java/gradle.properties]=simpleReplace | 
|  | 76 | FILES[lib/js/package.json]=jsonReplace | 
|  | 77 | FILES[lib/js/src/thrift.js]=simpleReplace | 
|  | 78 | FILES[lib/lua/Thrift.lua]=simpleReplace | 
|  | 79 | FILES[lib/netcore/Thrift/Properties/AssemblyInfo.cs]=simpleReplace | 
|  | 80 | FILES[lib/netcore/Thrift/Transports/Client/THttpClientTransport.cs]=simpleReplace | 
|  | 81 | FILES[lib/ocaml/_oasis]=simpleReplace | 
|  | 82 | FILES[lib/perl/lib/Thrift.pm]=simpleReplace | 
|  | 83 | FILES[lib/py/setup.py]=simpleReplace | 
|  | 84 | FILES[lib/rb/thrift.gemspec]=simpleReplace | 
|  | 85 | FILES[lib/rs/Cargo.toml]=simpleReplace | 
|  | 86 | FILES[lib/st/package.xml]=simpleReplace | 
| James E. King III | d7c11ad | 2019-01-11 19:19:44 -0500 | [diff] [blame] | 87 | FILES[lib/swift/Sources/Thrift.swift]=simpleReplace | 
| James E. King III | ecebd77 | 2018-12-28 08:50:58 -0500 | [diff] [blame] | 88 | FILES[package.json]=jsonReplace | 
|  | 89 | FILES[sonar-project.properties]=simpleReplace | 
|  | 90 | FILES[test/csharp/Properties/AssemblyInfo.cs]=simpleReplace | 
|  | 91 | FILES[test/csharp/ThriftTest.csproj]=simpleReplace | 
|  | 92 | FILES[test/dart/test_client/pubspec.yaml]=pubspecReplace | 
|  | 93 | FILES[test/erl/src/thrift_test.app.src]=simpleReplace | 
|  | 94 | FILES[tutorial/csharp/CsharpClient/Properties/AssemblyInfo.cs]=simpleReplace | 
|  | 95 | FILES[tutorial/csharp/CsharpServer/Properties/AssemblyInfo.cs]=simpleReplace | 
|  | 96 | FILES[tutorial/dart/client/pubspec.yaml]=pubspecReplace | 
|  | 97 | FILES[tutorial/dart/console_client/pubspec.yaml]=pubspecReplace | 
|  | 98 | FILES[tutorial/dart/server/pubspec.yaml]=pubspecReplace | 
|  | 99 | FILES[tutorial/delphi/DelphiClient/DelphiClient.dproj]=simpleReplace | 
|  | 100 | FILES[tutorial/delphi/DelphiServer/DelphiServer.dproj]=simpleReplace | 
|  | 101 | FILES[tutorial/hs/ThriftTutorial.cabal]=simpleReplace | 
|  | 102 | FILES[tutorial/ocaml/_oasis]=simpleReplace | 
|  | 103 |  | 
| James E. King III | c9ac8d2 | 2019-01-07 16:46:45 -0500 | [diff] [blame] | 104 | if [ ! -f "CHANGES.md" ]; then | 
| James E. King III | ecebd77 | 2018-12-28 08:50:58 -0500 | [diff] [blame] | 105 | >&2 echo "error: run veralign.sh while in the thrift root directory" | 
|  | 106 | exit 1 | 
|  | 107 | fi | 
|  | 108 |  | 
|  | 109 | if [ $# -ne 2 ]; then | 
|  | 110 | >&2 echo "usage: veralign.sh <oldVersion> <newVersion>" | 
|  | 111 | exit 1 | 
|  | 112 | fi | 
|  | 113 |  | 
|  | 114 | jq --version 1>/dev/null 2>/dev/null | 
|  | 115 | if [ $? -ne 0 ]; then | 
|  | 116 | >&2 echo "error: the 'jq' package is not installed" | 
|  | 117 | exit 1 | 
|  | 118 | fi | 
|  | 119 |  | 
|  | 120 | # | 
|  | 121 | # validateVersion: check that a version matches the major.minor.patch | 
|  | 122 | #   format which is the lowest common denominator supported by all | 
|  | 123 | #   project systems. | 
|  | 124 | # \param $1 the version | 
|  | 125 | # \returns 0 if the version is compliant | 
|  | 126 | # | 
|  | 127 | function validateVersion | 
|  | 128 | { | 
|  | 129 | local result | 
|  | 130 | local valid | 
|  | 131 | valid=$(echo "$1" | sed '/^[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+$/!{q22}') | 
|  | 132 | result=$? | 
|  | 133 | if [ $result -eq 22 ]; then | 
|  | 134 | >&2 echo "error: version '$1' does not conform to the required major.minor.patch format" | 
|  | 135 | return ${result} | 
|  | 136 | fi | 
|  | 137 | } | 
|  | 138 |  | 
|  | 139 | OLDVERSION=$1 | 
|  | 140 | NEWVERSION=$2 | 
|  | 141 | validateVersion "${OLDVERSION}" || exit $? | 
|  | 142 | validateVersion "${NEWVERSION}" || exit $? | 
|  | 143 |  | 
|  | 144 | # | 
|  | 145 | # escapeVersion: escape the version for use as a sed search | 
|  | 146 | # \param $1 the version to escape | 
|  | 147 | # \output the escaped string | 
|  | 148 | # \returns 0 | 
|  | 149 | # \example VERSEARCH=$(escapeVersion "[1.0.0]"); echo $VERSEARCH; => "\[1\.0\.0\]" | 
|  | 150 | # | 
|  | 151 | function escapeVersion | 
|  | 152 | { | 
|  | 153 | echo "$(echo $1 | sed 's/\./\\./g' | sed 's/\[/\\\[/g' | sed 's/\]/\\\]/g')" | 
|  | 154 | } | 
|  | 155 |  | 
|  | 156 | # Set up verbose hilighting if running interactive | 
|  | 157 | if [ "$(tput colors)" -ne 0 ]; then | 
|  | 158 | reverse=$(tput rev) | 
|  | 159 | red=$(tput setaf 1) | 
|  | 160 | green=$(tput setaf 2) | 
|  | 161 | yellow=$(tput setaf 3) | 
|  | 162 | normal=$(tput sgr0) | 
|  | 163 | fi | 
|  | 164 |  | 
|  | 165 | declare -A MANUAL | 
|  | 166 |  | 
|  | 167 | # | 
|  | 168 | # manual: note that update of said file is manual | 
|  | 169 | # \param $1 filename to do replacements on | 
|  | 170 | # \returns 0 | 
|  | 171 | # | 
|  | 172 | function manual | 
|  | 173 | { | 
|  | 174 | MANUAL["$1"]="" | 
|  | 175 | return 0 | 
|  | 176 | } | 
|  | 177 |  | 
|  | 178 | # | 
|  | 179 | # configureReplace: replace the AC_INIT field in configure.ac | 
|  | 180 | # \param $1 filename to do replacements on | 
|  | 181 | # \returns 0 on success | 
|  | 182 | # | 
|  | 183 |  | 
|  | 184 | function configureReplace | 
|  | 185 | { | 
|  | 186 | replace "$1" "[thrift], [${OLDVERSION}]" "[thrift], [${NEWVERSION}]" | 
|  | 187 | } | 
|  | 188 |  | 
|  | 189 | # | 
|  | 190 | # jsonReplace: replace a specific version field in a JSON file | 
|  | 191 | #   must be a top level "version" field in the json structure | 
|  | 192 | # \param $1 filename to do replacements on | 
|  | 193 | # \returns 0 on success | 
|  | 194 | # | 
|  | 195 |  | 
|  | 196 | function jsonReplace | 
|  | 197 | { | 
|  | 198 | local result | 
|  | 199 | local output | 
|  | 200 | if [ ! -z "$DRYRUN" ]; then | 
|  | 201 | output=$(jq -e ".version" "$1") | 
|  | 202 | else | 
|  | 203 | output=$(jq -e ".version = \"${NEWVERSION}\"" "$1" > tmp.$$.json && mv tmp.$$.json "$1") | 
|  | 204 | fi | 
|  | 205 | result=$? | 
|  | 206 | if [ $? -ne 0 ]; then | 
|  | 207 | printf "%-60s | %5d | ${red}ERROR${normal}: version tag not found" "$1" "$count" | 
|  | 208 | echo | 
|  | 209 | return 1 | 
|  | 210 | elif [ ! -z "$DRYRUN" ]; then | 
|  | 211 | output=${output%\"} | 
|  | 212 | output=${output#\"} | 
|  | 213 | printf "%-60s | %5d | MATCHES:   version: \"${reverse}${green}${output}${normal}\"" "$1" 1 | 
|  | 214 | echo | 
|  | 215 | return 0 | 
|  | 216 | fi | 
|  | 217 | printf "%-60s | %5d | ${green}OK${normal}" "$1" 1 | 
|  | 218 | echo | 
|  | 219 | return 0 | 
|  | 220 | } | 
|  | 221 |  | 
|  | 222 | # | 
|  | 223 | # pubspecReplace: replace a specific version field in a YAML file | 
|  | 224 | #   must be a top level "version" field in the yaml structure | 
|  | 225 | #   did not find a package that preserves comments so this is | 
|  | 226 | #   somewhat brain-dead, but it gets the job done | 
|  | 227 | # \param $1 filename to do replacements on | 
|  | 228 | # \returns 0 on success | 
|  | 229 | # | 
|  | 230 |  | 
|  | 231 | function pubspecReplace | 
|  | 232 | { | 
|  | 233 | replace "$1" "version: ${OLDVERSION}" "version: ${NEWVERSION}" | 
|  | 234 | } | 
|  | 235 |  | 
|  | 236 | # | 
|  | 237 | # replace: replace occurrences of one string with another | 
|  | 238 | #     the file specified must contain the old string at least once | 
|  | 239 | #     in order to be successful. | 
|  | 240 | # \param $1 filename to do replacements on | 
|  | 241 | # \param $2 the "old" string to be replaced | 
|  | 242 | # \param $3 the "new" striing to replace it with | 
|  | 243 | # \returns 0 on success | 
|  | 244 | # | 
|  | 245 | function replace | 
|  | 246 | { | 
|  | 247 | local result | 
|  | 248 | local output | 
|  | 249 | local oldString="$2" | 
|  | 250 | local newString="$3" | 
|  | 251 | local oldRegex=$(escapeVersion "${oldString}") | 
|  | 252 | local count=$(grep -Ec "${oldRegex}" "$1") | 
|  | 253 | local verbose | 
|  | 254 | if [ $count -eq 0 ]; then | 
|  | 255 | printf "%-60s | %5d | ${red}NOT FOUND${normal}: ${oldString}" "$1" 0 | 
|  | 256 | echo | 
|  | 257 | return 1 | 
|  | 258 | elif [ ! -z "$DRYRUN" ]; then | 
|  | 259 | printf "%-60s | %5d | MATCHES:" "$1" "$count" | 
|  | 260 | echo | 
|  | 261 | while read -r line; do | 
|  | 262 | echo " > $(echo "$line" | sed "s/${oldRegex}/${reverse}${green}${oldString}${normal}/g")" | 
|  | 263 | done < <(grep -E "${oldRegex}" "$1") | 
|  | 264 | return 0 | 
|  | 265 | fi | 
|  | 266 | output=$(sed -i "s/${oldRegex}/${newString}/g" "$1") | 
|  | 267 | result=$? | 
|  | 268 | if [ $result -ne 0 ]; then | 
|  | 269 | printf "%-60s | %5d | ${red}ERROR${normal}: %s" "$1" "$count" "$output" | 
|  | 270 | echo | 
|  | 271 | return 1 | 
|  | 272 | fi | 
|  | 273 | printf "%-60s | %5d | ${green}OK${normal}" "$1" "$count" | 
|  | 274 | echo | 
|  | 275 | return 0 | 
|  | 276 | } | 
|  | 277 |  | 
|  | 278 | # | 
|  | 279 | # simpleReplace: replace occurrences of ${OLDVERSION} with ${NEWVERSION} | 
|  | 280 | #     the file specified must contain OLDVERSION at least once | 
|  | 281 | #     in order to be successful. | 
|  | 282 | # \param $1 filename to do replacements on | 
|  | 283 | # \param $2 the "old" string to be replaced | 
|  | 284 | # \param $3 the "new" striing to replace it with | 
|  | 285 | # \returns 0 on success | 
|  | 286 | # | 
|  | 287 | function simpleReplace | 
|  | 288 | { | 
|  | 289 | replace "$1" "${OLDVERSION}" "${NEWVERSION}" | 
|  | 290 | } | 
|  | 291 |  | 
|  | 292 | echo "" | 
|  | 293 | echo "Apache Thrift Version Alignment Tool" | 
|  | 294 | echo "------------------------------------" | 
|  | 295 | echo "" | 
|  | 296 | echo "Previous Version: ${OLDVERSION}" | 
|  | 297 | echo "     New Version: ${NEWVERSION}" | 
|  | 298 | echo "" | 
|  | 299 | echo "-------------------------------------------------------------+-------+----------------------" | 
|  | 300 | echo "Filename                                                     | Count | Status               " | 
|  | 301 | echo "-------------------------------------------------------------+-------+----------------------" | 
|  | 302 |  | 
|  | 303 | for file in $(echo "${!FILES[@]}" | sort); do | 
|  | 304 | ${FILES[$file]} $file || exit $? | 
|  | 305 | done | 
|  | 306 |  | 
|  | 307 | echo | 
|  | 308 | echo "Files that must be modified manually:" | 
|  | 309 | echo | 
|  | 310 | for manu in $(echo "${!MANUAL[@]}" | sort); do | 
|  | 311 | echo " > ${yellow}${manu}${normal}" | 
|  | 312 | done | 
|  | 313 |  | 
|  | 314 | exit 0 |