Skip to content

Commit 3821cb1

Browse files
authored
Merge pull request #1241 from ucb-bar/abejgonzalez-patch-1
Update stable docs
2 parents 902218e + f2c5f08 commit 3821cb1

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

docs/conf.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,19 @@
6666
# built documents.
6767

6868
on_rtd = os.environ.get("READTHEDOCS") == "True"
69+
on_gha = os.environ.get("GITHUB_ACTIONS") == "true"
70+
6971
if on_rtd:
7072
for item, value in os.environ.items():
7173
print("[READTHEDOCS] {} = {}".format(item, value))
7274

73-
# default to latest for non rtd builds (this will be overridden on rtd)
74-
rtd_version = "latest"
75+
# Come up with a short version string for the build. This is doing a bunch of lifting:
76+
# - format doc text that self-references its version (see title page). This may be used in an ad-hoc
77+
# way to produce references to things like ScalaDoc, etc...
78+
# - procedurally generate github URL references using via `gh-file-ref`
7579
if on_rtd:
7680
rtd_version = os.environ.get("READTHEDOCS_VERSION")
77-
if rtd_version == "latest":
78-
version = "main" # TODO: default to what "latest" points to
79-
elif rtd_version == "stable":
81+
if rtd_version in ["stable", "latest"]:
8082
# get the latest git tag (which is what rtd normally builds under "stable")
8183
# this works since rtd builds things within the repo
8284
process = subprocess.Popen(["git", "describe", "--exact-match", "--tags"], stdout=subprocess.PIPE)
@@ -87,8 +89,23 @@
8789
version = "v?.?.?" # this should not occur as "stable" is always pointing to tagged version
8890
else:
8991
version = rtd_version # name of a branch
92+
elif on_gha:
93+
# GitHub actions does a build of the docs to ensure they are free of warnings.
94+
# Looking up a branch name or tag requires switching on the event type that triggered the workflow
95+
# so just use the SHA of the commit instead.
96+
version = os.environ.get("GITHUB_SHA")
97+
rtd_version = "stable" # default to stable when not on rtd
9098
else:
91-
version = "v?.?.?"
99+
# When running locally, try to set version to a branch name that could be
100+
# used to reference files on GH that could be added or moved. This should match rtd_version when running
101+
# in a RTD build container
102+
process = subprocess.Popen(["git", "rev-parse", "--abbrev-ref", "HEAD"], stdout=subprocess.PIPE)
103+
output = process.communicate()[0].decode("utf-8").strip()
104+
if process.returncode == 0:
105+
version = output
106+
else:
107+
raise Exception("git rev-parse --abbrev-ref HEAD returned non-zero")
108+
rtd_version = "stable" # default to stable when not on rtd
92109

93110
# for now make these match
94111
release = version

0 commit comments

Comments
 (0)