Skip to content

Commit a1ab657

Browse files
authored
Merge pull request #239 from tryolabs/auto-doc-versioning
Automatically deploy new doc versions
2 parents da9f160 + f10112b commit a1ab657

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,24 @@ jobs:
145145
run: |
146146
poetry config -n pypi-token.pypi "$PYPI_TOKEN"
147147
poetry publish --build -n
148+
149+
150+
release:
151+
runs-on: ubuntu-20.04
152+
needs: [release]
153+
if: github.event_name == 'release'
154+
env:
155+
PYTHON_VERSION: 3.8
156+
steps:
157+
- uses: actions/checkout@v3
158+
159+
- name: Set up Python ${{ env.PYTHON_VERSION }}
160+
uses: actions/setup-python@v4
161+
with:
162+
python-version: "${{ env.PYTHON_VERSION }}"
163+
164+
- name: Install dependencies
165+
run: pip install -r docs/requirements.txt
166+
167+
- name: Install dependencies
168+
run: python docs/deploy_docs.py

docs/deploy_docs.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""Script to deploy the latest version to github pages using mike"""
2+
import logging
3+
import subprocess
4+
from typing import List, Union
5+
6+
from packaging import version
7+
8+
logger = logging.getLogger(__file__)
9+
10+
11+
def run_cmd(cmd: str) -> List[str]:
12+
"Run a command in a subprocess."
13+
return subprocess.check_output(cmd.split()).decode("utf-8").splitlines()
14+
15+
16+
def get_current_version() -> version.Version:
17+
"Get current version specified in pyproject.toml."
18+
for line in run_cmd("poetry version"):
19+
if line.startswith("norfair"):
20+
return version.parse(line.split()[-1])
21+
raise Exception("Could not read current version from toml")
22+
23+
24+
def get_latest_version() -> Union[version.Version, None]:
25+
"Get the deployed version number tagged as `latest` in mike."
26+
for line in run_cmd("mike list"):
27+
if line.endswith("[latest]"):
28+
return version.parse(line.split()[0])
29+
logger.warning("Could not read the latest version deployed")
30+
31+
32+
def truncate_version(v: version.Version):
33+
"Truncates a version as `major.minor`"
34+
return version.parse(f"{v.major}.{v.minor}")
35+
36+
37+
if __name__ == "__main__":
38+
logging.basicConfig()
39+
40+
current_version = get_current_version()
41+
latest_version = get_latest_version()
42+
43+
target_version = truncate_version(current_version)
44+
alias = ""
45+
46+
if latest_version is None or current_version >= latest_version:
47+
alias = "latest"
48+
49+
logger.debug(f"{latest_version=}")
50+
logger.debug(f"{current_version=}")
51+
logger.debug(f"{target_version=}")
52+
logger.debug(f"{alias=}")
53+
54+
logger.info("Running mike...")
55+
56+
logger.info("\n".join(run_cmd(f"mike deploy -u {target_version} {alias}")))

0 commit comments

Comments
 (0)