110 lines
3.4 KiB
YAML
110 lines
3.4 KiB
YAML
name: Deploy Docs
|
|
|
|
on:
|
|
push:
|
|
branches: ["main"]
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Set up Python
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: "3.11"
|
|
|
|
- name: Install MkDocs
|
|
run: pip install -r requirements.txt
|
|
|
|
- name: Fetch language READMEs and update nav
|
|
env:
|
|
GITEA_URL: https://git.keshavanand.net
|
|
ORG: foreign-thon
|
|
run: |
|
|
python3 << 'PYEOF'
|
|
import urllib.request
|
|
import json
|
|
import os
|
|
import re
|
|
|
|
gitea_url = os.environ["GITEA_URL"]
|
|
org = os.environ["ORG"]
|
|
|
|
# Read languages.yml manually (no yaml dep needed)
|
|
with open("languages.yml") as f:
|
|
lines = f.readlines()
|
|
|
|
languages = []
|
|
current = {}
|
|
for line in lines:
|
|
line = line.strip()
|
|
if line.startswith("- code:"):
|
|
if current:
|
|
languages.append(current)
|
|
current = {"code": line.split(":", 1)[1].strip()}
|
|
elif line.startswith("name:") and current:
|
|
current["name"] = line.split(":", 1)[1].strip()
|
|
elif line.startswith("repo:") and current:
|
|
current["repo"] = line.split(":", 1)[1].strip()
|
|
if current:
|
|
languages.append(current)
|
|
|
|
nav_lines = []
|
|
|
|
for lang in languages:
|
|
code = lang["code"]
|
|
name = lang["name"]
|
|
repo = lang["repo"]
|
|
|
|
readme_url = f"{gitea_url}/{org}/{repo}/raw/branch/main/README.md"
|
|
try:
|
|
with urllib.request.urlopen(readme_url) as r:
|
|
content = r.read().decode("utf-8")
|
|
out_path = f"docs/language-packs/{code}.md"
|
|
with open(out_path, "w", encoding="utf-8") as f:
|
|
f.write(content)
|
|
nav_lines.append(f" - '{name} ({code})': language-packs/{code}.md")
|
|
print(f"✓ {repo} → {out_path}")
|
|
except Exception as e:
|
|
print(f"✗ {repo}: {e}")
|
|
|
|
# Inject into mkdocs.yml between markers
|
|
with open("mkdocs.yml") as f:
|
|
yml = f.read()
|
|
|
|
nav_block = "\n".join(nav_lines)
|
|
new_yml = re.sub(
|
|
r" # LANGS_NAV_START.*?# LANGS_NAV_END",
|
|
f" # LANGS_NAV_START\n{nav_block}\n # LANGS_NAV_END",
|
|
yml,
|
|
flags=re.DOTALL
|
|
)
|
|
|
|
with open("mkdocs.yml", "w") as f:
|
|
f.write(new_yml)
|
|
|
|
print(f"Nav updated with {len(nav_lines)} languages.")
|
|
PYEOF
|
|
|
|
- name: Build
|
|
run: mkdocs build --strict
|
|
|
|
- name: Deploy
|
|
env:
|
|
SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }}
|
|
SERVER_USER: ${{ secrets.SERVER_USER }}
|
|
SERVER_HOST: ${{ secrets.SERVER_HOST }}
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
echo "$SSH_DEPLOY_KEY" > ~/.ssh/deploy_key
|
|
chmod 600 ~/.ssh/deploy_key
|
|
ssh-keyscan -H $SERVER_HOST >> ~/.ssh/known_hosts
|
|
ssh -i ~/.ssh/deploy_key $SERVER_USER@$SERVER_HOST \
|
|
"rm -rf /var/www/foreignthon-docs/* && mkdir -p /var/www/foreignthon-docs"
|
|
scp -i ~/.ssh/deploy_key -r site/* \
|
|
$SERVER_USER@$SERVER_HOST:/var/www/foreignthon-docs/
|