-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnoxfile.py
More file actions
57 lines (44 loc) · 1.65 KB
/
Copy pathnoxfile.py
File metadata and controls
57 lines (44 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# SPDX-FileCopyrightText: Aresys S.r.l. <info@aresys.it>
# SPDX-License-Identifier: MIT
"""Automating SCT Plugins documentation NOX sessions"""
import os
import shutil
from datetime import datetime
from pathlib import Path
import nox
@nox.session()
def build_doc(session: nox.Session):
"""Building documentation"""
if Path("site").exists():
shutil.rmtree("site")
tag = os.getenv("CI_COMMIT_TAG") or os.getenv("GITHUB_REF_NAME", "dev")
sha = os.getenv("CI_COMMIT_SHORT_SHA")
date = datetime.now().strftime("%Y-%m-%d")
if sha is None:
try:
sha = session.run(
"git", "rev-parse", "--short", "HEAD", external=True, silent=True
).strip()
except Exception:
sha = ""
doc_name = f"{date}-{tag}-{sha}-html-doc"
session.log("Adding build info to documentation section")
build_info_file = Path("docs/about/build.template.md")
build_info = build_info_file.read_text()
build_info = (
build_info.replace("__SHA__", sha)
.replace("__TAG__", tag)
.replace("__DATE__", date)
)
build_info_file.parent.joinpath("build.md").write_text(build_info)
build_info_file.unlink()
session.log(f"Current dir: {Path.cwd()}")
session.log(f"Building documentation: {doc_name}")
session.install("zensical", "mkdocstrings-python")
session.run("pip", "list")
session.run("zensical", "build", "-f", str(Path.cwd() / "zensical.toml"))
if os.getenv("CI") == "true":
session.log("compressing documentation")
shutil.make_archive(
f"documentation-{doc_name}", "zip", root_dir=".", base_dir="site"
)