Skip to content

Commit 216bdcd

Browse files
authored
Add version bumping to .ci/make.sh
1 parent 2f4d20d commit 216bdcd

File tree

5 files changed

+97
-10
lines changed

5 files changed

+97
-10
lines changed

.ci/make.sh

Lines changed: 6 additions & 1 deletion
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/enterprise-search-python \
153+
$product \
154+
/bin/bash -c "python /code/enterprise-search-python/utils/bump-version.py $VERSION"
155+
156+
exit 0
152157
fi
153158

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

.ci/test-matrix.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22

33
STACK_VERSION:
4-
- 8.3.0-SNAPSHOT
4+
- "8.3.0-SNAPSHOT"
55

66
PYTHON_VERSION:
77
- "3.6"

.github/workflows/unified-release.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ jobs:
1717
assemble:
1818
name: Assemble
1919
runs-on: ubuntu-latest
20-
strategy:
21-
fail-fast: false
22-
matrix:
23-
stack_version: ['8.3.0-SNAPSHOT']
24-
20+
env:
21+
STACK_VERSION: "8.3-SNAPSHOT"
2522
steps:
2623
- name: Checkout
2724
uses: actions/checkout@v2
28-
- run: "./.ci/make.sh assemble ${{ matrix.stack_version }}"
29-
name: Assemble ${{ matrix.stack_version }}
25+
- name: "Assemble ${{ env.STACK_VERSION }}"
26+
run: "./.ci/make.sh assemble ${{ env.STACK_VERSION }}"

elastic_enterprise_search/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
__version__ = "8.3.0+dev"
18+
__version__ = "8.3.0"

utils/bump-version.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
# Pad the version value with .0 until there
58+
# we have the major, minor, and patch.
59+
for _ in range(3):
60+
if len(python_version.split(".")) >= 3:
61+
break
62+
python_version += ".0"
63+
64+
find_and_replace(
65+
path=SOURCE_DIR / "elastic_enterprise_search/_version.py",
66+
pattern=r"__version__ = \"[0-9]+[0-9\.]*[0-9](?:\+dev)?\"",
67+
replace=f'__version__ = "{python_version}"',
68+
)
69+
70+
# These values should always be the 'major.minor-SNAPSHOT'
71+
major_minor_version = ".".join(python_version.split(".")[:2])
72+
find_and_replace(
73+
path=SOURCE_DIR / ".ci/test-matrix.yml",
74+
pattern=r'STACK_VERSION:\s+\- "[0-9]+[0-9\.]*[0-9](?:\-SNAPSHOT)?"',
75+
replace=f'STACK_VERSION:\n - "{major_minor_version}.0-SNAPSHOT"',
76+
)
77+
find_and_replace(
78+
path=SOURCE_DIR / ".github/workflows/unified-release.yml",
79+
pattern=r'STACK_VERSION:\s+"[0-9]+[0-9\.]*[0-9](?:\-SNAPSHOT)?"',
80+
replace=f'STACK_VERSION: "{major_minor_version}-SNAPSHOT"',
81+
)
82+
83+
84+
if __name__ == "__main__":
85+
main()

0 commit comments

Comments
 (0)