mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add detection of curroent commit / branch (#7745)
this ensures runs are reproducible/replacable and doc contents stay up
This commit is contained in:
parent
06a95f944e
commit
413cc0ce20
23
docs/main.py
23
docs/main.py
@ -2,7 +2,6 @@
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import textwrap
|
||||
|
||||
import requests
|
||||
import yaml
|
||||
@ -54,11 +53,23 @@ def check_link(url) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def get_build_enviroment() -> str:
|
||||
"""Returns the branch we are currently building on, based on the environment variables of the various CI platforms."""
|
||||
# Check if we are in ReadTheDocs
|
||||
if os.environ.get('READTHEDOCS') == 'True':
|
||||
return os.environ.get('READTHEDOCS_GIT_IDENTIFIER')
|
||||
# We are in GitHub Actions
|
||||
elif os.environ.get('GITHUB_ACTIONS') == 'true':
|
||||
return os.environ.get('GITHUB_REF')
|
||||
else:
|
||||
return 'master'
|
||||
|
||||
|
||||
def define_env(env):
|
||||
"""Define custom environment variables for the documentation build process."""
|
||||
|
||||
@env.macro
|
||||
def sourcedir(dirname, branch='master'):
|
||||
def sourcedir(dirname, branch=None):
|
||||
"""Return a link to a directory within the source code repository.
|
||||
|
||||
Arguments:
|
||||
@ -70,6 +81,9 @@ def define_env(env):
|
||||
Raises:
|
||||
- FileNotFoundError: If the directory does not exist, or the generated URL is invalid
|
||||
"""
|
||||
if branch == None:
|
||||
branch = get_build_enviroment()
|
||||
|
||||
if dirname.startswith('/'):
|
||||
dirname = dirname[1:]
|
||||
|
||||
@ -94,7 +108,7 @@ def define_env(env):
|
||||
return url
|
||||
|
||||
@env.macro
|
||||
def sourcefile(filename, branch='master', raw=False):
|
||||
def sourcefile(filename, branch=None, raw=False):
|
||||
"""Return a link to a file within the source code repository.
|
||||
|
||||
Arguments:
|
||||
@ -106,6 +120,9 @@ def define_env(env):
|
||||
Raises:
|
||||
- FileNotFoundError: If the file does not exist, or the generated URL is invalid
|
||||
"""
|
||||
if branch == None:
|
||||
branch = get_build_enviroment()
|
||||
|
||||
if filename.startswith('/'):
|
||||
filename = filename[1:]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user