Skip to content

Commit aa0fa44

Browse files
committed
add configurable github docs parameters
Signed-off-by: Nicolae Dicu <Nicolae.Dicu.ext@qorix.ai>
1 parent 21f4bb8 commit aa0fa44

3 files changed

Lines changed: 65 additions & 4 deletions

File tree

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ jobs:
3838
id-token: write
3939

4040
with:
41-
bazel-target: "//docs:github_pages__release"
41+
bazel-target: "//docs:github_pages__release --define github_user=eclipse-score --define github_repo=docs-as-code"
4242
retention-days: 3

docs.bzl

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,37 @@ sphinx_requirements = all_requirements + [
5858
"@score_docs_as_code//src/extensions/score_source_code_linker:score_source_code_linker",
5959
]
6060

61+
def _set_github_settings(ctx):
62+
"""Sets GitHub settings for documentation.
63+
64+
This function creates a text file containing GitHub user and repo information,
65+
either from Bazel command line variables or default values. The file is used
66+
by Sphinx extensions to configure documentation settings.
67+
Usage example:
68+
bazel build //docs:github_pages__release --define github_user=eclipse-score --define github_repo=score
69+
70+
Args:
71+
ctx: bazel rule context.
72+
73+
Returns:
74+
A list containing DefaultInfo with runfiles for the settings file.
75+
"""
76+
77+
github_user = ctx.var.get("github_user") or "eclipse-score"
78+
github_repo = ctx.var.get("github_repo") or "score"
79+
80+
txt = ctx.actions.declare_file("github_settings.txt")
81+
ctx.actions.write(output = txt, content = github_user + "," + github_repo)
82+
83+
return [
84+
DefaultInfo(runfiles = ctx.runfiles(files = [txt])),
85+
]
86+
87+
github_settings = rule(
88+
implementation = _set_github_settings,
89+
attrs = {},
90+
)
91+
6192
def docs(source_files_to_scan_for_needs_links = None, source_dir = "docs", conf_dir = "docs", build_dir_for_incremental = "_build", docs_targets = []):
6293
"""
6394
Creates all targets related to documentation.
@@ -73,6 +104,10 @@ def docs(source_files_to_scan_for_needs_links = None, source_dir = "docs", conf_
73104
srcs_and_deps = source_files_to_scan_for_needs_links if source_files_to_scan_for_needs_links else [],
74105
)
75106

107+
github_settings(
108+
name = "github_settings",
109+
)
110+
76111
# We are iterating over all provided 'targets' in order to allow for automatic generation of them without
77112
# needing to modify the underlying 'docs.bzl' file.
78113
for target in docs_targets:
@@ -83,7 +118,7 @@ def docs(source_files_to_scan_for_needs_links = None, source_dir = "docs", conf_
83118
sphinx_build_binary(
84119
name = "sphinx_build" + suffix,
85120
visibility = ["//visibility:public"],
86-
data = ["@score_docs_as_code//src:docs_assets", "@score_docs_as_code//src:score_extension_files"] + external_needs_deps,
121+
data = ["@score_docs_as_code//src:docs_assets", "@score_docs_as_code//src:score_extension_files"] + external_needs_deps + [":github_settings"],
87122
deps = sphinx_requirements,
88123
)
89124
_incremental(

src/extensions/score_layout/html_options.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
1313
from sphinx.application import Sphinx
14+
from pathlib import Path
15+
import os
1416

1517

1618
def return_html_theme_options(app: Sphinx) -> dict[str, object]:
@@ -54,10 +56,34 @@ def return_html_theme_options(app: Sphinx) -> dict[str, object]:
5456
# html_logo = "_assets/S-CORE_Logo_white.svg"
5557

5658

59+
def set_github_context(root_path: Path) -> tuple[str, str]:
60+
"""
61+
Set the GitHub user and repository from settings file or use defaults.
62+
63+
Args:
64+
root_path: Path to the root directory containing github settings
65+
66+
Returns:
67+
tuple containing (github_user, github_repo)
68+
"""
69+
try:
70+
github_settings = (
71+
(root_path / Path("_main/docs/github_settings.txt")).read_text().strip()
72+
)
73+
github_user, github_repo = github_settings.split(",")
74+
except (FileNotFoundError, ValueError):
75+
github_user = "eclipse-score"
76+
github_repo = "score"
77+
return github_user, github_repo
78+
79+
80+
root = Path(os.environ["RUNFILES_DIR"])
81+
github_user, github_repo = set_github_context(root)
82+
5783
html_context = {
5884
# "github_url": "https://github.com", # or your GitHub Enterprise site
59-
"github_user": "eclipse-score",
60-
"github_repo": "score",
85+
"github_user": github_user,
86+
"github_repo": github_repo,
6187
"github_version": "main",
6288
"doc_path": "docs",
6389
}

0 commit comments

Comments
 (0)