Skip to content

Commit 2c9bc7e

Browse files
committed
ci(deploy): generate index with template
We already pull in jinja2 as a dependency of sphinx. Might as well put it to use here to make this process a little more bulletproof. Signed-off-by: Randolph Sapp <[email protected]>
1 parent 0ba3bf5 commit 2c9bc7e

File tree

3 files changed

+103
-30
lines changed

3 files changed

+103
-30
lines changed

.github/workflows/deploy.yml

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,18 @@ jobs:
1212
agregate:
1313
name: Agregate build artifacts
1414
runs-on: ubuntu-latest
15+
container:
16+
image: ghcr.io/texasinstruments/processor-sdk-doc:latest
17+
options: --entrypoint /bin/bash
1518

1619
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
23+
- name: Add directory to safe dir overrides
24+
run: |
25+
git config --global --add safe.directory "$PWD"
26+
1727
- name: Download all artifacts
1828
uses: actions/download-artifact@v4
1929
with:
@@ -23,36 +33,7 @@ jobs:
2333
run-id: ${{ github.event.workflow_run.id }}
2434

2535
- name: Generate root index
26-
run: |
27-
cat << EOF > build/index.html
28-
<!DOCTYPE html>
29-
<html lang="en">
30-
<head>
31-
<meta charset="utf-8">
32-
<title>PSDK Documentation Landing Page</title>
33-
</head>
34-
<body>
35-
<main>
36-
<h1>PSDK Documentation Landing Page</h1>
37-
<ul>
38-
EOF
39-
40-
for path in build/*/; do
41-
root_index=$(find "$path" -name index.html -print -quit)
42-
if [ -n "$root_index" ]; then
43-
text=$(basename "$path")
44-
relative_path=$(realpath "$root_index" --relative-to=build)
45-
printf ' <li><a href="%s">%s</a></li>\n' \
46-
"$relative_path" "$text" >> build/index.html
47-
fi
48-
done
49-
50-
cat << EOF >> build/index.html
51-
</ul>
52-
</main>
53-
</body>
54-
</html>
55-
EOF
36+
run: ./bin/root_index.py
5637

5738
- name: Upload static files as single artifact
5839
uses: actions/upload-pages-artifact@v3

bin/root_index.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>PSDK Documentation Landing Page</title>
7+
</head>
8+
<body>
9+
<main>
10+
<h1>PSDK Documentation Landing Page</h1>
11+
<p>
12+
The following documentation is currently available:
13+
</p>
14+
<ul>
15+
{% for path in path_list -%}
16+
<li>
17+
<a href="{{ path }}">{{ path.parts[0] }}</a>
18+
</li>
19+
{%- endfor %}
20+
</ul>
21+
</main>
22+
</body>
23+
</html>

bin/root_index.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env python3
2+
3+
"""Tool to find and make a index of doc root index files
4+
5+
SPDX-License-Identifier: MIT
6+
Copyright (C) 2025 Texas Instruments Incorporated - https://www.ti.com
7+
"""
8+
9+
from pathlib import Path
10+
import logging
11+
from jinja2 import Environment, FileSystemLoader
12+
13+
BUILD_PATH = Path("build/")
14+
TEMPLATE_PATH = Path(__file__).parent
15+
16+
logger = logging.getLogger(__name__)
17+
18+
19+
def get_root_index(path):
20+
"""Get the root index from a list of candidates
21+
22+
:param path: Pathlib path to search in
23+
"""
24+
candidates = [x for x in path.glob("**/index.html") if x.is_file()]
25+
if not candidates:
26+
return None
27+
28+
sorted_paths = sorted(candidates, key=lambda x: len(x.parts))
29+
return sorted_paths[0]
30+
31+
32+
def get_index_list():
33+
"""Get the list of index files to use from the build directory"""
34+
index_list = []
35+
for path in BUILD_PATH.glob("*/"):
36+
root = get_root_index(path)
37+
if root:
38+
logging.info("Found index: %s", root)
39+
root = root.relative_to(BUILD_PATH)
40+
logging.info("Updating path to: %s", root)
41+
index_list.append(root)
42+
return sorted(index_list)
43+
44+
45+
def generate_root_index(index_list):
46+
"""Make the root index file
47+
48+
:param index_list: List of pathlib paths to indexes
49+
"""
50+
root_index_path = BUILD_PATH.joinpath("index.html")
51+
logging.info("Loading jinja env")
52+
env = Environment(loader=FileSystemLoader(TEMPLATE_PATH))
53+
template = env.get_template("root_index.html")
54+
logging.info("Using template: %s", template.name)
55+
output = template.render(path_list=index_list)
56+
logging.info("Writing output to: %s", root_index_path)
57+
with root_index_path.open("w", encoding="utf-8") as f:
58+
f.write(output)
59+
60+
61+
def main():
62+
"""Main processing loop"""
63+
logging.basicConfig(level=logging.INFO)
64+
index_list = get_index_list()
65+
generate_root_index(index_list)
66+
67+
68+
if __name__ == "__main__":
69+
main()

0 commit comments

Comments
 (0)