]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | #!/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 | ||
43 | declare -A FILES | |
44 | ||
45 | # These files require a manual touch: | |
46 | FILES[CHANGES.md]=manual | |
47 | FILES[debian/changelog]=manual | |
48 | FILES[doap.rdf]=manual | |
49 | ||
50 | # These files can be updated automatically: | |
51 | FILES[ApacheThrift.nuspec]=simpleReplace | |
52 | FILES[CMakeLists.txt]=simpleReplace | |
53 | FILES[Thrift.podspec]=simpleReplace | |
54 | FILES[appveyor.yml]=simpleReplace | |
55 | FILES[bower.json]=jsonReplace | |
56 | FILES[configure.ac]=configureReplace | |
57 | FILES[contrib/thrift.spec]=simpleReplace | |
58 | FILES[doc/specs/idl.md]=simpleReplace | |
59 | FILES[lib/as3/gradle.properties]=simpleReplace | |
60 | FILES[lib/csharp/ThriftMSBuildTask/Properties/AssemblyInfo.cs]=simpleReplace | |
61 | FILES[lib/csharp/ThriftMSBuildTask/ThriftMSBuildTask.csproj]=simpleReplace | |
62 | FILES[lib/csharp/src/Properties/AssemblyInfo.cs]=simpleReplace | |
63 | FILES[lib/csharp/src/Thrift.csproj]=simpleReplace | |
64 | FILES[lib/csharp/test/Multiplex/Client/MultiplexClient.csproj]=simpleReplace | |
65 | FILES[lib/csharp/test/Multiplex/Client/Properties/AssemblyInfo.cs]=simpleReplace | |
66 | FILES[lib/csharp/test/Multiplex/Server/MultiplexServer.csproj]=simpleReplace | |
67 | FILES[lib/csharp/test/Multiplex/Server/Properties/AssemblyInfo.cs]=simpleReplace | |
68 | FILES[lib/csharp/test/ThriftMVCTest/Properties/AssemblyInfo.cs]=simpleReplace | |
69 | FILES[lib/d/src/thrift/base.d]=simpleReplace | |
70 | FILES[lib/dart/pubspec.yaml]=pubspecReplace | |
71 | FILES[lib/delphi/src/Thrift.pas]=simpleReplace | |
72 | FILES[lib/erl/src/thrift.app.src]=simpleReplace | |
73 | FILES[lib/haxe/haxelib.json]=simpleReplace | |
74 | FILES[lib/hs/thrift.cabal]=simpleReplace | |
75 | FILES[lib/java/gradle.properties]=simpleReplace | |
76 | FILES[lib/js/package.json]=jsonReplace | |
77 | FILES[lib/js/src/thrift.js]=simpleReplace | |
78 | FILES[lib/lua/Thrift.lua]=simpleReplace | |
79 | FILES[lib/netcore/Thrift/Properties/AssemblyInfo.cs]=simpleReplace | |
80 | FILES[lib/netcore/Thrift/Transports/Client/THttpClientTransport.cs]=simpleReplace | |
81 | FILES[lib/netstd/Thrift/Properties/AssemblyInfo.cs]=simpleReplace | |
82 | FILES[lib/netstd/Thrift/Transports/Client/THttpClientTransport.cs]=simpleReplace | |
83 | FILES[lib/netstd/Thrift/Thrift.csproj]=simpleReplace | |
84 | FILES[lib/ocaml/_oasis]=simpleReplace | |
85 | FILES[lib/perl/lib/Thrift.pm]=simpleReplace | |
86 | FILES[lib/py/setup.py]=simpleReplace | |
87 | FILES[lib/rb/thrift.gemspec]=simpleReplace | |
88 | FILES[lib/rs/Cargo.toml]=simpleReplace | |
89 | FILES[lib/st/package.xml]=simpleReplace | |
90 | FILES[lib/swift/Sources/Thrift.swift]=simpleReplace | |
91 | FILES[lib/swift/Tests/ThriftTests/ThriftTests.swift]=simpleReplace | |
92 | FILES[lib/ts/package.json]=jsonReplace | |
93 | FILES[package.json]=jsonReplace | |
94 | FILES[sonar-project.properties]=simpleReplace | |
95 | FILES[test/csharp/Properties/AssemblyInfo.cs]=simpleReplace | |
96 | FILES[test/csharp/ThriftTest.csproj]=simpleReplace | |
97 | FILES[test/dart/test_client/pubspec.yaml]=pubspecReplace | |
98 | FILES[test/erl/src/thrift_test.app.src]=simpleReplace | |
99 | FILES[tutorial/csharp/CsharpClient/Properties/AssemblyInfo.cs]=simpleReplace | |
100 | FILES[tutorial/csharp/CsharpServer/Properties/AssemblyInfo.cs]=simpleReplace | |
101 | FILES[tutorial/dart/client/pubspec.yaml]=pubspecReplace | |
102 | FILES[tutorial/dart/console_client/pubspec.yaml]=pubspecReplace | |
103 | FILES[tutorial/dart/server/pubspec.yaml]=pubspecReplace | |
104 | FILES[tutorial/delphi/DelphiClient/DelphiClient.dproj]=simpleReplace | |
105 | FILES[tutorial/delphi/DelphiServer/DelphiServer.dproj]=simpleReplace | |
106 | FILES[tutorial/hs/ThriftTutorial.cabal]=simpleReplace | |
107 | FILES[tutorial/ocaml/_oasis]=simpleReplace | |
108 | ||
109 | if [ ! -f "CHANGES.md" ]; then | |
110 | >&2 echo "error: run veralign.sh while in the thrift root directory" | |
111 | exit 1 | |
112 | fi | |
113 | ||
114 | if [ $# -ne 2 ]; then | |
115 | >&2 echo "usage: veralign.sh <oldVersion> <newVersion>" | |
116 | exit 1 | |
117 | fi | |
118 | ||
119 | jq --version 1>/dev/null 2>/dev/null | |
120 | if [ $? -ne 0 ]; then | |
121 | >&2 echo "error: the 'jq' package is not installed" | |
122 | exit 1 | |
123 | fi | |
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 | # | |
132 | function 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 | ||
144 | OLDVERSION=$1 | |
145 | NEWVERSION=$2 | |
146 | validateVersion "${OLDVERSION}" || exit $? | |
147 | validateVersion "${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 | # | |
156 | function escapeVersion | |
157 | { | |
158 | echo "$(echo $1 | sed 's/\./\\./g' | sed 's/\[/\\\[/g' | sed 's/\]/\\\]/g')" | |
159 | } | |
160 | ||
161 | # Set up verbose hilighting if running interactive | |
162 | if [ "$(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) | |
168 | fi | |
169 | ||
170 | declare -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 | # | |
177 | function 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 | ||
189 | function 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 | ||
201 | function 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 | ||
236 | function pubspecReplace | |
237 | { | |
238 | replace "$1" "version: ${OLDVERSION}" "version: ${NEWVERSION}" | |
239 | } | |
240 | ||
241 | # | |
242 | # replace: replace occurrences of one string with another | |
243 | # the file specified must contain the old string at least once | |
244 | # in order to be successful. | |
245 | # \param $1 filename to do replacements on | |
246 | # \param $2 the "old" string to be replaced | |
247 | # \param $3 the "new" striing to replace it with | |
248 | # \returns 0 on success | |
249 | # | |
250 | function replace | |
251 | { | |
252 | local result | |
253 | local output | |
254 | local oldString="$2" | |
255 | local newString="$3" | |
256 | local oldRegex=$(escapeVersion "${oldString}") | |
257 | local count=$(grep -Ec "${oldRegex}" "$1") | |
258 | local verbose | |
259 | if [ $count -eq 0 ]; then | |
260 | printf "%-60s | %5d | ${red}NOT FOUND${normal}: ${oldString}" "$1" 0 | |
261 | echo | |
262 | return 1 | |
263 | elif [ ! -z "$DRYRUN" ]; then | |
264 | printf "%-60s | %5d | MATCHES:" "$1" "$count" | |
265 | echo | |
266 | while read -r line; do | |
267 | echo " > $(echo "$line" | sed "s/${oldRegex}/${reverse}${green}${oldString}${normal}/g")" | |
268 | done < <(grep -E "${oldRegex}" "$1") | |
269 | return 0 | |
270 | fi | |
271 | output=$(sed -i "s/${oldRegex}/${newString}/g" "$1") | |
272 | result=$? | |
273 | if [ $result -ne 0 ]; then | |
274 | printf "%-60s | %5d | ${red}ERROR${normal}: %s" "$1" "$count" "$output" | |
275 | echo | |
276 | return 1 | |
277 | fi | |
278 | printf "%-60s | %5d | ${green}OK${normal}" "$1" "$count" | |
279 | echo | |
280 | return 0 | |
281 | } | |
282 | ||
283 | # | |
284 | # simpleReplace: replace occurrences of ${OLDVERSION} with ${NEWVERSION} | |
285 | # the file specified must contain OLDVERSION at least once | |
286 | # in order to be successful. | |
287 | # \param $1 filename to do replacements on | |
288 | # \param $2 the "old" string to be replaced | |
289 | # \param $3 the "new" striing to replace it with | |
290 | # \returns 0 on success | |
291 | # | |
292 | function simpleReplace | |
293 | { | |
294 | replace "$1" "${OLDVERSION}" "${NEWVERSION}" | |
295 | } | |
296 | ||
297 | echo "" | |
298 | echo "Apache Thrift Version Alignment Tool" | |
299 | echo "------------------------------------" | |
300 | echo "" | |
301 | echo "Previous Version: ${OLDVERSION}" | |
302 | echo " New Version: ${NEWVERSION}" | |
303 | echo "" | |
304 | echo "-------------------------------------------------------------+-------+----------------------" | |
305 | echo "Filename | Count | Status " | |
306 | echo "-------------------------------------------------------------+-------+----------------------" | |
307 | ||
308 | for file in $(echo "${!FILES[@]}" | sort); do | |
309 | ${FILES[$file]} $file || exit $? | |
310 | done | |
311 | ||
312 | echo | |
313 | echo "Files that must be modified manually:" | |
314 | echo | |
315 | for manu in $(echo "${!MANUAL[@]}" | sort); do | |
316 | echo " > ${yellow}${manu}${normal}" | |
317 | done | |
318 | ||
319 | exit 0 |