blob: 7080237a22b31b89e28fa7fead30e51d78bb685a [file] [log] [blame]
James E. King IIIecebd772018-12-28 08:50:58 -05001#!/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
43declare -A FILES
44
45# These files require a manual touch:
James E. King IIIe824efc2019-01-07 16:50:54 -050046FILES[CHANGES.md]=manual
James E. King IIIecebd772018-12-28 08:50:58 -050047FILES[debian/changelog]=manual
48FILES[doap.rdf]=manual
49
50# These files can be updated automatically:
51FILES[ApacheThrift.nuspec]=simpleReplace
James E. King IIIecebd772018-12-28 08:50:58 -050052FILES[appveyor.yml]=simpleReplace
53FILES[bower.json]=jsonReplace
Jens Geyer56700e42020-02-22 16:51:51 +010054FILES[CMakeLists.txt]=simpleReplace
Jens Geyer71997412019-10-19 21:22:59 +020055FILES[compiler/cpp/src/thrift/version.h]=simpleReplace
Jens Geyer56700e42020-02-22 16:51:51 +010056FILES[configure.ac]=configureReplace
57FILES[contrib/Rebus/Properties/AssemblyInfo.cs]=simpleReplace
James E. King IIIecebd772018-12-28 08:50:58 -050058FILES[contrib/thrift.spec]=simpleReplace
Jens Geyer56700e42020-02-22 16:51:51 +010059FILES[contrib/zeromq/csharp/AssemblyInfo.cs]=simpleReplace
James Z.M. Gao93ae7af2021-01-06 11:51:41 +080060FILES[contrib/thrift-maven-plugin/pom.xml]=pomReplace
James E. King III234fb472019-01-13 23:19:18 -050061FILES[doc/specs/idl.md]=simpleReplace
James E. King IIIb1d63e72019-01-22 14:16:39 -050062FILES[lib/as3/gradle.properties]=simpleReplace
James E. King IIIecebd772018-12-28 08:50:58 -050063FILES[lib/d/src/thrift/base.d]=simpleReplace
64FILES[lib/dart/pubspec.yaml]=pubspecReplace
65FILES[lib/delphi/src/Thrift.pas]=simpleReplace
66FILES[lib/erl/src/thrift.app.src]=simpleReplace
67FILES[lib/haxe/haxelib.json]=simpleReplace
68FILES[lib/hs/thrift.cabal]=simpleReplace
69FILES[lib/java/gradle.properties]=simpleReplace
Jens Geyer616df982019-10-19 22:08:13 +020070FILES[lib/js/package-lock.json]=jsonReplace
Jens Geyer56700e42020-02-22 16:51:51 +010071FILES[lib/js/package.json]=jsonReplace
James E. King IIIecebd772018-12-28 08:50:58 -050072FILES[lib/js/src/thrift.js]=simpleReplace
73FILES[lib/lua/Thrift.lua]=simpleReplace
Jens Geyer3fc0b8d2021-02-11 23:17:45 +010074FILES[lib/netstd/Tests/Thrift.Tests/Thrift.Tests.csproj]=simpleReplace
75FILES[lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift.PublicInterfaces.Compile.Tests.csproj]=simpleReplace
76FILES[lib/netstd/Tests/Thrift.IntegrationTests/Thrift.IntegrationTests.csproj]=simpleReplace
Jens Geyeraa0c8b32019-01-28 23:27:45 +010077FILES[lib/netstd/Thrift/Properties/AssemblyInfo.cs]=simpleReplace
Jens Geyerb75e88a2019-10-17 21:56:39 +020078FILES[lib/netstd/Thrift/Thrift.csproj]=simpleReplace
James E. King IIIecebd772018-12-28 08:50:58 -050079FILES[lib/ocaml/_oasis]=simpleReplace
80FILES[lib/perl/lib/Thrift.pm]=simpleReplace
81FILES[lib/py/setup.py]=simpleReplace
82FILES[lib/rb/thrift.gemspec]=simpleReplace
83FILES[lib/rs/Cargo.toml]=simpleReplace
84FILES[lib/st/package.xml]=simpleReplace
James E. King IIId7c11ad2019-01-11 19:19:44 -050085FILES[lib/swift/Sources/Thrift.swift]=simpleReplace
James E. King III17355422019-01-11 23:06:08 -050086FILES[lib/swift/Tests/ThriftTests/ThriftTests.swift]=simpleReplace
Jens Geyer616df982019-10-19 22:08:13 +020087FILES[lib/ts/package-lock.json]=jsonReplace
Jens Geyer56700e42020-02-22 16:51:51 +010088FILES[lib/ts/package.json]=jsonReplace
Jens Geyer616df982019-10-19 22:08:13 +020089FILES[package-lock.json]=jsonReplace
Jens Geyer56700e42020-02-22 16:51:51 +010090FILES[package.json]=jsonReplace
James E. King IIIecebd772018-12-28 08:50:58 -050091FILES[sonar-project.properties]=simpleReplace
James E. King IIIecebd772018-12-28 08:50:58 -050092FILES[test/dart/test_client/pubspec.yaml]=pubspecReplace
93FILES[test/erl/src/thrift_test.app.src]=simpleReplace
Jens Geyer3fc0b8d2021-02-11 23:17:45 +010094FILES[test/netstd/Client/Client.csproj]=simpleReplace
95FILES[test/netstd/Server/Server.csproj]=simpleReplace
Jens Geyer56700e42020-02-22 16:51:51 +010096FILES[Thrift.podspec]=simpleReplace
James E. King IIIecebd772018-12-28 08:50:58 -050097FILES[tutorial/dart/client/pubspec.yaml]=pubspecReplace
98FILES[tutorial/dart/console_client/pubspec.yaml]=pubspecReplace
99FILES[tutorial/dart/server/pubspec.yaml]=pubspecReplace
100FILES[tutorial/delphi/DelphiClient/DelphiClient.dproj]=simpleReplace
101FILES[tutorial/delphi/DelphiServer/DelphiServer.dproj]=simpleReplace
102FILES[tutorial/hs/ThriftTutorial.cabal]=simpleReplace
Jens Geyer3fc0b8d2021-02-11 23:17:45 +0100103FILES[tutorial/netstd/Client/Client.csproj]=simpleReplace
104FILES[tutorial/netstd/Interfaces/Interfaces.csproj]=simpleReplace
105FILES[tutorial/netstd/Server/Server.csproj]=simpleReplace
James E. King IIIecebd772018-12-28 08:50:58 -0500106FILES[tutorial/ocaml/_oasis]=simpleReplace
107
Jens Geyer56700e42020-02-22 16:51:51 +0100108
109
James E. King IIIc9ac8d22019-01-07 16:46:45 -0500110if [ ! -f "CHANGES.md" ]; then
James E. King IIIecebd772018-12-28 08:50:58 -0500111 >&2 echo "error: run veralign.sh while in the thrift root directory"
112 exit 1
113fi
114
115if [ $# -ne 2 ]; then
116 >&2 echo "usage: veralign.sh <oldVersion> <newVersion>"
117 exit 1
118fi
119
120jq --version 1>/dev/null 2>/dev/null
121if [ $? -ne 0 ]; then
122 >&2 echo "error: the 'jq' package is not installed"
123 exit 1
124fi
125
126#
127# validateVersion: check that a version matches the major.minor.patch
128# format which is the lowest common denominator supported by all
129# project systems.
130# \param $1 the version
131# \returns 0 if the version is compliant
132#
133function validateVersion
134{
135 local result
136 local valid
137 valid=$(echo "$1" | sed '/^[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+$/!{q22}')
138 result=$?
139 if [ $result -eq 22 ]; then
140 >&2 echo "error: version '$1' does not conform to the required major.minor.patch format"
141 return ${result}
142 fi
143}
144
145OLDVERSION=$1
146NEWVERSION=$2
147validateVersion "${OLDVERSION}" || exit $?
148validateVersion "${NEWVERSION}" || exit $?
149
150#
151# escapeVersion: escape the version for use as a sed search
152# \param $1 the version to escape
153# \output the escaped string
154# \returns 0
155# \example VERSEARCH=$(escapeVersion "[1.0.0]"); echo $VERSEARCH; => "\[1\.0\.0\]"
156#
157function escapeVersion
158{
James Z.M. Gao93ae7af2021-01-06 11:51:41 +0800159 echo "$(echo "$1" | sed 's/\./\\./g' | sed 's/\[/\\\[/g' | sed 's/\]/\\\]/g')"
James E. King IIIecebd772018-12-28 08:50:58 -0500160}
161
162# Set up verbose hilighting if running interactive
163if [ "$(tput colors)" -ne 0 ]; then
164 reverse=$(tput rev)
165 red=$(tput setaf 1)
166 green=$(tput setaf 2)
167 yellow=$(tput setaf 3)
168 normal=$(tput sgr0)
169fi
170
171declare -A MANUAL
172
173#
174# manual: note that update of said file is manual
175# \param $1 filename to do replacements on
176# \returns 0
177#
178function manual
179{
180 MANUAL["$1"]=""
181 return 0
182}
183
184#
185# configureReplace: replace the AC_INIT field in configure.ac
186# \param $1 filename to do replacements on
187# \returns 0 on success
188#
189
190function configureReplace
191{
192 replace "$1" "[thrift], [${OLDVERSION}]" "[thrift], [${NEWVERSION}]"
193}
194
195#
196# jsonReplace: replace a specific version field in a JSON file
197# must be a top level "version" field in the json structure
198# \param $1 filename to do replacements on
199# \returns 0 on success
200#
201
202function jsonReplace
203{
204 local result
205 local output
206 if [ ! -z "$DRYRUN" ]; then
207 output=$(jq -e ".version" "$1")
208 else
209 output=$(jq -e ".version = \"${NEWVERSION}\"" "$1" > tmp.$$.json && mv tmp.$$.json "$1")
210 fi
211 result=$?
212 if [ $? -ne 0 ]; then
213 printf "%-60s | %5d | ${red}ERROR${normal}: version tag not found" "$1" "$count"
214 echo
215 return 1
216 elif [ ! -z "$DRYRUN" ]; then
217 output=${output%\"}
218 output=${output#\"}
219 printf "%-60s | %5d | MATCHES: version: \"${reverse}${green}${output}${normal}\"" "$1" 1
220 echo
221 return 0
222 fi
223 printf "%-60s | %5d | ${green}OK${normal}" "$1" 1
224 echo
225 return 0
226}
227
228#
229# pubspecReplace: replace a specific version field in a YAML file
230# must be a top level "version" field in the yaml structure
231# did not find a package that preserves comments so this is
232# somewhat brain-dead, but it gets the job done
233# \param $1 filename to do replacements on
234# \returns 0 on success
235#
236
237function pubspecReplace
238{
239 replace "$1" "version: ${OLDVERSION}" "version: ${NEWVERSION}"
240}
241
242#
James Z.M. Gao93ae7af2021-01-06 11:51:41 +0800243# pomReplace: replace a specific version field in a maven pom file
244# must be a top level "version" field in the xml structure
245# \param $1 filename to do replacements on
246# \returns 0 on success
247#
248
249function pomReplace
250{
251 replace "$1" "^ <version>${OLDVERSION}<\/version>" " <version>${NEWVERSION}<\/version>"
252}
253
254#
James E. King IIIecebd772018-12-28 08:50:58 -0500255# replace: replace occurrences of one string with another
256# the file specified must contain the old string at least once
257# in order to be successful.
258# \param $1 filename to do replacements on
259# \param $2 the "old" string to be replaced
260# \param $3 the "new" striing to replace it with
261# \returns 0 on success
262#
263function replace
264{
265 local result
266 local output
267 local oldString="$2"
268 local newString="$3"
269 local oldRegex=$(escapeVersion "${oldString}")
270 local count=$(grep -Ec "${oldRegex}" "$1")
271 local verbose
272 if [ $count -eq 0 ]; then
273 printf "%-60s | %5d | ${red}NOT FOUND${normal}: ${oldString}" "$1" 0
274 echo
275 return 1
276 elif [ ! -z "$DRYRUN" ]; then
277 printf "%-60s | %5d | MATCHES:" "$1" "$count"
278 echo
279 while read -r line; do
280 echo " > $(echo "$line" | sed "s/${oldRegex}/${reverse}${green}${oldString}${normal}/g")"
281 done < <(grep -E "${oldRegex}" "$1")
282 return 0
283 fi
284 output=$(sed -i "s/${oldRegex}/${newString}/g" "$1")
285 result=$?
286 if [ $result -ne 0 ]; then
287 printf "%-60s | %5d | ${red}ERROR${normal}: %s" "$1" "$count" "$output"
288 echo
289 return 1
290 fi
291 printf "%-60s | %5d | ${green}OK${normal}" "$1" "$count"
292 echo
293 return 0
294}
295
296#
297# simpleReplace: replace occurrences of ${OLDVERSION} with ${NEWVERSION}
298# the file specified must contain OLDVERSION at least once
299# in order to be successful.
300# \param $1 filename to do replacements on
301# \param $2 the "old" string to be replaced
302# \param $3 the "new" striing to replace it with
303# \returns 0 on success
304#
305function simpleReplace
306{
307 replace "$1" "${OLDVERSION}" "${NEWVERSION}"
308}
309
310echo ""
311echo "Apache Thrift Version Alignment Tool"
312echo "------------------------------------"
313echo ""
314echo "Previous Version: ${OLDVERSION}"
315echo " New Version: ${NEWVERSION}"
316echo ""
317echo "-------------------------------------------------------------+-------+----------------------"
318echo "Filename | Count | Status "
319echo "-------------------------------------------------------------+-------+----------------------"
320
321for file in $(echo "${!FILES[@]}" | sort); do
322 ${FILES[$file]} $file || exit $?
323done
324
325echo
326echo "Files that must be modified manually:"
327echo
328for manu in $(echo "${!MANUAL[@]}" | sort); do
329 echo " > ${yellow}${manu}${normal}"
330done
331
332exit 0