Skip to content

Commit b72ff94

Browse files
committed
[ci] Add script to bump version in Makefile and update others
[skip ci] Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent 22a40b7 commit b72ff94

File tree

4 files changed

+195
-6
lines changed

4 files changed

+195
-6
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Release Preparation
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
grid-version:
7+
required: true
8+
type: string
9+
workflow_dispatch:
10+
inputs:
11+
grid-version:
12+
required: true
13+
type: string
14+
description: Expected Grid version to update
15+
16+
jobs:
17+
pr-results:
18+
name: Create a PR with changelog
19+
runs-on: ubuntu-24.04
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@main
23+
with:
24+
persist-credentials: false
25+
fetch-depth: 0
26+
- name: Check existing PR
27+
id: check-pr
28+
run: |
29+
PR_NUMBER=$(gh pr list --base trunk --head release-preparation --json number --jq '.[0].number')
30+
if [ "$PR_NUMBER" != "null" ] && [ -n "$PR_NUMBER" ]; then
31+
echo "pr-exists=true" >> $GITHUB_OUTPUT
32+
else
33+
echo "pr-exists=false" >> $GITHUB_OUTPUT
34+
fi
35+
env:
36+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
- name: Checkout PR branch
38+
if: steps.check-pr.outputs.pr-exists == 'true'
39+
run: |
40+
git checkout release-preparation
41+
- name: Run scripts
42+
run: |
43+
EXPECTED_BASE_VERSION=${EXPECTED_BASE_VERSION} make update_release_version
44+
make update_selenium_version_matrix
45+
make update_browser_versions_matrix
46+
make lint_format_scripts
47+
env:
48+
EXPECTED_BASE_VERSION: ${{ inputs.grid-version }}
49+
- name: Commit & Push changes
50+
if: steps.check-pr.outputs.pr-exists == 'true'
51+
uses: actions-js/push@master
52+
with:
53+
github_token: ${{ secrets.GITHUB_TOKEN }}
54+
author_email: "[email protected]"
55+
author_name: "Selenium CI Bot"
56+
message: "[build] Upload Selenium Grid ${{ inputs.grid-version }}"
57+
empty: true
58+
rebase: true
59+
branch: "release-preparation"
60+
- name: Create Pull Request
61+
if: steps.check-pr.outputs.pr-exists == 'false'
62+
uses: peter-evans/create-pull-request@main
63+
with:
64+
token: ${{ secrets.SELENIUM_CI_TOKEN }}
65+
commit-message: |
66+
[build] Upload Selenium Grid ${{ inputs.grid-version }}
67+
title: "[build] Upload Selenium Grid ${{ inputs.grid-version }}"
68+
body: "This PR to update Selenium Grid ${{ inputs.grid-version }} and backward browser versions"
69+
committer: 'Selenium CI Bot <[email protected]>'
70+
author: 'Selenium CI Bot <[email protected]>'
71+
branch: release-preparation

Base/Dockerfile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ ARG RELEASE=selenium-${VERSION}
99
# Default value should be aligned with upstream Selenium (https://github.com/SeleniumHQ/selenium/blob/trunk/MODULE.bazel)
1010
ARG OPENTELEMETRY_VERSION=1.55.0
1111
ARG GRPC_VERSION=1.76.0
12-
ARG NETTY_VERSION=4.2.7.Final
1312
ARG CS_VERSION=2.1.25-M18
1413
ARG ENVSUBST_VERSION=1.4.6
1514
ARG CURL_VERSION=8.16.0
@@ -143,11 +142,6 @@ RUN --mount=type=secret,id=SEL_PASSWD \
143142
java -jar /tmp/cs fetch --classpath --cache /external_jars \
144143
io.opentelemetry:opentelemetry-exporter-otlp:${OPENTELEMETRY_VERSION} \
145144
io.grpc:grpc-netty:${GRPC_VERSION} \
146-
io.netty:netty-handler-proxy:${NETTY_VERSION} \
147-
io.netty:netty-parent:${NETTY_VERSION} \
148-
io.netty:netty-codec-http:${NETTY_VERSION} \
149-
io.netty:netty-codec-http2:${NETTY_VERSION} \
150-
io.netty:netty-codec:${NETTY_VERSION} \
151145
> /external_jars/.classpath.txt \
152146
&& chmod 664 /external_jars/.classpath.txt ; \
153147
fi \

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ generate_readme_charts:
100100
update_list_env_vars: install_python_deps
101101
python3 scripts/generate_list_env_vars/extract_env.py
102102

