Skip to content

Commit

Permalink
chore(docs): updated build command for GH pages
Browse files Browse the repository at this point in the history
  • Loading branch information
cofin committed Nov 30, 2024
1 parent a5fdd16 commit 4acb65e
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions tools/build_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ class VersionSpec(TypedDict):


@contextmanager
def checkout(branch: str) -> Generator[None]:
subprocess.run(["git", "checkout", branch], check=True) # noqa: S607
def checkout(branch: str, skip: bool = False) -> Generator[None]:
if not skip:
subprocess.run(["git", "checkout", branch], check=True) # noqa: S607
yield
subprocess.run(["git", "checkout", "-"], check=True) # noqa: S607
if not skip:
subprocess.run(["git", "checkout", "-"], check=True) # noqa: S607


def load_version_spec() -> VersionSpec:
Expand All @@ -55,13 +57,13 @@ def load_version_spec() -> VersionSpec:

def build(output_dir: str, version: str | None) -> None:
if version is None:
version = importlib.metadata.version("litestar_inertia").rsplit(".")[0]
version = importlib.metadata.version("advanced_alchemy").rsplit(".")[0]
else:
os.environ["LITESTAR_INERTIA_DOCS_BUILD_VERSION"] = version
os.environ["LITESTAR_VITE_DOCS_BUILD_VERSION"] = version

subprocess.run(["make", "docs"], check=True) # noqa: S607

Path(output_dir).mkdir()
Path(output_dir).mkdir(exist_ok=True, parents=True)
Path(output_dir).joinpath(".nojekyll").touch(exist_ok=True)

version_spec = load_version_spec()
Expand All @@ -76,7 +78,7 @@ def build(output_dir: str, version: str | None) -> None:
shutil.copytree(docs_src_path, Path(output_dir) / version, dirs_exist_ok=True)

# copy existing versions into our output dir to preserve them when cleaning the branch
with checkout("gh-pages"):
with checkout("gh-pages", skip=True):
for other_version in [*version_spec["versions"], "latest"]:
other_version_path = Path(other_version)
other_version_target_path = Path(output_dir) / other_version
Expand Down

0 comments on commit 4acb65e

Please sign in to comment.