blob: f59eaf40a0b28945f6c7674675953802227b5a56 [file] [log] [blame]
Jens Geyer4eee6812023-02-06 23:40:56 +01001#!/usr/bin/env bash
James E. King IIIecebd772018-12-28 08:50:58 -05002#
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 IIIecebd772018-12-28 08:50:58 -050062FILES[lib/d/src/thrift/base.d]=simpleReplace
63FILES[lib/dart/pubspec.yaml]=pubspecReplace
64FILES[lib/delphi/src/Thrift.pas]=simpleReplace
65FILES[lib/erl/src/thrift.app.src]=simpleReplace
66FILES[lib/haxe/haxelib.json]=simpleReplace
James E. King IIIecebd772018-12-28 08:50:58 -050067FILES[lib/java/gradle.properties]=simpleReplace
Jens Geyer616df982019-10-19 22:08:13 +020068FILES[lib/js/package-lock.json]=jsonReplace
Jens Geyer56700e42020-02-22 16:51:51 +010069FILES[lib/js/package.json]=jsonReplace
James E. King IIIecebd772018-12-28 08:50:58 -050070FILES[lib/js/src/thrift.js]=simpleReplace
71FILES[lib/lua/Thrift.lua]=simpleReplace
Jens Geyer3fc0b8d2021-02-11 23:17:45 +010072FILES[lib/netstd/Tests/Thrift.Tests/Thrift.Tests.csproj]=simpleReplace
Jens Geyer0f0e11f2024-07-19 00:44:43 +020073FILES[lib/netstd/Tests/Thrift.Compile.Tests/Thrift.Compile.net8/Thrift.Compile.net8.csproj]=simpleReplace
74FILES[lib/netstd/Tests/Thrift.Compile.Tests/Thrift.Compile.net6/Thrift.Compile.net6.csproj]=simpleReplace
75FILES[lib/netstd/Tests/Thrift.Compile.Tests/Thrift.Compile.netstd2/Thrift.Compile.netstd2.csproj]=simpleReplace
76FILES[lib/netstd/Tests/Thrift.Compile.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
Jens Geyer3fc0b8d2021-02-11 23:17:45 +0100102FILES[tutorial/netstd/Client/Client.csproj]=simpleReplace
103FILES[tutorial/netstd/Interfaces/Interfaces.csproj]=simpleReplace
104FILES[tutorial/netstd/Server/Server.csproj]=simpleReplace
James E. King IIIecebd772018-12-28 08:50:58 -0500105FILES[tutorial/ocaml/_oasis]=simpleReplace
106
Jens Geyer56700e42020-02-22 16:51:51 +0100107
108
James E. King IIIc9ac8d22019-01-07 16:46:45 -0500109if [ ! -f "CHANGES.md" ]; then
James E. King IIIecebd772018-12-28 08:50:58 -0500110 >&2 echo "error: run veralign.sh while in the thrift root directory"
111 exit 1
112fi
113
114if [ $# -ne 2 ]; then
115 >&2 echo "usage: veralign.sh <oldVersion> <newVersion>"
116 exit 1
117fi
118
119jq --version 1>/dev/null 2>/dev/null
120if [ $? -ne 0 ]; then
121 >&2 echo "error: the 'jq' package is not installed"
122 exit 1
123fi
124
125#
126# validateVersion: check that a version matches the major.minor.patch
127# format which is the lowest common denominator supported by all
128# project systems.
129# \param $1 the version
130# \returns 0 if the version is compliant
131#
132function validateVersion
133{
134 local result
135 local valid
136 valid=$(echo "$1" | sed '/^[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+$/!{q22}')
137 result=$?
138 if [ $result -eq 22 ]; then
139 >&2 echo "error: version '$1' does not conform to the required major.minor.patch format"
140 return ${result}
141 fi
142}
143
144OLDVERSION=$1
145NEWVERSION=$2
146validateVersion "${OLDVERSION}" || exit $?
147validateVersion "${NEWVERSION}" || exit $?
148
149#
150# escapeVersion: escape the version for use as a sed search
151# \param $1 the version to escape
152# \output the escaped string
153# \returns 0
154# \example VERSEARCH=$(escapeVersion "[1.0.0]"); echo $VERSEARCH; => "\[1\.0\.0\]"
155#
156function escapeVersion
157{
James Z.M. Gao93ae7af2021-01-06 11:51:41 +0800158 echo "$(echo "$1" | sed 's/\./\\./g' | sed 's/\[/\\\[/g' | sed 's/\]/\\\]/g')"
James E. King IIIecebd772018-12-28 08:50:58 -0500159}
160
161# Set up verbose hilighting if running interactive
162if [ "$(tput colors)" -ne 0 ]; then
163 reverse=$(tput rev)
164 red=$(tput setaf 1)
165 green=$(tput setaf 2)
166 yellow=$(tput setaf 3)
167 normal=$(tput sgr0)
168fi
169
170declare -A MANUAL
171
172#
173# manual: note that update of said file is manual
174# \param $1 filename to do replacements on
175# \returns 0
176#
177function manual
178{
179 MANUAL["$1"]=""
180 return 0
181}
182
183#
184# configureReplace: replace the AC_INIT field in configure.ac
185# \param $1 filename to do replacements on
186# \returns 0 on success
187#
188
189function configureReplace
190{
191 replace "$1" "[thrift], [${OLDVERSION}]" "[thrift], [${NEWVERSION}]"
192}
193
194#
195# jsonReplace: replace a specific version field in a JSON file
196# must be a top level "version" field in the json structure
197# \param $1 filename to do replacements on
198# \returns 0 on success
199#
200
201function jsonReplace
202{
203 local result
204 local output
205 if [ ! -z "$DRYRUN" ]; then
206 output=$(jq -e ".version" "$1")
207 else
208 output=$(jq -e ".version = \"${NEWVERSION}\"" "$1" > tmp.$$.json && mv tmp.$$.json "$1")
209 fi
210 result=$?
211 if [ $? -ne 0 ]; then
212 printf "%-60s | %5d | ${red}ERROR${normal}: version tag not found" "$1" "$count"
213 echo
214 return 1
215 elif [ ! -z "$DRYRUN" ]; then
216 output=${output%\"}
217 output=${output#\"}
218 printf "%-60s | %5d | MATCHES: version: \"${reverse}${green}${output}${normal}\"" "$1" 1
219 echo
220 return 0
221 fi
222 printf "%-60s | %5d | ${green}OK${normal}" "$1" 1
223 echo
224 return 0
225}
226
227#
228# pubspecReplace: replace a specific version field in a YAML file
229# must be a top level "version" field in the yaml structure
230# did not find a package that preserves comments so this is
231# somewhat brain-dead, but it gets the job done
232# \param $1 filename to do replacements on
233# \returns 0 on success
234#
235
236function pubspecReplace
237{
238 replace "$1" "version: ${OLDVERSION}" "version: ${NEWVERSION}"
239}
240
241#
James Z.M. Gao93ae7af2021-01-06 11:51:41 +0800242# pomReplace: replace a specific version field in a maven pom file
243# must be a top level "version" field in the xml structure
244# \param $1 filename to do replacements on
245# \returns 0 on success
246#
247
248function pomReplace
249{
250 replace "$1" "^ <version>${OLDVERSION}<\/version>" " <version>${NEWVERSION}<\/version>"
251}
252
253#
James E. King IIIecebd772018-12-28 08:50:58 -0500254# replace: replace occurrences of one string with another
255# the file specified must contain the old string at least once
256# in order to be successful.
257# \param $1 filename to do replacements on
258# \param $2 the "old" string to be replaced
259# \param $3 the "new" striing to replace it with
260# \returns 0 on success
261#
262function replace
263{
264 local result
265 local output
266 local oldString="$2"
267 local newString="$3"
268 local oldRegex=$(escapeVersion "${oldString}")
269 local count=$(grep -Ec "${oldRegex}" "$1")
270 local verbose
271 if [ $count -eq 0 ]; then
272 printf "%-60s | %5d | ${red}NOT FOUND${normal}: ${oldString}" "$1" 0
273 echo
274 return 1
275 elif [ ! -z "$DRYRUN" ]; then
276 printf "%-60s | %5d | MATCHES:" "$1" "$count"
277 echo
278 while read -r line; do
279 echo " > $(echo "$line" | sed "s/${oldRegex}/${reverse}${green}${oldString}${normal}/g")"
280 done < <(grep -E "${oldRegex}" "$1")
281 return 0
282 fi
283 output=$(sed -i "s/${oldRegex}/${newString}/g" "$1")
284 result=$?
285 if [ $result -ne 0 ]; then
286 printf "%-60s | %5d | ${red}ERROR${normal}: %s" "$1" "$count" "$output"
287 echo
288 return 1
289 fi
290 printf "%-60s | %5d | ${green}OK${normal}" "$1" "$count"
291 echo
292 return 0
293}
294
295#
296# simpleReplace: replace occurrences of ${OLDVERSION} with ${NEWVERSION}
297# the file specified must contain OLDVERSION at least once
298# in order to be successful.
299# \param $1 filename to do replacements on
300# \param $2 the "old" string to be replaced
301# \param $3 the "new" striing to replace it with
302# \returns 0 on success
303#
304function simpleReplace
305{
306 replace "$1" "${OLDVERSION}" "${NEWVERSION}"
307}
308
309echo ""
310echo "Apache Thrift Version Alignment Tool"
311echo "------------------------------------"
312echo ""
313echo "Previous Version: ${OLDVERSION}"
314echo " New Version: ${NEWVERSION}"
315echo ""
316echo "-------------------------------------------------------------+-------+----------------------"
317echo "Filename | Count | Status "
318echo "-------------------------------------------------------------+-------+----------------------"
319
320for file in $(echo "${!FILES[@]}" | sort); do
321 ${FILES[$file]} $file || exit $?
322done
323
324echo
325echo "Files that must be modified manually:"
326echo
327for manu in $(echo "${!MANUAL[@]}" | sort); do
328 echo " > ${yellow}${manu}${normal}"
329done
330
331exit 0