evennia/docs/deploy.py

66 lines
1.9 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.
This is assumed to be executed from inside the docs/ folder.
"""
import glob
import os
2022-11-14 21:30:05 +01:00
import subprocess
2022-11-14 20:42:10 +01:00
import sys
# branches that should not be rebuilt anymore (all others are considered active)
legacy_branches = ["0.9.5"]
# the branch pointed to by the 'latest' symlink
latest_branch = "0.9.5"
def deploy():
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
for file_path in glob.glob("*"):
# run from inside the docs/ dir
# delete old but active doc branches
2022-11-14 21:30:05 +01:00
_, *filename = file_path.rsplit("/", 1)
2022-11-14 20:42:10 +01:00
2022-11-14 21:30:05 +01:00
if filename and filename[0] in legacy_branches:
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
print("remove file_path:", file_path)
os.system(f"rm -Rf {file_path}")
2022-11-14 20:42:10 +01:00
# copy built branches to current dir
2022-11-14 21:30:05 +01:00
os.system("cp -Rf build/html/* .")
2022-11-14 20:42:10 +01:00
# symlink to latest and link its index to the root
2022-11-14 21:30:05 +01:00
os.system(f"ln -s {latest_branch} latest")
os.system(f"ln -s {latest_branch}/index.html .")
2022-11-14 20:42:10 +01:00
# docs/build is in .gitignore so will be skipped
2022-11-14 21:30:05 +01:00
os.system("git add .")
os.system('git commit -a -m "Updated HTML docs."')
os.system("git push origin gh-pages")
2022-11-14 20:42:10 +01:00
# get back to previous branch
2022-11-14 21:30:05 +01:00
os.system("git checkout .")
2022-11-14 20:42:10 +01:00
print("Deployed to https:// evennia.github.io/evennia/")
if __name__ == "__main__":
deploy()