mirror of
https://github.com/deunix-educ/PyQuest.git
synced 2026-11-25 08:19:44 +01:00
Online documentation at /docs/ for authors and administrators: built into dist, nginx auth_request (check-docs), editor and admin links, Docker/server_update integration
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
+14
-3
@@ -17,10 +17,11 @@ NOT_PRECACHED = {"service-worker.js"}
|
||||
|
||||
|
||||
def is_author_tool(relative: str) -> bool:
|
||||
"""Fichiers propres à l'éditeur de niveaux : sur un serveur ils peuvent être protégés par authentification,
|
||||
donc jamais pré-cachés (le service worker les récupérerait sans session et mettrait une page de connexion en cache)."""
|
||||
"""Fichiers propres à l'éditeur de niveaux et documentation en ligne (/docs/) : sur un serveur ils peuvent être
|
||||
protégés par authentification, donc jamais pré-cachés (le service worker les récupérerait sans session et mettrait une page de connexion en cache)."""
|
||||
return (
|
||||
relative == "author.html"
|
||||
relative.startswith("docs/")
|
||||
or relative == "author.html"
|
||||
or relative == "css/author.css"
|
||||
or relative.startswith("js/author/")
|
||||
or (relative.startswith("js/i18n/author.") and relative.endswith(".json"))
|
||||
@@ -54,6 +55,14 @@ def content_hash(paths: list[str]) -> str:
|
||||
|
||||
|
||||
def main() -> int:
|
||||
# --docs DOSSIER : documentation déjà générée (mkdocs build), copiée dans dist/docs/ (non pré-cachée).
|
||||
docs: Path | None = None
|
||||
if "--docs" in sys.argv:
|
||||
index = sys.argv.index("--docs")
|
||||
docs = Path(sys.argv[index + 1]) if index + 1 < len(sys.argv) else None
|
||||
if docs is None or not (docs / "index.html").is_file():
|
||||
print("--docs : dossier de documentation générée introuvable (make docs).", file=sys.stderr)
|
||||
return 1
|
||||
pyodide = ROOT / "vendor" / "pyodide"
|
||||
if not pyodide.exists():
|
||||
print("vendor/pyodide absent : lancez `make vendor-pyodide` d'abord.", file=sys.stderr)
|
||||
@@ -64,6 +73,8 @@ def main() -> int:
|
||||
copy_tree(ROOT / "app", DIST)
|
||||
copy_tree(ROOT / "levels", DIST / "levels")
|
||||
shutil.copytree(pyodide, DIST / "vendor" / "pyodide")
|
||||
if docs is not None:
|
||||
shutil.copytree(docs, DIST / "docs")
|
||||
|
||||
precache = shell_files()
|
||||
worker = DIST / "service-worker.js"
|
||||
|
||||
@@ -62,6 +62,16 @@ else
|
||||
ko "author.html : 200 (public) ou 302 vers la connexion attendus, reçu ${author_code}"
|
||||
fi
|
||||
|
||||
# Documentation en ligne : réservée aux comptes connectés derrière le backend (302 vers la connexion) ; sinon publique.
|
||||
docs_code="$(status "${BASE}/docs/")"
|
||||
if [[ "${author_code}" == 302 ]]; then
|
||||
docs_location="$(header "${BASE}/docs/" Location)"
|
||||
if [[ "${docs_code}" == 302 && "${docs_location}" == *"/api/auth/login/?next=/docs/"* ]]; then ok "documentation protégée par connexion (/docs/)"; else ko "/docs/ : 302 vers la connexion attendu, reçu ${docs_code}"; fi
|
||||
expect_status "${BASE}/api/auth/check-docs/" 404
|
||||
else
|
||||
echo " info /docs/ répond ${docs_code} (200 = documentation publiée, 404 = absente)"
|
||||
fi
|
||||
|
||||
if [[ "${BASE}" == https://* ]]; then
|
||||
redirect="$(curl -s -o /dev/null -w '%{http_code}' --max-time 20 "http://${BASE#https://}/")"
|
||||
if [[ "${redirect}" == 301 || "${redirect}" == 308 ]]; then ok "HTTP redirige vers HTTPS (${redirect})"; else ko "HTTP devrait rediriger vers HTTPS, code ${redirect}"; fi
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#
|
||||
# ./scripts/server_update.sh # tout
|
||||
# ./scripts/server_update.sh --rollback # revient à la version précédente du site
|
||||
# Options : --no-pull --no-build --no-restart --no-check --dry-run
|
||||
# Options : --no-pull --no-build --no-docs --no-restart --no-check --dry-run
|
||||
#
|
||||
# Variables : PYQUEST_WEB_ROOT (défaut /var/www/pyquest), PYQUEST_KEEP (versions conservées, défaut 3),
|
||||
# PYQUEST_ENV_FILE (défaut /etc/pyquest/env), PYQUEST_SERVICE (défaut pyquest).
|
||||
@@ -17,12 +17,13 @@ KEEP="${PYQUEST_KEEP:-3}"
|
||||
ENV_FILE="${PYQUEST_ENV_FILE:-/etc/pyquest/env}"
|
||||
SERVICE="${PYQUEST_SERVICE:-pyquest}"
|
||||
VENV="${REPO}/.venv-prod"
|
||||
PULL=1; BUILD=1; RESTART=1; CHECK=1; DRY_RUN=0; ROLLBACK=0
|
||||
PULL=1; BUILD=1; DOCS=1; RESTART=1; CHECK=1; DRY_RUN=0; ROLLBACK=0
|
||||
|
||||
for arg in "$@"; do
|
||||
case "${arg}" in
|
||||
--no-pull) PULL=0 ;;
|
||||
--no-build) BUILD=0 ;;
|
||||
--no-docs) DOCS=0 ;;
|
||||
--no-restart) RESTART=0 ;;
|
||||
--no-check) CHECK=0 ;;
|
||||
--dry-run) DRY_RUN=1 ;;
|
||||
@@ -69,7 +70,21 @@ COMMIT="$(git -C "${REPO}" rev-parse --short HEAD 2>/dev/null || echo nogit)"
|
||||
if [[ "${BUILD}" == 1 ]]; then
|
||||
step "Moteur Python (Pyodide) et construction du site"
|
||||
run "${REPO}/scripts/vendor_pyodide.sh"
|
||||
run python3 "${REPO}/scripts/build.py"
|
||||
BUILD_ARGS=()
|
||||
if [[ "${DOCS}" == 1 ]]; then
|
||||
# Documentation en ligne (/docs/, réservée aux comptes connectés) : un échec ne bloque pas la mise à jour du site.
|
||||
DOCS_VENV="${REPO}/.venv-docs"
|
||||
if [[ "${DRY_RUN}" == 1 ]]; then
|
||||
echo "[dry-run] mkdocs build (documentation, ${DOCS_VENV})"
|
||||
BUILD_ARGS=(--docs "${REPO}/site")
|
||||
elif { [[ -x "${DOCS_VENV}/bin/mkdocs" ]] || { python3 -m venv "${DOCS_VENV}" && "${DOCS_VENV}/bin/pip" install --quiet -r "${REPO}/requirements-docs.txt"; }; } \
|
||||
&& (cd "${REPO}" && "${DOCS_VENV}/bin/mkdocs" build --quiet 2>/dev/null); then
|
||||
BUILD_ARGS=(--docs "${REPO}/site")
|
||||
else
|
||||
echo "ATTENTION : la documentation n'a pas pu être construite (paquet python3-venv, accès à PyPI ?) : le site est publié sans elle." >&2
|
||||
fi
|
||||
fi
|
||||
run python3 "${REPO}/scripts/build.py" "${BUILD_ARGS[@]}"
|
||||
fi
|
||||
[[ "${DRY_RUN}" == 1 || -f "${REPO}/dist/index.html" ]] || { echo "dist/ est absent : relancer sans --no-build." >&2; exit 1; }
|
||||
[[ "${DRY_RUN}" == 1 || -f "${REPO}/dist/vendor/pyodide/pyodide.asm.wasm" ]] || { echo "Pyodide manque dans dist/." >&2; exit 1; }
|
||||
|
||||
Reference in New Issue
Block a user