Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
doc: fix an error if the doc is not generated from github
Browse files Browse the repository at this point in the history
The commit 57c45c0 expect Sphinx to find the environment variable
RELEASE_TAG.
It seems it's only the case when the documentation is generated from
github using the workflow defined in the release.yml file.

This commit allows to generate the doc from outside github, by
retrieving the ref or tag of the current branch if we are on a git
repository.
Otherwise the version is set to "n/a".
  • Loading branch information
sbourdelin committed May 12, 2021
1 parent fa2a873 commit 63057eb
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion doc/sphinx/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import subprocess
# import sys
# sys.path.insert(0, os.path.abspath('.'))

Expand All @@ -24,7 +25,19 @@
author = 'SiFive Inc.'

# The short X.Y version
version = os.environ['RELEASE_TAG']
# if github provides us a ref or tag
if 'RELEASE_TAG' in os.environ:
version = os.environ['RELEASE_TAG']
# if we are in a git repository
elif subprocess.call(["git", "branch"], stderr=subprocess.STDOUT, stdout=open(os.devnull, 'w')) == 0:
# retrieve the last tag or ref on that branch
git = subprocess.Popen(['git', 'show-ref', 'HEAD'], stdout=subprocess.PIPE)
cut = subprocess.Popen(['cut', '-d/', '-f3'], stdin=git.stdout, stdout=subprocess.PIPE)
git.stdout.close()
version = cut.communicate()[0].strip().decode('ascii')
else:
version = "n/a"

# The full version, including alpha/beta/rc tags
release = version

Expand Down

0 comments on commit 63057eb

Please sign in to comment.