Skip to content

Commit f53aeeb

Browse files
svekarsfacebook-github-bot
authored andcommitted
Propagate version number in the doc build. (#1022)
Summary: Pull Request resolved: #1022 - We need to dynamically get the version number from the GITHUB_REF_NAME so that it is displayed directly in the version dropdown on the website. Reviewed By: huydhn Differential Revision: D50464418 fbshipit-source-id: 06c3a49c47df899855264bd553fdb6c46fa2b662
1 parent d65bb6b commit f53aeeb

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

.github/workflows/doc-build.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ jobs:
4141
export CHANNEL=nightly
4242
fi
4343
44+
# Get the version of ExecuTorch from REF_NAME and save as ET_VERSION_DOCS
45+
# ET_VERSION_DOCS will be pulled during the doc build to add to the version dropdown
46+
# on the website. See docs/source/conf.py for details
47+
48+
REF_TYPE=${{ github.ref_type }}
49+
REF_NAME=${{ github.ref_name }}
50+
51+
echo "$REF_TYPE"
52+
echo "$REF_NAME"
53+
54+
ET_VERSION_DOCS="${REF_NAME}"
55+
echo "$ET_VERSION_DOCS"
56+
4457
set -eux
4558
4659
# Build docset:

docs/source/conf.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,42 @@
7373
)
7474

7575
html_favicon = "_static/img/ExecuTorch-Logo-cropped.svg"
76+
77+
# Get ET_VERSION_DOCS during the build.
78+
et_version_docs = os.environ.get("ET_VERSION_DOCS", None)
79+
80+
81+
# The code below will cut version displayed in the dropdown like this:
82+
# tags like v0.1.0 = > 0.1
83+
# branch like release/0.1 => 0.1
84+
# main will remain main
85+
# if not set will fail back to main
86+
# the version varible is used in layout.html: https://github.com/pytorch/executorch/blob/main/docs/source/_templates/layout.html#L29
87+
if et_version_docs:
88+
# Check if starts with release/ and set the version to the number after slash
89+
if et_version_docs.startswith("release/"):
90+
version = et_version_docs.split("/")[-1]
91+
else:
92+
# Remove "v" prefix if present
93+
if et_version_docs.startswith("v"):
94+
et_version_docs = et_version_docs[1:]
95+
# Split to major, minor, and patch
96+
version_components = et_version_docs.split(".")
97+
98+
# Combine the major and minor version components:
99+
if len(version_components) >= 2:
100+
version = release = ".".join(version_components[:2])
101+
else:
102+
# If there are not enough components, use the full version
103+
version = release = et_version_docs
104+
105+
html_title = " ".join((project, version, "documentation"))
106+
# IF ET_VERSION_DOCS not set, set version to main.
107+
# This can be updated to nightly and so on.
108+
else:
109+
version = "main"
110+
release = "main"
111+
76112
breathe_projects = {"ExecuTorch": "../build/xml/"}
77113
breathe_default_project = "ExecuTorch"
78114

0 commit comments

Comments
 (0)