| 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 | ecebd77 | 2018-12-28 08:50:58 -0500 | [diff] [blame] | 52 | FILES[appveyor.yml]=simpleReplace | 
|  | 53 | FILES[bower.json]=jsonReplace | 
| Jens Geyer | 56700e4 | 2020-02-22 16:51:51 +0100 | [diff] [blame] | 54 | FILES[CMakeLists.txt]=simpleReplace | 
| Jens Geyer | 7199741 | 2019-10-19 21:22:59 +0200 | [diff] [blame] | 55 | FILES[compiler/cpp/src/thrift/version.h]=simpleReplace | 
| Jens Geyer | 56700e4 | 2020-02-22 16:51:51 +0100 | [diff] [blame] | 56 | FILES[configure.ac]=configureReplace | 
|  | 57 | FILES[contrib/Rebus/Properties/AssemblyInfo.cs]=simpleReplace | 
| James E. King III | ecebd77 | 2018-12-28 08:50:58 -0500 | [diff] [blame] | 58 | FILES[contrib/thrift.spec]=simpleReplace | 
| Jens Geyer | 56700e4 | 2020-02-22 16:51:51 +0100 | [diff] [blame] | 59 | FILES[contrib/zeromq/csharp/AssemblyInfo.cs]=simpleReplace | 
| James E. King III | 234fb47 | 2019-01-13 23:19:18 -0500 | [diff] [blame] | 60 | FILES[doc/specs/idl.md]=simpleReplace | 
| James E. King III | b1d63e7 | 2019-01-22 14:16:39 -0500 | [diff] [blame] | 61 | FILES[lib/as3/gradle.properties]=simpleReplace | 
| James E. King III | ecebd77 | 2018-12-28 08:50:58 -0500 | [diff] [blame] | 62 | FILES[lib/d/src/thrift/base.d]=simpleReplace | 
|  | 63 | FILES[lib/dart/pubspec.yaml]=pubspecReplace | 
|  | 64 | FILES[lib/delphi/src/Thrift.pas]=simpleReplace | 
|  | 65 | FILES[lib/erl/src/thrift.app.src]=simpleReplace | 
|  | 66 | FILES[lib/haxe/haxelib.json]=simpleReplace | 
|  | 67 | FILES[lib/hs/thrift.cabal]=simpleReplace | 
|  | 68 | FILES[lib/java/gradle.properties]=simpleReplace | 
| Jens Geyer | 616df98 | 2019-10-19 22:08:13 +0200 | [diff] [blame] | 69 | FILES[lib/js/package-lock.json]=jsonReplace | 
| Jens Geyer | 56700e4 | 2020-02-22 16:51:51 +0100 | [diff] [blame] | 70 | FILES[lib/js/package.json]=jsonReplace | 
| James E. King III | ecebd77 | 2018-12-28 08:50:58 -0500 | [diff] [blame] | 71 | FILES[lib/js/src/thrift.js]=simpleReplace | 
|  | 72 | FILES[lib/lua/Thrift.lua]=simpleReplace | 
| Jens Geyer | 56700e4 | 2020-02-22 16:51:51 +0100 | [diff] [blame] | 73 | FILES[lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Properties/AssemblyInfo.cs]=simpleReplace | 
|  | 74 | FILES[lib/netstd/Thrift/Properties/AssemblyInfo.cs]=simpleReplace | 
| Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 75 | FILES[lib/netstd/Thrift/Properties/AssemblyInfo.cs]=simpleReplace | 
| Jens Geyer | b75e88a | 2019-10-17 21:56:39 +0200 | [diff] [blame] | 76 | FILES[lib/netstd/Thrift/Thrift.csproj]=simpleReplace | 
| James E. King III | ecebd77 | 2018-12-28 08:50:58 -0500 | [diff] [blame] | 77 | FILES[lib/ocaml/_oasis]=simpleReplace | 
|  | 78 | FILES[lib/perl/lib/Thrift.pm]=simpleReplace | 
|  | 79 | FILES[lib/py/setup.py]=simpleReplace | 
|  | 80 | FILES[lib/rb/thrift.gemspec]=simpleReplace | 
|  | 81 | FILES[lib/rs/Cargo.toml]=simpleReplace | 
|  | 82 | FILES[lib/st/package.xml]=simpleReplace | 
| James E. King III | d7c11ad | 2019-01-11 19:19:44 -0500 | [diff] [blame] | 83 | FILES[lib/swift/Sources/Thrift.swift]=simpleReplace | 
| James E. King III | 1735542 | 2019-01-11 23:06:08 -0500 | [diff] [blame] | 84 | FILES[lib/swift/Tests/ThriftTests/ThriftTests.swift]=simpleReplace | 
| Jens Geyer | 616df98 | 2019-10-19 22:08:13 +0200 | [diff] [blame] | 85 | FILES[lib/ts/package-lock.json]=jsonReplace | 
| Jens Geyer | 56700e4 | 2020-02-22 16:51:51 +0100 | [diff] [blame] | 86 | FILES[lib/ts/package.json]=jsonReplace | 
| Jens Geyer | 616df98 | 2019-10-19 22:08:13 +0200 | [diff] [blame] | 87 | FILES[package-lock.json]=jsonReplace | 
| Jens Geyer | 56700e4 | 2020-02-22 16:51:51 +0100 | [diff] [blame] | 88 | FILES[package.json]=jsonReplace | 
| James E. King III | ecebd77 | 2018-12-28 08:50:58 -0500 | [diff] [blame] | 89 | FILES[sonar-project.properties]=simpleReplace | 
| James E. King III | ecebd77 | 2018-12-28 08:50:58 -0500 | [diff] [blame] | 90 | FILES[test/dart/test_client/pubspec.yaml]=pubspecReplace | 
|  | 91 | FILES[test/erl/src/thrift_test.app.src]=simpleReplace | 
| Jens Geyer | 56700e4 | 2020-02-22 16:51:51 +0100 | [diff] [blame] | 92 | FILES[test/netstd/Client/Properties/AssemblyInfo.cs]=simpleReplace | 
|  | 93 | FILES[test/netstd/Server/Properties/AssemblyInfo.cs]=simpleReplace | 
|  | 94 | FILES[Thrift.podspec]=simpleReplace | 
| James E. King III | ecebd77 | 2018-12-28 08:50:58 -0500 | [diff] [blame] | 95 | FILES[tutorial/dart/client/pubspec.yaml]=pubspecReplace | 
|  | 96 | FILES[tutorial/dart/console_client/pubspec.yaml]=pubspecReplace | 
|  | 97 | FILES[tutorial/dart/server/pubspec.yaml]=pubspecReplace | 
|  | 98 | FILES[tutorial/delphi/DelphiClient/DelphiClient.dproj]=simpleReplace | 
|  | 99 | FILES[tutorial/delphi/DelphiServer/DelphiServer.dproj]=simpleReplace | 
|  | 100 | FILES[tutorial/hs/ThriftTutorial.cabal]=simpleReplace | 
| Jens Geyer | 56700e4 | 2020-02-22 16:51:51 +0100 | [diff] [blame] | 101 | FILES[tutorial/netstd/Client/Properties/AssemblyInfo.cs]=simpleReplace | 
|  | 102 | FILES[tutorial/netstd/Interfaces/Properties/AssemblyInfo.cs]=simpleReplace | 
|  | 103 | FILES[tutorial/netstd/Server/Properties/AssemblyInfo.cs]=simpleReplace | 
| James E. King III | ecebd77 | 2018-12-28 08:50:58 -0500 | [diff] [blame] | 104 | FILES[tutorial/ocaml/_oasis]=simpleReplace | 
|  | 105 |  | 
| Jens Geyer | 56700e4 | 2020-02-22 16:51:51 +0100 | [diff] [blame] | 106 |  | 
|  | 107 |  | 
| James E. King III | c9ac8d2 | 2019-01-07 16:46:45 -0500 | [diff] [blame] | 108 | if [ ! -f "CHANGES.md" ]; then | 
| James E. King III | ecebd77 | 2018-12-28 08:50:58 -0500 | [diff] [blame] | 109 | >&2 echo "error: run veralign.sh while in the thrift root directory" | 
|  | 110 | exit 1 | 
|  | 111 | fi | 
|  | 112 |  | 
|  | 113 | if [ $# -ne 2 ]; then | 
|  | 114 | >&2 echo "usage: veralign.sh <oldVersion> <newVersion>" | 
|  | 115 | exit 1 | 
|  | 116 | fi | 
|  | 117 |  | 
|  | 118 | jq --version 1>/dev/null 2>/dev/null | 
|  | 119 | if [ $? -ne 0 ]; then | 
|  | 120 | >&2 echo "error: the 'jq' package is not installed" | 
|  | 121 | exit 1 | 
|  | 122 | fi | 
|  | 123 |  | 
|  | 124 | # | 
|  | 125 | # validateVersion: check that a version matches the major.minor.patch | 
|  | 126 | #   format which is the lowest common denominator supported by all | 
|  | 127 | #   project systems. | 
|  | 128 | # \param $1 the version | 
|  | 129 | # \returns 0 if the version is compliant | 
|  | 130 | # | 
|  | 131 | function validateVersion | 
|  | 132 | { | 
|  | 133 | local result | 
|  | 134 | local valid | 
|  | 135 | valid=$(echo "$1" | sed '/^[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+$/!{q22}') | 
|  | 136 | result=$? | 
|  | 137 | if [ $result -eq 22 ]; then | 
|  | 138 | >&2 echo "error: version '$1' does not conform to the required major.minor.patch format" | 
|  | 139 | return ${result} | 
|  | 140 | fi | 
|  | 141 | } | 
|  | 142 |  | 
|  | 143 | OLDVERSION=$1 | 
|  | 144 | NEWVERSION=$2 | 
|  | 145 | validateVersion "${OLDVERSION}" || exit $? | 
|  | 146 | validateVersion "${NEWVERSION}" || exit $? | 
|  | 147 |  | 
|  | 148 | # | 
|  | 149 | # escapeVersion: escape the version for use as a sed search | 
|  | 150 | # \param $1 the version to escape | 
|  | 151 | # \output the escaped string | 
|  | 152 | # \returns 0 | 
|  | 153 | # \example VERSEARCH=$(escapeVersion "[1.0.0]"); echo $VERSEARCH; => "\[1\.0\.0\]" | 
|  | 154 | # | 
|  | 155 | function escapeVersion | 
|  | 156 | { | 
|  | 157 | echo "$(echo $1 | sed 's/\./\\./g' | sed 's/\[/\\\[/g' | sed 's/\]/\\\]/g')" | 
|  | 158 | } | 
|  | 159 |  | 
|  | 160 | # Set up verbose hilighting if running interactive | 
|  | 161 | if [ "$(tput colors)" -ne 0 ]; then | 
|  | 162 | reverse=$(tput rev) | 
|  | 163 | red=$(tput setaf 1) | 
|  | 164 | green=$(tput setaf 2) | 
|  | 165 | yellow=$(tput setaf 3) | 
|  | 166 | normal=$(tput sgr0) | 
|  | 167 | fi | 
|  | 168 |  | 
|  | 169 | declare -A MANUAL | 
|  | 170 |  | 
|  | 171 | # | 
|  | 172 | # manual: note that update of said file is manual | 
|  | 173 | # \param $1 filename to do replacements on | 
|  | 174 | # \returns 0 | 
|  | 175 | # | 
|  | 176 | function manual | 
|  | 177 | { | 
|  | 178 | MANUAL["$1"]="" | 
|  | 179 | return 0 | 
|  | 180 | } | 
|  | 181 |  | 
|  | 182 | # | 
|  | 183 | # configureReplace: replace the AC_INIT field in configure.ac | 
|  | 184 | # \param $1 filename to do replacements on | 
|  | 185 | # \returns 0 on success | 
|  | 186 | # | 
|  | 187 |  | 
|  | 188 | function configureReplace | 
|  | 189 | { | 
|  | 190 | replace "$1" "[thrift], [${OLDVERSION}]" "[thrift], [${NEWVERSION}]" | 
|  | 191 | } | 
|  | 192 |  | 
|  | 193 | # | 
|  | 194 | # jsonReplace: replace a specific version field in a JSON file | 
|  | 195 | #   must be a top level "version" field in the json structure | 
|  | 196 | # \param $1 filename to do replacements on | 
|  | 197 | # \returns 0 on success | 
|  | 198 | # | 
|  | 199 |  | 
|  | 200 | function jsonReplace | 
|  | 201 | { | 
|  | 202 | local result | 
|  | 203 | local output | 
|  | 204 | if [ ! -z "$DRYRUN" ]; then | 
|  | 205 | output=$(jq -e ".version" "$1") | 
|  | 206 | else | 
|  | 207 | output=$(jq -e ".version = \"${NEWVERSION}\"" "$1" > tmp.$$.json && mv tmp.$$.json "$1") | 
|  | 208 | fi | 
|  | 209 | result=$? | 
|  | 210 | if [ $? -ne 0 ]; then | 
|  | 211 | printf "%-60s | %5d | ${red}ERROR${normal}: version tag not found" "$1" "$count" | 
|  | 212 | echo | 
|  | 213 | return 1 | 
|  | 214 | elif [ ! -z "$DRYRUN" ]; then | 
|  | 215 | output=${output%\"} | 
|  | 216 | output=${output#\"} | 
|  | 217 | printf "%-60s | %5d | MATCHES:   version: \"${reverse}${green}${output}${normal}\"" "$1" 1 | 
|  | 218 | echo | 
|  | 219 | return 0 | 
|  | 220 | fi | 
|  | 221 | printf "%-60s | %5d | ${green}OK${normal}" "$1" 1 | 
|  | 222 | echo | 
|  | 223 | return 0 | 
|  | 224 | } | 
|  | 225 |  | 
|  | 226 | # | 
|  | 227 | # pubspecReplace: replace a specific version field in a YAML file | 
|  | 228 | #   must be a top level "version" field in the yaml structure | 
|  | 229 | #   did not find a package that preserves comments so this is | 
|  | 230 | #   somewhat brain-dead, but it gets the job done | 
|  | 231 | # \param $1 filename to do replacements on | 
|  | 232 | # \returns 0 on success | 
|  | 233 | # | 
|  | 234 |  | 
|  | 235 | function pubspecReplace | 
|  | 236 | { | 
|  | 237 | replace "$1" "version: ${OLDVERSION}" "version: ${NEWVERSION}" | 
|  | 238 | } | 
|  | 239 |  | 
|  | 240 | # | 
|  | 241 | # replace: replace occurrences of one string with another | 
|  | 242 | #     the file specified must contain the old string at least once | 
|  | 243 | #     in order to be successful. | 
|  | 244 | # \param $1 filename to do replacements on | 
|  | 245 | # \param $2 the "old" string to be replaced | 
|  | 246 | # \param $3 the "new" striing to replace it with | 
|  | 247 | # \returns 0 on success | 
|  | 248 | # | 
|  | 249 | function replace | 
|  | 250 | { | 
|  | 251 | local result | 
|  | 252 | local output | 
|  | 253 | local oldString="$2" | 
|  | 254 | local newString="$3" | 
|  | 255 | local oldRegex=$(escapeVersion "${oldString}") | 
|  | 256 | local count=$(grep -Ec "${oldRegex}" "$1") | 
|  | 257 | local verbose | 
|  | 258 | if [ $count -eq 0 ]; then | 
|  | 259 | printf "%-60s | %5d | ${red}NOT FOUND${normal}: ${oldString}" "$1" 0 | 
|  | 260 | echo | 
|  | 261 | return 1 | 
|  | 262 | elif [ ! -z "$DRYRUN" ]; then | 
|  | 263 | printf "%-60s | %5d | MATCHES:" "$1" "$count" | 
|  | 264 | echo | 
|  | 265 | while read -r line; do | 
|  | 266 | echo " > $(echo "$line" | sed "s/${oldRegex}/${reverse}${green}${oldString}${normal}/g")" | 
|  | 267 | done < <(grep -E "${oldRegex}" "$1") | 
|  | 268 | return 0 | 
|  | 269 | fi | 
|  | 270 | output=$(sed -i "s/${oldRegex}/${newString}/g" "$1") | 
|  | 271 | result=$? | 
|  | 272 | if [ $result -ne 0 ]; then | 
|  | 273 | printf "%-60s | %5d | ${red}ERROR${normal}: %s" "$1" "$count" "$output" | 
|  | 274 | echo | 
|  | 275 | return 1 | 
|  | 276 | fi | 
|  | 277 | printf "%-60s | %5d | ${green}OK${normal}" "$1" "$count" | 
|  | 278 | echo | 
|  | 279 | return 0 | 
|  | 280 | } | 
|  | 281 |  | 
|  | 282 | # | 
|  | 283 | # simpleReplace: replace occurrences of ${OLDVERSION} with ${NEWVERSION} | 
|  | 284 | #     the file specified must contain OLDVERSION at least once | 
|  | 285 | #     in order to be successful. | 
|  | 286 | # \param $1 filename to do replacements on | 
|  | 287 | # \param $2 the "old" string to be replaced | 
|  | 288 | # \param $3 the "new" striing to replace it with | 
|  | 289 | # \returns 0 on success | 
|  | 290 | # | 
|  | 291 | function simpleReplace | 
|  | 292 | { | 
|  | 293 | replace "$1" "${OLDVERSION}" "${NEWVERSION}" | 
|  | 294 | } | 
|  | 295 |  | 
|  | 296 | echo "" | 
|  | 297 | echo "Apache Thrift Version Alignment Tool" | 
|  | 298 | echo "------------------------------------" | 
|  | 299 | echo "" | 
|  | 300 | echo "Previous Version: ${OLDVERSION}" | 
|  | 301 | echo "     New Version: ${NEWVERSION}" | 
|  | 302 | echo "" | 
|  | 303 | echo "-------------------------------------------------------------+-------+----------------------" | 
|  | 304 | echo "Filename                                                     | Count | Status               " | 
|  | 305 | echo "-------------------------------------------------------------+-------+----------------------" | 
|  | 306 |  | 
|  | 307 | for file in $(echo "${!FILES[@]}" | sort); do | 
|  | 308 | ${FILES[$file]} $file || exit $? | 
|  | 309 | done | 
|  | 310 |  | 
|  | 311 | echo | 
|  | 312 | echo "Files that must be modified manually:" | 
|  | 313 | echo | 
|  | 314 | for manu in $(echo "${!MANUAL[@]}" | sort); do | 
|  | 315 | echo " > ${yellow}${manu}${normal}" | 
|  | 316 | done | 
|  | 317 |  | 
|  | 318 | exit 0 |