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