blob: 3967d8493d0b74dff7148ffcfc1b27a09f081e3a [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
Jens Geyer467c6bd2024-09-03 01:21:07 +020071FILES[lib/js/package-lock.json]=simpleReplace
James E. King IIIecebd772018-12-28 08:50:58 -050072FILES[lib/lua/Thrift.lua]=simpleReplace
Jens Geyer467c6bd2024-09-03 01:21:07 +020073FILES[lib/netstd/Thrift/Properties/AssemblyInfo.cs]=simpleReplace
Jens Geyer80e9c4f2024-09-03 01:00:03 +020074FILES[lib/netstd/Benchmarks/Thrift.Benchmarks/Thrift.Benchmarks.csproj]=simpleReplace
Jens Geyer80e9c4f2024-09-03 01:00:03 +020075FILES[lib/netstd/Tests/Thrift.Compile.Tests/Thrift.Compile.net8/Thrift.Compile.net8.csproj]=simpleReplace
Jens Geyere26b4a82024-11-12 23:53:04 +010076FILES[lib/netstd/Tests/Thrift.Compile.Tests/Thrift.Compile.net9/Thrift.Compile.net9.csproj]=simpleReplace
Jens Geyer2f214c22025-11-13 23:24:45 +010077FILES[lib/netstd/Tests/Thrift.Compile.Tests/Thrift.Compile.net10/Thrift.Compile.net10.csproj]=simpleReplace
Jens Geyer0f0e11f2024-07-19 00:44:43 +020078FILES[lib/netstd/Tests/Thrift.Compile.Tests/Thrift.Compile.netstd2/Thrift.Compile.netstd2.csproj]=simpleReplace
Jens Geyer80e9c4f2024-09-03 01:00:03 +020079FILES[lib/netstd/Tests/Thrift.IntegrationTests/Thrift.IntegrationTests.csproj]=simpleReplace
80FILES[lib/netstd/Tests/Thrift.Tests/Thrift.Tests.csproj]=simpleReplace
Jens Geyerb75e88a2019-10-17 21:56:39 +020081FILES[lib/netstd/Thrift/Thrift.csproj]=simpleReplace
James E. King IIIecebd772018-12-28 08:50:58 -050082FILES[lib/ocaml/_oasis]=simpleReplace
83FILES[lib/perl/lib/Thrift.pm]=simpleReplace
84FILES[lib/py/setup.py]=simpleReplace
85FILES[lib/rb/thrift.gemspec]=simpleReplace
86FILES[lib/rs/Cargo.toml]=simpleReplace
87FILES[lib/st/package.xml]=simpleReplace
James E. King IIId7c11ad2019-01-11 19:19:44 -050088FILES[lib/swift/Sources/Thrift.swift]=simpleReplace
James E. King III17355422019-01-11 23:06:08 -050089FILES[lib/swift/Tests/ThriftTests/ThriftTests.swift]=simpleReplace
Jens Geyer616df982019-10-19 22:08:13 +020090FILES[lib/ts/package-lock.json]=jsonReplace
Jens Geyer56700e42020-02-22 16:51:51 +010091FILES[lib/ts/package.json]=jsonReplace
Jens Geyer616df982019-10-19 22:08:13 +020092FILES[package-lock.json]=jsonReplace
Jens Geyer56700e42020-02-22 16:51:51 +010093FILES[package.json]=jsonReplace
James E. King IIIecebd772018-12-28 08:50:58 -050094FILES[sonar-project.properties]=simpleReplace
James E. King IIIecebd772018-12-28 08:50:58 -050095FILES[test/dart/test_client/pubspec.yaml]=pubspecReplace
96FILES[test/erl/src/thrift_test.app.src]=simpleReplace
Jens Geyer3fc0b8d2021-02-11 23:17:45 +010097FILES[test/netstd/Client/Client.csproj]=simpleReplace
98FILES[test/netstd/Server/Server.csproj]=simpleReplace
Jens Geyer56700e42020-02-22 16:51:51 +010099FILES[Thrift.podspec]=simpleReplace
James E. King IIIecebd772018-12-28 08:50:58 -0500100FILES[tutorial/dart/client/pubspec.yaml]=pubspecReplace
101FILES[tutorial/dart/console_client/pubspec.yaml]=pubspecReplace
102FILES[tutorial/dart/server/pubspec.yaml]=pubspecReplace
103FILES[tutorial/delphi/DelphiClient/DelphiClient.dproj]=simpleReplace
104FILES[tutorial/delphi/DelphiServer/DelphiServer.dproj]=simpleReplace
Jens Geyer3fc0b8d2021-02-11 23:17:45 +0100105FILES[tutorial/netstd/Client/Client.csproj]=simpleReplace
106FILES[tutorial/netstd/Interfaces/Interfaces.csproj]=simpleReplace
107FILES[tutorial/netstd/Server/Server.csproj]=simpleReplace
James E. King IIIecebd772018-12-28 08:50:58 -0500108FILES[tutorial/ocaml/_oasis]=simpleReplace
Jens Geyer467c6bd2024-09-03 01:21:07 +0200109FILES[lib/ts/package-lock.json]=simpleReplace
110FILES[package-lock.json]=simpleReplace
James E. King IIIecebd772018-12-28 08:50:58 -0500111
Jens Geyer56700e42020-02-22 16:51:51 +0100112
113
James E. King IIIc9ac8d22019-01-07 16:46:45 -0500114if [ ! -f "CHANGES.md" ]; then
James E. King IIIecebd772018-12-28 08:50:58 -0500115 >&2 echo "error: run veralign.sh while in the thrift root directory"
116 exit 1
117fi
118
119if [ $# -ne 2 ]; then
120 >&2 echo "usage: veralign.sh <oldVersion> <newVersion>"
121 exit 1
122fi
123
124jq --version 1>/dev/null 2>/dev/null
125if [ $? -ne 0 ]; then
126 >&2 echo "error: the 'jq' package is not installed"
127 exit 1
128fi
129
130#
131# validateVersion: check that a version matches the major.minor.patch
132# format which is the lowest common denominator supported by all
133# project systems.
134# \param $1 the version
135# \returns 0 if the version is compliant
136#
137function validateVersion
138{
139 local result
140 local valid
141 valid=$(echo "$1" | sed '/^[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+$/!{q22}')
142 result=$?
143 if [ $result -eq 22 ]; then
144 >&2 echo "error: version '$1' does not conform to the required major.minor.patch format"
145 return ${result}
146 fi
147}
148
149OLDVERSION=$1
150NEWVERSION=$2
151validateVersion "${OLDVERSION}" || exit $?
152validateVersion "${NEWVERSION}" || exit $?
153
154#
155# escapeVersion: escape the version for use as a sed search
156# \param $1 the version to escape
157# \output the escaped string
158# \returns 0
159# \example VERSEARCH=$(escapeVersion "[1.0.0]"); echo $VERSEARCH; => "\[1\.0\.0\]"
160#
161function escapeVersion
162{
James Z.M. Gao93ae7af2021-01-06 11:51:41 +0800163 echo "$(echo "$1" | sed 's/\./\\./g' | sed 's/\[/\\\[/g' | sed 's/\]/\\\]/g')"
James E. King IIIecebd772018-12-28 08:50:58 -0500164}
165
166# Set up verbose hilighting if running interactive
167if [ "$(tput colors)" -ne 0 ]; then
168 reverse=$(tput rev)
169 red=$(tput setaf 1)
170 green=$(tput setaf 2)
171 yellow=$(tput setaf 3)
172 normal=$(tput sgr0)
173fi
174
175declare -A MANUAL
176
177#
178# manual: note that update of said file is manual
179# \param $1 filename to do replacements on
180# \returns 0
181#
182function manual
183{
184 MANUAL["$1"]=""
185 return 0
186}
187
188#
189# configureReplace: replace the AC_INIT field in configure.ac
190# \param $1 filename to do replacements on
191# \returns 0 on success
192#
193
194function configureReplace
195{
196 replace "$1" "[thrift], [${OLDVERSION}]" "[thrift], [${NEWVERSION}]"
197}
198
199#
200# jsonReplace: replace a specific version field in a JSON file
201# must be a top level "version" field in the json structure
202# \param $1 filename to do replacements on
203# \returns 0 on success
204#
205
206function jsonReplace
207{
208 local result
209 local output
210 if [ ! -z "$DRYRUN" ]; then
211 output=$(jq -e ".version" "$1")
212 else
213 output=$(jq -e ".version = \"${NEWVERSION}\"" "$1" > tmp.$$.json && mv tmp.$$.json "$1")
214 fi
215 result=$?
216 if [ $? -ne 0 ]; then
217 printf "%-60s | %5d | ${red}ERROR${normal}: version tag not found" "$1" "$count"
218 echo
219 return 1
220 elif [ ! -z "$DRYRUN" ]; then
221 output=${output%\"}
222 output=${output#\"}
223 printf "%-60s | %5d | MATCHES: version: \"${reverse}${green}${output}${normal}\"" "$1" 1
224 echo
225 return 0
226 fi
227 printf "%-60s | %5d | ${green}OK${normal}" "$1" 1
228 echo
229 return 0
230}
231
232#
233# pubspecReplace: replace a specific version field in a YAML file
234# must be a top level "version" field in the yaml structure
235# did not find a package that preserves comments so this is
236# somewhat brain-dead, but it gets the job done
237# \param $1 filename to do replacements on
238# \returns 0 on success
239#
240
241function pubspecReplace
242{
243 replace "$1" "version: ${OLDVERSION}" "version: ${NEWVERSION}"
244}
245
246#
James Z.M. Gao93ae7af2021-01-06 11:51:41 +0800247# pomReplace: replace a specific version field in a maven pom file
248# must be a top level "version" field in the xml structure
249# \param $1 filename to do replacements on
250# \returns 0 on success
251#
252
253function pomReplace
254{
255 replace "$1" "^ <version>${OLDVERSION}<\/version>" " <version>${NEWVERSION}<\/version>"
256}
257
258#
James E. King IIIecebd772018-12-28 08:50:58 -0500259# replace: replace occurrences of one string with another
260# the file specified must contain the old string at least once
261# in order to be successful.
262# \param $1 filename to do replacements on
263# \param $2 the "old" string to be replaced
264# \param $3 the "new" striing to replace it with
265# \returns 0 on success
266#
267function replace
268{
269 local result
270 local output
271 local oldString="$2"
272 local newString="$3"
273 local oldRegex=$(escapeVersion "${oldString}")
274 local count=$(grep -Ec "${oldRegex}" "$1")
275 local verbose
276 if [ $count -eq 0 ]; then
277 printf "%-60s | %5d | ${red}NOT FOUND${normal}: ${oldString}" "$1" 0
278 echo
279 return 1
280 elif [ ! -z "$DRYRUN" ]; then
281 printf "%-60s | %5d | MATCHES:" "$1" "$count"
282 echo
283 while read -r line; do
284 echo " > $(echo "$line" | sed "s/${oldRegex}/${reverse}${green}${oldString}${normal}/g")"
285 done < <(grep -E "${oldRegex}" "$1")
286 return 0
287 fi
288 output=$(sed -i "s/${oldRegex}/${newString}/g" "$1")
289 result=$?
290 if [ $result -ne 0 ]; then
291 printf "%-60s | %5d | ${red}ERROR${normal}: %s" "$1" "$count" "$output"
292 echo
293 return 1
294 fi
295 printf "%-60s | %5d | ${green}OK${normal}" "$1" "$count"
296 echo
297 return 0
298}
299
300#
301# simpleReplace: replace occurrences of ${OLDVERSION} with ${NEWVERSION}
302# the file specified must contain OLDVERSION at least once
303# in order to be successful.
304# \param $1 filename to do replacements on
305# \param $2 the "old" string to be replaced
306# \param $3 the "new" striing to replace it with
307# \returns 0 on success
308#
309function simpleReplace
310{
311 replace "$1" "${OLDVERSION}" "${NEWVERSION}"
312}
313
314echo ""
315echo "Apache Thrift Version Alignment Tool"
316echo "------------------------------------"
317echo ""
318echo "Previous Version: ${OLDVERSION}"
319echo " New Version: ${NEWVERSION}"
320echo ""
321echo "-------------------------------------------------------------+-------+----------------------"
322echo "Filename | Count | Status "
323echo "-------------------------------------------------------------+-------+----------------------"
324
325for file in $(echo "${!FILES[@]}" | sort); do
326 ${FILES[$file]} $file || exit $?
327done
328
329echo
330echo "Files that must be modified manually:"
331echo
332for manu in $(echo "${!MANUAL[@]}" | sort); do
333 echo " > ${yellow}${manu}${normal}"
334done
335
336exit 0