blob: c15e0010d56f9b55fd1afb1a251214abf182c55a [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
Jens Geyer71997412019-10-19 21:22:59 +020057FILES[compiler/cpp/src/thrift/version.h]=simpleReplace
James E. King IIIecebd772018-12-28 08:50:58 -050058FILES[contrib/thrift.spec]=simpleReplace
James E. King III234fb472019-01-13 23:19:18 -050059FILES[doc/specs/idl.md]=simpleReplace
James E. King IIIb1d63e72019-01-22 14:16:39 -050060FILES[lib/as3/gradle.properties]=simpleReplace
James E. King IIIecebd772018-12-28 08:50:58 -050061FILES[lib/csharp/ThriftMSBuildTask/Properties/AssemblyInfo.cs]=simpleReplace
62FILES[lib/csharp/ThriftMSBuildTask/ThriftMSBuildTask.csproj]=simpleReplace
63FILES[lib/csharp/src/Properties/AssemblyInfo.cs]=simpleReplace
64FILES[lib/csharp/src/Thrift.csproj]=simpleReplace
65FILES[lib/csharp/test/Multiplex/Client/MultiplexClient.csproj]=simpleReplace
66FILES[lib/csharp/test/Multiplex/Client/Properties/AssemblyInfo.cs]=simpleReplace
67FILES[lib/csharp/test/Multiplex/Server/MultiplexServer.csproj]=simpleReplace
68FILES[lib/csharp/test/Multiplex/Server/Properties/AssemblyInfo.cs]=simpleReplace
69FILES[lib/csharp/test/ThriftMVCTest/Properties/AssemblyInfo.cs]=simpleReplace
70FILES[lib/d/src/thrift/base.d]=simpleReplace
71FILES[lib/dart/pubspec.yaml]=pubspecReplace
72FILES[lib/delphi/src/Thrift.pas]=simpleReplace
73FILES[lib/erl/src/thrift.app.src]=simpleReplace
74FILES[lib/haxe/haxelib.json]=simpleReplace
75FILES[lib/hs/thrift.cabal]=simpleReplace
76FILES[lib/java/gradle.properties]=simpleReplace
77FILES[lib/js/package.json]=jsonReplace
Jens Geyer616df982019-10-19 22:08:13 +020078FILES[lib/js/package-lock.json]=jsonReplace
James E. King IIIecebd772018-12-28 08:50:58 -050079FILES[lib/js/src/thrift.js]=simpleReplace
80FILES[lib/lua/Thrift.lua]=simpleReplace
Jens Geyeraa0c8b32019-01-28 23:27:45 +010081FILES[lib/netstd/Thrift/Properties/AssemblyInfo.cs]=simpleReplace
Jens Geyerb75e88a2019-10-17 21:56:39 +020082FILES[lib/netstd/Thrift/Thrift.csproj]=simpleReplace
James E. King IIIecebd772018-12-28 08:50:58 -050083FILES[lib/ocaml/_oasis]=simpleReplace
84FILES[lib/perl/lib/Thrift.pm]=simpleReplace
85FILES[lib/py/setup.py]=simpleReplace
86FILES[lib/rb/thrift.gemspec]=simpleReplace
87FILES[lib/rs/Cargo.toml]=simpleReplace
88FILES[lib/st/package.xml]=simpleReplace
James E. King IIId7c11ad2019-01-11 19:19:44 -050089FILES[lib/swift/Sources/Thrift.swift]=simpleReplace
James E. King III17355422019-01-11 23:06:08 -050090FILES[lib/swift/Tests/ThriftTests/ThriftTests.swift]=simpleReplace
James E. King III3f559942019-01-26 08:12:56 -050091FILES[lib/ts/package.json]=jsonReplace
Jens Geyer616df982019-10-19 22:08:13 +020092FILES[lib/ts/package-lock.json]=jsonReplace
James E. King IIIecebd772018-12-28 08:50:58 -050093FILES[package.json]=jsonReplace
Jens Geyer616df982019-10-19 22:08:13 +020094FILES[package-lock.json]=jsonReplace
James E. King IIIecebd772018-12-28 08:50:58 -050095FILES[sonar-project.properties]=simpleReplace
96FILES[test/csharp/Properties/AssemblyInfo.cs]=simpleReplace
97FILES[test/csharp/ThriftTest.csproj]=simpleReplace
98FILES[test/dart/test_client/pubspec.yaml]=pubspecReplace
99FILES[test/erl/src/thrift_test.app.src]=simpleReplace
100FILES[tutorial/csharp/CsharpClient/Properties/AssemblyInfo.cs]=simpleReplace
101FILES[tutorial/csharp/CsharpServer/Properties/AssemblyInfo.cs]=simpleReplace
102FILES[tutorial/dart/client/pubspec.yaml]=pubspecReplace
103FILES[tutorial/dart/console_client/pubspec.yaml]=pubspecReplace
104FILES[tutorial/dart/server/pubspec.yaml]=pubspecReplace
105FILES[tutorial/delphi/DelphiClient/DelphiClient.dproj]=simpleReplace
106FILES[tutorial/delphi/DelphiServer/DelphiServer.dproj]=simpleReplace
107FILES[tutorial/hs/ThriftTutorial.cabal]=simpleReplace
108FILES[tutorial/ocaml/_oasis]=simpleReplace
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{
159 echo "$(echo $1 | sed 's/\./\\./g' | sed 's/\[/\\\[/g' | sed 's/\]/\\\]/g')"
160}
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#
243# replace: replace occurrences of one string with another
244# the file specified must contain the old string at least once
245# in order to be successful.
246# \param $1 filename to do replacements on
247# \param $2 the "old" string to be replaced
248# \param $3 the "new" striing to replace it with
249# \returns 0 on success
250#
251function replace
252{
253 local result
254 local output
255 local oldString="$2"
256 local newString="$3"
257 local oldRegex=$(escapeVersion "${oldString}")
258 local count=$(grep -Ec "${oldRegex}" "$1")
259 local verbose
260 if [ $count -eq 0 ]; then
261 printf "%-60s | %5d | ${red}NOT FOUND${normal}: ${oldString}" "$1" 0
262 echo
263 return 1
264 elif [ ! -z "$DRYRUN" ]; then
265 printf "%-60s | %5d | MATCHES:" "$1" "$count"
266 echo
267 while read -r line; do
268 echo " > $(echo "$line" | sed "s/${oldRegex}/${reverse}${green}${oldString}${normal}/g")"
269 done < <(grep -E "${oldRegex}" "$1")
270 return 0
271 fi
272 output=$(sed -i "s/${oldRegex}/${newString}/g" "$1")
273 result=$?
274 if [ $result -ne 0 ]; then
275 printf "%-60s | %5d | ${red}ERROR${normal}: %s" "$1" "$count" "$output"
276 echo
277 return 1
278 fi
279 printf "%-60s | %5d | ${green}OK${normal}" "$1" "$count"
280 echo
281 return 0
282}
283
284#
285# simpleReplace: replace occurrences of ${OLDVERSION} with ${NEWVERSION}
286# the file specified must contain OLDVERSION at least once
287# in order to be successful.
288# \param $1 filename to do replacements on
289# \param $2 the "old" string to be replaced
290# \param $3 the "new" striing to replace it with
291# \returns 0 on success
292#
293function simpleReplace
294{
295 replace "$1" "${OLDVERSION}" "${NEWVERSION}"
296}
297
298echo ""
299echo "Apache Thrift Version Alignment Tool"
300echo "------------------------------------"
301echo ""
302echo "Previous Version: ${OLDVERSION}"
303echo " New Version: ${NEWVERSION}"
304echo ""
305echo "-------------------------------------------------------------+-------+----------------------"
306echo "Filename | Count | Status "
307echo "-------------------------------------------------------------+-------+----------------------"
308
309for file in $(echo "${!FILES[@]}" | sort); do
310 ${FILES[$file]} $file || exit $?
311done
312
313echo
314echo "Files that must be modified manually:"
315echo
316for manu in $(echo "${!MANUAL[@]}" | sort); do
317 echo " > ${yellow}${manu}${normal}"
318done
319
320exit 0