From 23103236f27107f24a495a9859f5ea7cf4e99886 Mon Sep 17 00:00:00 2001 From: Craptain Date: Fri, 25 Oct 2024 23:20:44 +0200 Subject: [PATCH] Make build script that generates html from srt files, then pushes to redot-docs-live (#45) * Make build script that generates html from srt files, then pushes that html to redot-docs-live * Combines migrate.py, Sphinx, and some standard shell tools * Uses a deploy key that's limited to only the redot-docs-live repo * Publishes with ssh * Uses build secrets in CloudFlare that contain ssh keys * Contains a hack that removes a git config var that was inserted by CloudFlare * Limited external configurability for now, may change if needed * Remove Lint error --------- Co-authored-by: Arjan Dikhoff --- .gitignore | 9 +++-- build.sh | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++ migrate.py | 4 +-- 3 files changed, 112 insertions(+), 5 deletions(-) create mode 100755 build.sh diff --git a/.gitignore b/.gitignore index 2e2df35cecf..710a4e2301d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,9 +2,6 @@ !redirects.csv .env -_build/ -_build-old/ -_migrated/ env/ __pycache__ *.pyc @@ -52,3 +49,9 @@ godot-docs-venv/ # Jetbrains IDE files /.idea/ + +_build/ +_migrated/ +_sphinx/ +_repo/ +*.log diff --git a/build.sh b/build.sh new file mode 100755 index 00000000000..474658e811e --- /dev/null +++ b/build.sh @@ -0,0 +1,104 @@ +#!/bin/bash + +# Init env vars +date=`date` +workDir=`pwd` +sshCommand="ssh -v" # Add -v, -vv, or -vvv for verbose debugging + +gitBranch=`git rev-parse --abbrev-ref HEAD` +if [ -n "$CF_PAGES" ] +then + echo "We are on Cloudflare Pages. Retrieve branch from env." + gitBranch=$CF_PAGES_BRANCH +fi +gitCommitMessage="branch $gitBranch on $date" +redotDocsLiveBranch=${1:-develop} + +inputDir="." +migrateDir="_migrated" +sphinxDir="_sphinx" +repoDir="_repo" + +liveRoot="redot-docs-live" +liveRepo="git@github.com:Redot-Engine/$liveRoot.git" +buildDir="html/en/$gitBranch" # TODO: implement i18n support + +# Report vars and intention +echo "Building $gitCommitMessage" +echo "Live branch: $redotDocsLiveBranch" +echo "Live root: $liveRoot, live repo: $liveRepo, build dir: $buildDir, report dir: $reportDir" +echo "Temp dirs: $migrateDir, $sphinxDir, $repoDir" + +echo "Delete temp dirs" +rm -rf $migrateDir +rm -rf $sphinxDir +rm -rf $repoDir + +echo "Migrate Godot to Redot" +mkdir -p $migrateDir +python migrate.py $inputDir $migrateDir + +echo "Translate to html" +mkdir -p $sphinxDir +sphinx-build -b html -j 4 $migrateDir $sphinxDir + +echo "DUMMY FILE FOR TESTING: $date" > $sphinxDir/test.html + +echo "Cloning $liveRepo $repoDir" +git clone $liveRepo $repoDir + +cd $repoDir +echo "Checking out $redotDocsLiveBranch" +git checkout $redotDocsLiveBranch + +git config core.sshCommand "$sshCommand" +echo "Using ssh command: $sshCommand" + +if [ -n "$CF_PAGES" ] +then + echo "We are on Cloudflare Pages. Setting custom ssh key and method" + # HACK: Remove annoying https redirect. I presume this was used by Cloudflare + echo "Remove Cloudflare redirect." + insteadof=`git config --list | grep insteadof` + remove=`echo $insteadof | cut -d "=" -f 1` + git config --global --unset $remove + + mkdir ~/.ssh + echo "$BUILD_SSH_KEY" > ~/.ssh/id_ed25519 + echo "$BUILD_SSH_KEY_PUB" > ~/.ssh/id_ed25519.pub + echo "$KNOWN_HOSTS" > ~/.ssh/known_hosts + + chmod 0600 ~/.ssh/id_ed25519 + chmod 0600 ~/.ssh/id_ed25519.pub + chmod 0644 ~/.ssh/known_hosts + chmod 0755 ~/.ssh + + # Init git + git remote set-url origin git@github.com:Redot-Engine/redot-docs-live.git + + echo "Setting credentials" + git config user.email "noreply_pages_bot@cloudflare.com" + git config user.name "Redot Docs Build Worker" +fi + +echo "### GIT CONFIG VALUES ###" +git config core.pager cat +git config --list + +echo "Copying generated content to repository" +echo "mkdir -p $buildDir" +mkdir -p $buildDir +echo "cp -r ../$sphinxDir/* $buildDir" +cp -r ../$sphinxDir/* $buildDir + +echo "Commit and push to $redotDocsLiveBranch, with message $gitCommitMessage" +git add . +git commit --message "$gitCommitMessage" +git push --force + +# Create some output so Cloudflare is happy +cd .. +mkdir -p ./output +echo "Build finished. Commit message: $gitCommitMessage" > ./output/index.html + +echo "Done. Made by @Craptain" diff --git a/migrate.py b/migrate.py index 4a857ec1b79..4eacc02c164 100644 --- a/migrate.py +++ b/migrate.py @@ -203,9 +203,9 @@ ('MadeWithGodot', 'MadeWithRedot'), (' if on_rtd else "(DEV) "', ''), (' Read the Docs', ' Versions'), - ("const homeUrl = baseUrl.split('/latest/')[0] + '/stable/';", "const homeUrl = 'https://docs-stable.redotengine.org/';"), + ("const homeUrl = baseUrl.split('/latest/')[0] + '/stable/';", "const homeUrl = '/en/stable';"), ('{% set listed_languages = ({"en":"#", "de":"#", "es":"#", "fr":"#"}).items() -%}', '{% set listed_languages = ({"en":"#"}).items() -%}'), - ('({"stable":"#", "latest":"#"})', '({"stable":"https://docs-stable.redotengine.org/", "latest":"https://docs-latest.redotengine.org/", "3.6":"https://docs-3-6.redotengine.org/"})'), + ('({"stable":"#", "latest":"#"})', '({"stable":"/en/stable", "latest":"/en/latest", "3.6":"/en/3.6"})'), ('Hosted by Read the Docs', 'Hosted by CloudFlare'), ('Privacy Policy', ''), ('G-dot', 'Godot'),