Skip to content

Commit

Permalink
Added GA to deploy doc versions
Browse files Browse the repository at this point in the history
  • Loading branch information
javiber committed Jan 4, 2023
1 parent 9d753db commit f10112b
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,24 @@ jobs:
run: |
poetry config -n pypi-token.pypi "$PYPI_TOKEN"
poetry publish --build -n
release:
runs-on: ubuntu-20.04
needs: [release]
if: github.event_name == 'release'
env:
PYTHON_VERSION: 3.8
steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: "${{ env.PYTHON_VERSION }}"

- name: Install dependencies
run: pip install -r docs/requirements.txt

- name: Install dependencies
run: python docs/deploy_docs.py
56 changes: 56 additions & 0 deletions docs/deploy_docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Script to deploy the latest version to github pages using mike"""
import logging
import subprocess
from typing import List, Union

from packaging import version

logger = logging.getLogger(__file__)


def run_cmd(cmd: str) -> List[str]:
"Run a command in a subprocess."
return subprocess.check_output(cmd.split()).decode("utf-8").splitlines()


def get_current_version() -> version.Version:
"Get current version specified in pyproject.toml."
for line in run_cmd("poetry version"):
if line.startswith("norfair"):
return version.parse(line.split()[-1])
raise Exception("Could not read current version from toml")


def get_latest_version() -> Union[version.Version, None]:
"Get the deployed version number tagged as `latest` in mike."
for line in run_cmd("mike list"):
if line.endswith("[latest]"):
return version.parse(line.split()[0])
logger.warning("Could not read the latest version deployed")


def truncate_version(v: version.Version):
"Truncates a version as `major.minor`"
return version.parse(f"{v.major}.{v.minor}")


if __name__ == "__main__":
logging.basicConfig()

current_version = get_current_version()
latest_version = get_latest_version()

target_version = truncate_version(current_version)
alias = ""

if latest_version is None or current_version >= latest_version:
alias = "latest"

logger.debug(f"{latest_version=}")
logger.debug(f"{current_version=}")
logger.debug(f"{target_version=}")
logger.debug(f"{alias=}")

logger.info("Running mike...")

logger.info("\n".join(run_cmd(f"mike deploy -u {target_version} {alias}")))

0 comments on commit f10112b

Please sign in to comment.