diff --git a/.github/scripts/deploy-website.sh b/.github/scripts/deploy-website.sh new file mode 100755 index 00000000..7d8a8082 --- /dev/null +++ b/.github/scripts/deploy-website.sh @@ -0,0 +1,91 @@ +#!/usr/bin/env bash +# Lädt den Ordner website/ per SFTP (oder FTPS) zu All-Inkl hoch. +# +# Auf dem Server wird nur gelöscht, was ein früherer Lauf dieses Skripts selbst +# hochgeladen hat (Liste in .visustruct-deploy-manifest.txt im Zielordner), und +# veraltete Build-Dateien in app/assets/. +# Fremde Dateien im Zielordner und alles außerhalb davon bleiben unangetastet. +# +# Umgebung: +# DEPLOY_HOST, DEPLOY_USER, LFTP_PASSWORD Pflicht +# DEPLOY_PROTOCOL sftp (Standard) oder ftps +# DEPLOY_DIR Zielordner relativ zum Login, Standard visustruct.org +# ("." wenn der FTP-Benutzer direkt in diesem Ordner landet) +# SOURCE_DIR Standard website +# DRY_RUN=1 nur anzeigen, nichts hochladen oder löschen +set -euo pipefail + +: "${DEPLOY_HOST:?DEPLOY_HOST fehlt}" +: "${DEPLOY_USER:?DEPLOY_USER fehlt}" +: "${LFTP_PASSWORD:?LFTP_PASSWORD fehlt}" +export LFTP_PASSWORD + +PROTOCOL="${DEPLOY_PROTOCOL:-sftp}" +REMOTE_DIR="${DEPLOY_DIR:-visustruct.org}" +SOURCE_DIR="${SOURCE_DIR:-website}" +DRY_RUN="${DRY_RUN:-0}" +MANIFEST=".visustruct-deploy-manifest.txt" + +case "$REMOTE_DIR" in + ""|"/"|"~"|*..*|*'"'*) echo "Ungültiger Zielordner: '$REMOTE_DIR'" >&2; exit 1 ;; +esac +[ -f "$SOURCE_DIR/index.html" ] || { echo "$SOURCE_DIR/index.html fehlt" >&2; exit 1; } + +case "$PROTOCOL" in + sftp) URL="sftp://$DEPLOY_HOST" + SETTINGS="set sftp:auto-confirm yes" ;; + ftps) URL="ftp://$DEPLOY_HOST" + SETTINGS="set ftp:ssl-force true; set ftp:ssl-protect-data true; set ssl:verify-certificate ${DEPLOY_VERIFY_CERT:-yes}" ;; + *) echo "DEPLOY_PROTOCOL muss sftp oder ftps sein" >&2; exit 1 ;; +esac + +work="$(mktemp -d)" +trap 'rm -rf "$work"' EXIT + +connect="$SETTINGS; set net:max-retries 3; set net:timeout 30; set cmd:fail-exit yes +open --env-password -u \"$DEPLOY_USER\" $URL +cd \"$REMOTE_DIR\"" + +# Neue Dateiliste +(cd "$SOURCE_DIR" && find . -type f ! -name .DS_Store ! -name "$MANIFEST" | sed 's|^\./||' | LC_ALL=C sort) > "$work/new" + +# Alte Dateiliste vom Server (fehlt beim ersten Lauf) +if ! lftp -c "$connect; get $MANIFEST -o \"$work/old\"" 2>/dev/null; then + echo "Keine frühere Dateiliste auf dem Server gefunden, es wird nichts gelöscht." + : > "$work/old" +fi + +# app/assets/ wird von Vite bei jedem Build komplett neu erzeugt (Dateinamen mit +# Hash). Was dort auf dem Server liegt und nicht mehr zum Build gehört, ist veraltet, +# auch wenn es noch von Hand hochgeladen wurde. +lftp -c "$connect; cls -1 app/assets/" 2>/dev/null | sed 's|^.*/||; s|^|app/assets/|' | grep -v '/$' >> "$work/old" || true + +# Dateien, die früher hochgeladen wurden und jetzt nicht mehr dazugehören +LC_ALL=C sort -u "$work/old" | LC_ALL=C comm -23 - "$work/new" > "$work/stale" +: > "$work/rm.lftp" +while IFS= read -r f; do + case "$f" in + ""|/*|*..*|*'"'*|*'\'*) echo "Überspringe verdächtigen Eintrag: '$f'" >&2; continue ;; + esac + echo "rm -f \"$f\"" >> "$work/rm.lftp" +done < "$work/stale" + +echo "Dateien: $(wc -l < "$work/new") hochladen, $(wc -l < "$work/rm.lftp") veraltete löschen (Ziel: $REMOTE_DIR)" +sed 's/^rm -f / löschen: /' "$work/rm.lftp" + +if [ "$DRY_RUN" = "1" ]; then + lftp -c "$connect; mirror -R --dry-run --no-perms --exclude-glob .DS_Store \"$SOURCE_DIR\" ." + echo "Trockenlauf: nichts geändert." + exit 0 +fi + +# Erst alles außer HTML (Skripte, Bilder, CSS), dann die Seiten selbst, +# damit keine Seite live ist, deren Assets noch fehlen. +lftp <” (German „Objektinspektor · Verzweigung“ etc.), matching the web editor and the lessons. The palette keeps its heading “Elements”. diff --git a/README.md b/README.md index 26251c7f..325fa0c8 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,15 @@ git clone https://github.com/code4teaching/VisuStruct-SwiftUI.git **Remote:** [github.com/code4teaching/VisuStruct-SwiftUI](https://github.com/code4teaching/VisuStruct-SwiftUI) +## Website deployment + +`website/` is published to visustruct.org (All-Inkl) by the workflow **Webseite veröffentlichen** (`.github/workflows/deploy-website.yml`). It runs the web tests first and then uploads via SFTP (`.github/scripts/deploy-website.sh`). + +- **Publish:** push a tag `web-v…` (e.g. `web-v1.0`, also possible via *Releases → Draft a new release*), or start it by hand under *Actions → Webseite veröffentlichen → Run workflow* (with an optional dry run). +- **Secrets** (*Settings → Secrets and variables → Actions*): `SFTP_USER`, `SFTP_PASSWORD`. +- **Optional variables:** `DEPLOY_HOST` (default `w0103087.kasserver.com`), `DEPLOY_DIR` (default `visustruct.org`), `DEPLOY_PROTOCOL` (`sftp` or `ftps`). +- On the server only files from earlier deployments (listed in `.visustruct-deploy-manifest.txt`) and outdated build files in `app/assets/` are deleted. Other files are left alone. + ## Changelog / release notes Versioned release notes live in **[CHANGELOG.md](CHANGELOG.md)**. On the repository’s **GitHub home page**, only this **README** is shown in full by default; open `CHANGELOG.md` in the file list (or use the **Changes** link at the top) to read the history. The **Releases** tab only shows extra notes if you create [GitHub Releases](https://github.com/code4teaching/VisuStruct-SwiftUI/releases) (optional, in addition to the changelog file).