-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.py
107 lines (85 loc) · 3.03 KB
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import os
import re
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path
def get_version_from_branch(branch: str) -> str:
if branch == "master":
return "master"
if match := re.match(r"openssl-(3\.[0-9]+)", branch):
return match.group(1)
if branch == "OpenSSL_1_1_1-stable":
return "1.1.1"
if branch == "OpenSSL_1_0_2-stable":
return "1.0.2"
print(f"Incorrect branch {branch}")
raise SystemExit(1)
def clone(branch: str, tmp_dir: str) -> None:
subprocess.run(
["git", "clone", "--single-branch", "-b", branch, "--depth", "1", "https://github.com/openssl/openssl", tmp_dir]
)
def get_commit_hash(tmp_dir: str) -> str:
ps = subprocess.run(["git", "rev-parse", "HEAD"], cwd=tmp_dir, capture_output=True)
if ps.returncode != 0:
raise SystemExit(ps.returncode)
return ps.stdout.decode("utf-8").strip()
def build_manpages(tmp_dir: str):
if return_code := subprocess.run(["sh", "config"], cwd=tmp_dir).returncode != 0:
raise SystemExit(return_code)
cmd = ["make", "-j", str(os.cpu_count()), "build_man_docs"]
if return_code := subprocess.run(cmd, cwd=tmp_dir).returncode != 0:
raise SystemExit(return_code)
def clean_docs():
try:
shutil.rmtree("docs/")
except FileNotFoundError:
pass
def create_dirs():
os.makedirs("docs/man1", exist_ok=True)
os.makedirs("docs/man3", exist_ok=True)
os.makedirs("docs/man5", exist_ok=True)
os.makedirs("docs/man7", exist_ok=True)
def convert_pod_to_md(tmp_dir: str):
# for openssl 1.0.2
dir_map = {
"apps": "man1",
"crypto": "man3",
"ssl": "man3",
"man1": "man1",
"man3": "man3",
"man5": "man5",
"man7": "man7",
}
for pod in Path(f"{tmp_dir}/doc").glob("**/*.pod"):
if "internal" in pod.parent.parts:
continue
target = f"docs/{dir_map[pod.parent.name]}/{pod.stem}.md"
ps = subprocess.run(["pod2markdown",
"--html-encode-chars", "1",
"--man-url-prefix", "../../man",
str(pod), target])
if ps.returncode != 0:
raise SystemExit(ps.returncode)
def copy_images(tmp_dir: str):
shutil.copytree(f"{tmp_dir}/doc/man7/img", "docs/man7/img")
def build_site(commit: str, version: str):
commit_msg = f"deploy openssl/openssl@{commit} to {version}"
return subprocess.run(["mike", "deploy", "-m", commit_msg, version]).returncode
def main():
branch = sys.argv[1]
version = get_version_from_branch(branch)
clean_docs()
create_dirs()
with tempfile.TemporaryDirectory() as tmp_dir:
clone(branch, tmp_dir)
commit = get_commit_hash(tmp_dir)
if version not in ["1.0.2", "1.1.1"]:
build_manpages(tmp_dir)
convert_pod_to_md(tmp_dir)
if version not in ["1.0.2", "1.1.1"]:
copy_images(tmp_dir)
return build_site(commit, version)
if __name__ == "__main__":
sys.exit(main())