Skip to content

Commit

Permalink
Added a method to determine the GitHub branch
Browse files Browse the repository at this point in the history
Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>
  • Loading branch information
melechlapson and Eric-Arellano committed Feb 21, 2024
1 parent 5bd18cd commit b985ba6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
33 changes: 30 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import datetime
import doctest
import inspect
import os
import re
import sys
from pathlib import PurePath

Expand Down Expand Up @@ -163,6 +165,33 @@
# ----------------------------------------------------------------------------------
# Source code links
# ----------------------------------------------------------------------------------
def determine_github_branch() -> str:
"""Determine the GitHub branch name to use for source code links. We need to decide whether to use `stable/<version>` vs. `main` for dev builds.
Refer to https://docs.github.com/en/actions/learn-github-actions/variables for how we determine this with GitHub Actions.
"""
print(os.environ)
# If not `GITHUB_REF_NAME` is not set, default to `main`. This
# is relevant for local builds.
if "GITHUB_REF_NAME" not in os.environ:
return "main"

# PR workflows set the branch they're merging into.
if base_ref := os.environ.get("GITHUB_BASE_REF"):
return base_ref

ref_name = os.environ["GITHUB_REF_NAME"]
if os.environ["GITHUB_REF_TYPE"] == "branch":
return ref_name

# Else, the ref_name is a tag like `1.0.0` or `1.0.0rc1`. We need
# to transform this to a Git branch like `stable/1.0`.
version_without_patch = re.match(r"(\d+\.\d+)", ref_name).group()
return f"stable/{version_without_patch}"


GITHUB_BRANCH = determine_github_branch()


def linkcode_resolve(domain, info):
if domain != "py":
return None
Expand Down Expand Up @@ -194,6 +223,4 @@ def linkcode_resolve(domain, info):
ending_lineno = lineno + len(source) - 1
linespec = f"#L{lineno}-L{ending_lineno}"

git_branch = "main"

return f"https://github.com/Qiskit/qiskit/tree/{git_branch}/{file_name}{linespec}"
return f"https://github.com/Qiskit/qiskit/tree/{GITHUB_BRANCH}/{file_name}{linespec}"
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ setenv =
QISKIT_SUPRESS_PACKAGING_WARNINGS=Y
QISKIT_TEST_CAPTURE_STREAMS=1
QISKIT_PARALLEL=FALSE
passenv = RAYON_NUM_THREADS, OMP_NUM_THREADS, QISKIT_PARALLEL, RUST_BACKTRACE, SETUPTOOLS_ENABLE_FEATURES, QISKIT_TESTS, QISKIT_IN_PARALLEL
passenv = RAYON_NUM_THREADS, OMP_NUM_THREADS, QISKIT_PARALLEL, RUST_BACKTRACE, SETUPTOOLS_ENABLE_FEATURES, QISKIT_TESTS, QISKIT_IN_PARALLEL, GITHUB_REF_NAME, GITHUB_REF_TYPE, GITHUB_BASE_REF
deps =
setuptools_rust # This is work around for the bug of tox 3 (see #8606 for more details.)
-r{toxinidir}/requirements.txt
Expand Down

0 comments on commit b985ba6

Please sign in to comment.