Skip to content

Commit 162d8fa

Browse files
committed
chore: add script to bump OpenSSL version
Add helper script and nox session to bump openssl. Similar to what's being done to bump cmake.
1 parent d289c22 commit 162d8fa

File tree

3 files changed

+143
-28
lines changed

3 files changed

+143
-28
lines changed

noxfile.py

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,8 @@ def docs(session: nox.Session) -> str:
7676
print("Unsupported argument to docs")
7777

7878

79-
@nox.session
80-
def bump(session: nox.Session) -> None:
81-
"""
82-
Set to a new version, use -- <version>, otherwise will use the latest version.
83-
"""
84-
parser = argparse.ArgumentParser(description="Process some integers.")
79+
def _bump(session: nox.Session, name: str, repository: str, script: str, files) -> None:
80+
parser = argparse.ArgumentParser()
8581
parser.add_argument(
8682
"--commit", action="store_true", help="Make a branch and commit."
8783
)
@@ -92,34 +88,45 @@ def bump(session: nox.Session) -> None:
9288

9389
if args.version is None:
9490
session.install("lastversion")
95-
version = session.run(
96-
"lastversion", "kitware/cmake", log=False, silent=True
97-
).strip()
91+
version = session.run("lastversion", repository, log=False, silent=True).strip()
9892
else:
9993
version = args.version
10094

10195
session.install("requests")
10296

10397
extra = ["--quiet"] if args.commit else []
104-
session.run("python", "scripts/update_cmake_version.py", version, *extra)
98+
session.run("python", script, version, *extra)
10599

106100
if args.commit:
107-
session.run("git", "switch", "-c", f"update-to-cmake-{version}", external=True)
108-
files = (
109-
"CMakeUrls.cmake",
110-
"docs/index.rst",
111-
"README.rst",
112-
"tests/test_distribution.py",
113-
"docs/update_cmake_version.rst",
114-
)
115-
session.run(
116-
"git",
117-
"add",
118-
"-u",
119-
*files,
120-
external=True,
121-
)
122-
session.run("git", "commit", "-m", f"Update to CMake {version}", external=True)
101+
session.run("git", "switch", "-c", f"update-to-{name.lower()}-{version}", external=True)
102+
session.run("git", "add", "-u", *files, external=True)
103+
session.run("git", "commit", "-m", f"Update to {name} {version}", external=True)
123104
session.log(
124-
'Complete! Now run: gh pr create --fill --body "Created by running `nox -s bump -- --commit`"'
105+
f'Complete! Now run: gh pr create --fill --body "Created by running `nox -s {session.name} -- --commit`"'
125106
)
107+
108+
109+
@nox.session
110+
def bump(session: nox.Session) -> None:
111+
"""
112+
Set to a new version, use -- <version>, otherwise will use the latest version.
113+
"""
114+
files = (
115+
"CMakeUrls.cmake",
116+
"docs/index.rst",
117+
"README.rst",
118+
"tests/test_distribution.py",
119+
"docs/update_cmake_version.rst",
120+
)
121+
_bump(session, "CMake", "kitware/cmake", "scripts/update_cmake_version.py", files)
122+
123+
124+
@nox.session(name="bump-openssl")
125+
def bump_openssl(session: nox.Session) -> None:
126+
"""
127+
Set openssl to a new version, use -- <version>, otherwise will use the latest version.
128+
"""
129+
files = (
130+
"scripts/manylinux-build-and-install-openssl.sh",
131+
)
132+
_bump(session, "OpenSSL", "openssl/openssl", "scripts/update_openssl_version.py", files)

scripts/manylinux-build-and-install-openssl.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ MY_DIR=$(dirname "${BASH_SOURCE[0]}")
1111
source $MY_DIR/utils.sh
1212

