diff --git a/.ci/make.sh b/.ci/make.sh index 93b261fb9..db7f8fc99 100755 --- a/.ci/make.sh +++ b/.ci/make.sh @@ -148,7 +148,12 @@ if [[ "$CMD" == "assemble" ]]; then fi if [[ "$CMD" == "bump" ]]; then - echo "TODO" + docker run \ + --rm -v $repo:/code/elasticsearch-py \ + $product \ + /bin/bash -c "python /code/elasticsearch-py/utils/bump-version.py $VERSION" + + exit 0 fi if [[ "$CMD" == "codegen" ]]; then diff --git a/utils/bump-version.py b/utils/bump-version.py new file mode 100644 index 000000000..5bf97b85d --- /dev/null +++ b/utils/bump-version.py @@ -0,0 +1,75 @@ +# Licensed to Elasticsearch B.V. under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch B.V. licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Command line tool which changes the branch to be +ready to build and test the given Elastic stack version. +""" + +import re +import sys +from pathlib import Path + +SOURCE_DIR = Path(__file__).absolute().parent.parent + + +def find_and_replace(path, pattern, replace): + # Does a find and replace within a file path and complains + # if the given pattern isn't found in the file. + with open(path, "r") as f: + old_data = f.read() + + if re.search(pattern, old_data, flags=re.MULTILINE) is None: + print(f"Didn't find the pattern {pattern!r} in {path!s}") + exit(1) + + new_data = re.sub(pattern, replace, old_data, flags=re.MULTILINE) + with open(path, "w") as f: + f.truncate() + f.write(new_data) + + +def main(): + if len(sys.argv) != 2: + print("usage: utils/bump-version.py [stack version]") + exit(1) + + stack_version = sys.argv[1] + try: + python_version = re.search(r"^([0-9][0-9\.]*[0-9]+)", stack_version).group(1) + except AttributeError: + print(f"Couldn't match the given stack version {stack_version!r}") + exit(1) + + find_and_replace( + path=SOURCE_DIR / "elasticsearch/_version.py", + pattern=r"__versionstr__ = \"[0-9]+[0-9\.]*[0-9](?:\+dev)?\"", + replace=f'__versionstr__ = "{python_version}"', + ) + find_and_replace( + path=SOURCE_DIR / ".ci/test-matrix.yml", + pattern=r"STACK_VERSION:\s+\- [0-9]+[0-9\.]*[0-9]-SNAPSHOT", + replace=f"STACK_VERSION:\n - {stack_version}", + ) + find_and_replace( + path=SOURCE_DIR / ".github/workflows/unified-release.yml", + pattern=r"stack_version: \['[0-9]+[0-9\.]*[0-9]-SNAPSHOT'\]", + replace=f"stack_version: ['{stack_version}']", + ) + + +if __name__ == "__main__": + main()