Skip to content

Commit 8880122

Browse files
authored
Implement '.ci/make.sh bump' to set version
1 parent c4143d9 commit 8880122

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

.ci/make.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,12 @@ if [[ "$CMD" == "assemble" ]]; then
148148
fi
149149

150150
if [[ "$CMD" == "bump" ]]; then
151-
echo "TODO"
151+
docker run \
152+
--rm -v $repo:/code/elasticsearch-py \
153+
$product \
154+
/bin/bash -c "python /code/elasticsearch-py/utils/bump-version.py $VERSION"
155+
156+
exit 0
152157
fi
153158

154159
if [[ "$CMD" == "codegen" ]]; then

utils/bump-version.py

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
"""Command line tool which changes the branch to be
19+
ready to build and test the given Elastic stack version.
20+
"""
21+
22+
import re
23+
import sys
24+
from pathlib import Path
25+
26+
SOURCE_DIR = Path(__file__).absolute().parent.parent
27+
28+
29+
def find_and_replace(path, pattern, replace):
30+
# Does a find and replace within a file path and complains
31+
# if the given pattern isn't found in the file.
32+
with open(path, "r") as f:
33+
old_data = f.read()
34+
35+
if re.search(pattern, old_data, flags=re.MULTILINE) is None:
36+
print(f"Didn't find the pattern {pattern!r} in {path!s}")
37+
exit(1)
38+
39+
new_data = re.sub(pattern, replace, old_data, flags=re.MULTILINE)
40+
with open(path, "w") as f:
41+
f.truncate()
42+
f.write(new_data)
43+
44+
45+
def main():
46+
if len(sys.argv) != 2:
47+
print("usage: utils/bump-version.py [stack version]")
48+
exit(1)
49+
50+
stack_version = sys.argv[1]
51+
try:
52+
python_version = re.search(r"^([0-9][0-9\.]*[0-9]+)", stack_version).group(1)
53+
except AttributeError:
54+
print(f"Couldn't match the given stack version {stack_version!r}")
55+
exit(1)
56+
57+
find_and_replace(
58+
path=SOURCE_DIR / "elasticsearch/_version.py",
59+
pattern=r"__versionstr__ = \"[0-9]+[0-9\.]*[0-9](?:\+dev)?\"",
60+
replace=f'__versionstr__ = "{python_version}"',
61+
)
62+
find_and_replace(
63+
path=SOURCE_DIR / ".ci/test-matrix.yml",
64+
pattern=r"STACK_VERSION:\s+\- [0-9]+[0-9\.]*[0-9]-SNAPSHOT",
65+
replace=f"STACK_VERSION:\n - {stack_version}",
66+
)
67+
find_and_replace(
68+
path=SOURCE_DIR / ".github/workflows/unified-release.yml",
69+
pattern=r"stack_version: \['[0-9]+[0-9\.]*[0-9]-SNAPSHOT'\]",
70+
replace=f"stack_version: ['{stack_version}']",
71+
)
72+
73+
74+
if __name__ == "__main__":
75+
main()

0 commit comments

Comments
 (0)