-
Notifications
You must be signed in to change notification settings - Fork 1
/
noxfile.py
73 lines (57 loc) · 1.82 KB
/
noxfile.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
Noxfile for spok, primary function is to build the docs
which have python dependencies (mkdocs)
"""
import os
import webbrowser
import nox
# GitHub Actions
ON_CI = bool(os.getenv("CI"))
# Dependencies needed for a docs build
DOCS_DEPS = (
"mkdocs",
"mkdocs-material",
"mkdocs-include-markdown-plugin",
)
# Make it so the default nox task is to serve the docs
nox.options.sessions = ("serve",)
@nox.session
def build(session: nox.Session) -> None:
"""
Builds the project documentation
"""
session.install("--upgrade", "pip", "setuptools", "wheel")
session.install(*DOCS_DEPS)
session.run("mkdocs", "build", "--clean")
@nox.session
def serve(session: nox.Session) -> None:
"""
Builds the project documentation and serves it locally.
"""
session.install("--upgrade", "pip", "setuptools", "wheel")
session.install(*DOCS_DEPS)
webbrowser.open(url="http://127.0.0.1:8000/spok/")
session.run("mkdocs", "serve")
@nox.session
def publish(session: nox.Session) -> None:
"""
Used by GitHub actions to deploy docs to GitHub Pages.
"""
if not (token := os.getenv("GITHUB_TOKEN")):
session.error("Cannot deploy docs without a $GITHUB_TOKEN environment variable")
session.install("--upgrade", "pip", "setuptools", "wheel")
session.install(*DOCS_DEPS)
if ON_CI:
session.run(
"git",
"remote",
"add",
"gh-token",
f"https://{token}@github.com/FollowTheProcess/spok.git",
external=True,
)
session.run("git", "fetch", "gh-token", external=True)
session.run("git", "fetch", "gh-token", "gh-pages:gh-pages", external=True)
session.run("mkdocs", "gh-deploy", "-v", "--clean", "--remote-name", "gh-token")
else:
session.run("mkdocs", "gh-deploy")