evennia/docs/deploy.py

90 lines
2.7 KiB
Python
Raw Normal View History

2022-11-14 20:42:10 +01:00
"""
Deploy to github, from github Action. This is run after the docs have finished building. All new
documentation branches will be available in build/html/* at this point. We need to copy those
contents to the root of the repo.
2022-11-15 19:48:08 +01:00
This can be tested with `make release` or `make deploy` and require git push rights to
the evennia repo. Use DISABLE_GIT_PUSH for local testing - git-pushing from local can cause
clashes upstream.
We will look in source/conf.py for the `.latest_version` string and `.legacy_versions` list,
this allows us to skip deleting legacy docs (which may be ever harder to build) while correctly
symlinking to the current 'latest' documentation.
2022-11-14 20:42:10 +01:00
This is assumed to be executed from inside the docs/ folder.
2022-11-15 19:48:08 +01:00
2022-11-14 20:42:10 +01:00
"""
import glob
2022-11-15 19:48:08 +01:00
import importlib
2022-11-14 20:42:10 +01:00
import os
2022-11-14 21:30:05 +01:00
import subprocess
2022-11-14 20:42:10 +01:00
import sys
2022-11-15 19:48:08 +01:00
# set for local testing
DISABLE_GIT_PUSH = False
2022-11-14 20:42:10 +01:00
def deploy():
2022-11-15 19:48:08 +01:00
"""Perform the deploy of the built Evennia documentation to the gh-pages branch."""
conf_file = importlib.machinery.SourceFileLoader("conf", "source/conf.py").load_module()
latest_version = conf_file.latest_version
legacy_versions = conf_file.legacy_versions
2022-11-14 20:42:10 +01:00
2022-11-14 21:30:05 +01:00
if subprocess.call(["git", "status", "--untracked=no", "--porcelain"]):
2022-11-14 20:42:10 +01:00
print(
"There are uncommitted or untracked changes. Make sure "
"to commit everything in your current branch first."
)
sys.exit(1)
# get the deployment branch
2022-11-14 21:30:05 +01:00
os.system("git fetch")
os.system("git checkout gh-pages")
2022-11-14 20:42:10 +01:00
2022-11-15 19:48:08 +01:00
os.system("pwd")
os.system("ls")
names_to_skip = legacy_versions + ["build"]
2022-11-14 20:42:10 +01:00
for file_path in glob.glob("*"):
# run from inside the docs/ dir
# delete old but active doc branches
2022-11-15 19:48:08 +01:00
if file_path in names_to_skip:
2022-11-14 20:42:10 +01:00
# skip deleting the legacy brancehs
continue
else:
# we want to delete both active branches and old symlinks
2022-11-14 21:30:05 +01:00
os.system(f"rm -Rf {file_path}")
2022-11-15 19:48:08 +01:00
print(f"removed file_path: {file_path}")
2022-11-14 20:42:10 +01:00
# copy built branches to current dir
2022-11-15 19:48:08 +01:00
os.system("ls")
2022-11-14 21:30:05 +01:00
os.system("cp -Rf build/html/* .")
2022-11-14 20:42:10 +01:00
2022-11-15 19:48:08 +01:00
os.system("ls")
2022-11-14 20:42:10 +01:00
2022-11-15 19:48:08 +01:00
# symlink to latest and link its index to the root
os.system(f"ln -s {latest_version} latest")
os.system(f"ln -s {latest_version}/index.html .")
os.system("ls")
if not DISABLE_GIT_PUSH:
print("committing and pushing docs ...")
os.system("git add .") # docs/build is in .gitignore so will be skipped
os.system('git commit -a -m "Updated HTML docs."')
os.system("git push origin gh-pages")
else:
print("Skipped git push.")
2022-11-14 20:42:10 +01:00
print("Deployed to https:// evennia.github.io/evennia/")
if __name__ == "__main__":
deploy()