103+
update_release_version: install_python_deps
104+
python3 scripts/release_preparation/update_versions.py --expected-base-version $(EXPECTED_BASE_VERSION)
105+
103106
update_selenium_version_matrix: install_python_deps
104107
python3 tests/build-backward-compatible/add_selenium_version.py $(BASE_VERSION)
105108

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import argparse
2+
import re
3+
import sys
4+
from pathlib import Path
5+
6+
BASE_VERSION_PATTERN = re.compile(r"^BASE_VERSION\s*:=.*?(\d+\.\d+\.\d+)", re.MULTILINE)
7+
BASE_VERSION_NIGHTLY_PATTERN = re.compile(
8+
r"^BASE_VERSION_NIGHTLY\s*:=.*?(\d+\.\d+\.\d+-SNAPSHOT)",
9+
re.MULTILINE,
10+
)
11+
12+
13+
def find_makefile():
14+
cwd = Path.cwd()
15+
candidate = cwd / "Makefile"
16+
if candidate.exists():
17+
return candidate
18+
19+
script_dir = Path(__file__).parent
20+
if script_dir != cwd:
21+
candidate = script_dir / "Makefile"
22+
if candidate.exists():
23+
return candidate
24+
25+
return None
26+
27+
28+
def parse_versions(content: str):
29+
base_match = BASE_VERSION_PATTERN.search(content)
30+
nightly_match = BASE_VERSION_NIGHTLY_PATTERN.search(content)
31+
32+
if not base_match:
33+
raise ValueError("BASE_VERSION not found in Makefile")
34+
if not nightly_match:
35+
raise ValueError("BASE_VERSION_NIGHTLY not found in Makefile")
36+
37+
return base_match.group(1), nightly_match.group(1)
38+
39+
40+
def bump_minor(version: str) -> str:
41+
parts = version.split(".")
42+
if len(parts) != 3:
43+
raise ValueError(f"Unsupported version format: {version}")
44+
45+
major, minor, _ = parts
46+
47+
try:
48+
minor_number = int(minor)
49+
except ValueError as exc:
50+
raise ValueError(f"Minor version is not an integer in '{version}'") from exc
51+
52+
return f"{major}.{minor_number + 1}.0"
53+
54+
55+
def update_versions(makefile_path: Path, expected_base_version: str | None) -> bool:
56+
content = makefile_path.read_text()
57+
current_base, current_nightly = parse_versions(content)
58+
59+
if expected_base_version and current_base == expected_base_version:
60+
print(
61+
"BASE_VERSION already matches expected value "
62+
f"({expected_base_version}); skipping updates."
63+
)
64+
return False
65+
66+
nightly_base = current_nightly.removesuffix("-SNAPSHOT")
67+
new_base = nightly_base
68+
new_nightly = bump_minor(nightly_base) + "-SNAPSHOT"
69+
70+
if new_base == current_base and new_nightly == current_nightly:
71+
print("Makefile already uses the desired versions; nothing to update.")
72+
return False
73+
74+
updated_content = content.replace(current_base, new_base)
75+
updated_content = updated_content.replace(current_nightly, new_nightly)
76+
77+
makefile_path.write_text(updated_content)
78+
79+
print(f"Updated BASE_VERSION from {current_base} to {new_base}")
80+
print(f"Updated BASE_VERSION_NIGHTLY from {current_nightly} to {new_nightly}")
81+
return True
82+
83+
84+
def main(argv: list[str]) -> int:
85+
parser = argparse.ArgumentParser(description="Bump Selenium Grid versions in Makefile")
86+
parser.add_argument(
87+
"makefile",
88+
nargs="?",
89+
help="Optional path to the Makefile (default: search in CWD then script directory)",
90+
)
91+
parser.add_argument(
92+
"--expected-base-version",
93+
dest="expected_base_version",
94+
help="If provided and Makefile already contains this BASE_VERSION, skip updating.",
95+
)
96+
args = parser.parse_args(argv)
97+
98+
if args.makefile:
99+
makefile_path = Path(args.makefile)
100+
else:
101+
found = find_makefile()
102+
if not found:
103+
print("Error: Could not locate Makefile", file=sys.stderr)
104+
return 1
105+
makefile_path = found
106+
107+
if not makefile_path.exists():
108+
print(f"Error: {makefile_path} does not exist", file=sys.stderr)
109+
return 1
110+
111+
try:
112+
changed = update_versions(makefile_path, args.expected_base_version)
113+
except ValueError as exc:
114+
print(f"Error: {exc}", file=sys.stderr)
115+
return 1
116+
117+
return 0 if changed else 0
118+
119+
120+
if __name__ == "__main__":
121+
sys.exit(main(sys.argv[1:]))

0 commit comments

Comments
 (0)