1313
OPENSSL_ROOT=openssl-3.0.3
14-
# Hash from https://www.openssl.org/source/openssl-3.0.3.tar.gz.sha256
1514
OPENSSL_HASH=ee0078adcef1de5f003c62c80cc96527721609c6f3bb42b7795df31f8b558c0b
1615

1716
cd /tmp

scripts/update_openssl_version.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Command line executable allowing to update OpenSSL version.
5+
"""
6+
7+
import argparse
8+
import contextlib
9+
import os
10+
import re
11+
import textwrap
12+
13+
try:
14+
import requests
15+
except ImportError:
16+
raise SystemExit(
17+
"requests not available: "
18+
"consider installing it running 'pip install requests'"
19+
)
20+
21+
ROOT_DIR = os.path.join(os.path.dirname(__file__), "..")
22+
23+
24+
@contextlib.contextmanager
25+
def _log(txt, verbose=True):
26+
if verbose:
27+
print(txt)
28+
yield
29+
if verbose:
30+
print("%s - done" % txt)
31+
32+
33+
def get_openssl_sha256(version, verbose=False):
34+
files_base_url = (
35+
"https://www.openssl.org/source/openssl-%s.tar.gz.sha256" % version
36+
)
37+
with _log("Collecting SHA256 from '%s'" % files_base_url):
38+
sha256 = requests.get(files_base_url).content.decode("ascii").strip()
39+
if verbose:
40+
print("got sha256: {}".format(sha256))
41+
return sha256
42+
43+
44+
def _update_file(filepath, regex, replacement):
45+
msg = "Updating %s" % os.path.relpath(filepath, ROOT_DIR)
46+
with _log(msg):
47+
pattern = re.compile(regex)
48+
with open(filepath, "r") as doc_file:
49+
lines = doc_file.readlines()
50+
updated_content = []
51+
for line in lines:
52+
updated_content.append(re.sub(pattern, replacement, line))
53+
with open(filepath, "w") as doc_file:
54+
doc_file.writelines(updated_content)
55+
56+
57+
def update_openssl_script(version, sha256):
58+
pattern = re.compile(r"^OPENSSL_ROOT=.*")
59+
replacement = "OPENSSL_ROOT=openssl-%s" % version
60+
_update_file(
61+
os.path.join(ROOT_DIR, "scripts/manylinux-build-and-install-openssl.sh"), pattern, replacement
62+
)
63+
pattern = re.compile(r"^OPENSSL_HASH=.*")
64+
replacement = "OPENSSL_HASH=%s" % sha256
65+
_update_file(
66+
os.path.join(ROOT_DIR, "scripts/manylinux-build-and-install-openssl.sh"), pattern, replacement
67+
)
68+
69+
70+
def main():
71+
parser = argparse.ArgumentParser(description=__doc__)
72+
parser.add_argument(
73+
"openssl_version",
74+
metavar="OPENSSL_VERSION",
75+
type=str,
76+
help="OpenSSL version",
77+
)
78+
parser.add_argument(
79+
"--collect-only",
80+
action="store_true",
81+
help="If specified, only display the hashsum for the requested version",
82+
)
83+
parser.add_argument(
84+
"--quiet",
85+
action="store_true",
86+
help="Hide the output",
87+
)
88+
args = parser.parse_args()
89+
90+
sha256 = get_openssl_sha256(args.openssl_version, verbose=args.collect_only)
91+
if args.collect_only:
92+
return
93+
94+
update_openssl_script(args.openssl_version, sha256)
95+
96+
if not args.quiet:
97+
msg = """\
98+
Complete! Now run:
99+
100+
git switch -c update-to-openssl-{release}
101+
git add -u scripts/manylinux-build-and-install-openssl.sh
102+
git commit -m "Update to OpenSSL {release}"
103+
gh pr create --fill --body "Created by update_openssl_version.py"
104+
"""
105+
print(textwrap.dedent(msg.format(release=args.openssl_version)))
106+
107+
108+
if __name__ == "__main__":
109+
main()

0 commit comments

Comments
 (0)