Skip to content

Commit

Permalink
Make build script that generates html from srt files, then pushes to …
Browse files Browse the repository at this point in the history
…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 <[email protected]>
  • Loading branch information
adikhoff and Arjan Dikhoff committed Oct 25, 2024
1 parent f3c3409 commit 2310323
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 5 deletions.
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
!redirects.csv
.env

_build/
_build-old/
_migrated/
env/
__pycache__
*.pyc
Expand Down Expand Up @@ -52,3 +49,9 @@ godot-docs-venv/

# Jetbrains IDE files
/.idea/

_build/
_migrated/
_sphinx/
_repo/
*.log
104 changes: 104 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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="[email protected]: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 [email protected]:Redot-Engine/redot-docs-live.git

echo "Setting credentials"
git config user.email "[email protected]"
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"
4 changes: 2 additions & 2 deletions migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@
('MadeWithGodot', 'MadeWithRedot'),
(' if on_rtd else "(DEV) "', ''),
('<span class="fa fa-book"> Read the Docs</span>', '<span class="fa fa-book"> Versions</span>'),
("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 <a href="https://readthedocs.org">Read the Docs', 'Hosted by <a href="https://cloudflare.com">CloudFlare'),
('<a href="https://docs.readthedocs.io/page/privacy-policy.html">Privacy Policy</a>', ''),
('G-dot', 'Godot'),
Expand Down

0 comments on commit 2310323

Please sign in to comment.