|
66 | 66 | # built documents. |
67 | 67 |
|
68 | 68 | on_rtd = os.environ.get("READTHEDOCS") == "True" |
| 69 | +on_gha = os.environ.get("GITHUB_ACTIONS") == "true" |
| 70 | + |
69 | 71 | if on_rtd: |
70 | 72 | for item, value in os.environ.items(): |
71 | 73 | print("[READTHEDOCS] {} = {}".format(item, value)) |
72 | 74 |
|
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` |
75 | 79 | if on_rtd: |
76 | 80 | 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"]: |
80 | 82 | # get the latest git tag (which is what rtd normally builds under "stable") |
81 | 83 | # this works since rtd builds things within the repo |
82 | 84 | process = subprocess.Popen(["git", "describe", "--exact-match", "--tags"], stdout=subprocess.PIPE) |
|
87 | 89 | version = "v?.?.?" # this should not occur as "stable" is always pointing to tagged version |
88 | 90 | else: |
89 | 91 | 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 |
90 | 98 | 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 |
92 | 109 |
|
93 | 110 | # for now make these match |
94 | 111 | release = version |
|
0 commit comments