Skip to content

Commit

Permalink
add repo tag and commit associated with the build
Browse files Browse the repository at this point in the history
Signed-off-by: Niels Bantilan <[email protected]>
  • Loading branch information
cosmicBboy committed Dec 11, 2023
1 parent 8cc422e commit aa6f13a
Show file tree
Hide file tree
Showing 3 changed files with 258 additions and 1 deletion.
25 changes: 24 additions & 1 deletion docs/_ext/import_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
class ImportProjectsConfig:
clone_dir: str
flytekit_api_dir: str
show_repo_tags: bool
source_regex_mapping: dict = field(default_factory=dict)


@dataclass
class Project:
name: str
source: str
dest: str
local: bool = False
Expand Down Expand Up @@ -54,6 +56,16 @@ def update_sys_path_for_flytekit(import_project_config: ImportProjectsConfig):
sys.path.insert(0, dir_path)


def update_html_context(project: Project, tag: str, commit: str, config: Config):
tag_url = f"{project.source}/releases/tag/{tag}"
commit_url = f"{project.source}/tree/{commit}"

config.html_context[f"{project.name}_tag"] = tag
config.html_context[f"{project.name}_tag_url"] = tag_url
config.html_context[f"{project.name}_commit"] = commit
config.html_context[f"{project.name}_commit_url"] = commit_url


def import_projects(app: Sphinx, config: Config):
"""Clone projects from git or copy from local directory."""
projects = [Project(**p) for p in config.import_projects]
Expand All @@ -67,13 +79,24 @@ def import_projects(app: Sphinx, config: Config):
):
(srcdir / _dir).mkdir(parents=True, exist_ok=True)

config.html_context["show_repo_tags"] = False
if import_projects_config.show_repo_tags:
config.html_context["show_repo_tags"] = True

for project in projects:
if project.local:
local_dir = srcdir / project.source
else:
local_dir = srcdir / import_projects_config.clone_dir / project.dest
shutil.rmtree(local_dir, ignore_errors=True)
Repo.clone_from(project.source, local_dir)
repo = Repo.clone_from(project.source, local_dir)

if import_projects_config.show_repo_tags:
# use the latest git tag when building docs in a prod
tags = sorted(repo.tags, key=lambda t: t.commit.committed_datetime)
tag = tags[-1]
update_html_context(project, str(tag), str(tag.commit)[:7], config)
repo.git.checkout(str(tag))

local_docs_path = local_dir / project.docs_path
dest_docs_dir = srcdir / project.dest
Expand Down
227 changes: 227 additions & 0 deletions docs/_templates/page.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,11 @@
"clone_dir": "_projects",
"flytekit_api_dir": "_src/flytekit/",
"source_regex_mapping": REPLACE_PATTERNS,
"show_repo_tags": bool(int(os.environ.get("SHOW_REPO_TAGS", 0))),
}

html_context = {}

# Define these environment variables to use local copies of the projects. This
# is useful for building the docs in the CI/CD of the corresponding repos.
flytesnacks_local_path = os.environ.get("FLYTESNACKS_LOCAL_PATH", None)
Expand All @@ -344,6 +347,7 @@

import_projects = [
{
"name": "flytesnacks",
"source": flytesnacks_local_path or "https://github.com/flyteorg/flytesnacks",
"docs_path": "docs",
"dest": "flytesnacks",
Expand All @@ -362,6 +366,7 @@
"local": flytesnacks_local_path is not None,
},
{
"name": "flytekit",
"source": flytekit_local_path or "https://github.com/flyteorg/flytekit",
"docs_path": "docs/source",
"dest": "api/flytekit",
Expand All @@ -374,12 +379,14 @@
"local": flytekit_local_path is not None,
},
{
"name": "flytectl",
"source": flytectl_local_path or "https://github.com/flyteorg/flytectl",
"docs_path": "docs/source",
"dest": "flytectl",
"local": flytectl_local_path is not None,
},
{
"name": "flyteidl",
"source": "../flyteidl",
"docs_path": "protos",
"dest": "protos", # to stay compatible with flyteidl docs path naming
Expand Down

0 comments on commit aa6f13a

Please sign in to comment.