Skip to content
This repository was archived by the owner on Nov 7, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 71 additions & 19 deletions .github/scripts/deploy-website.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# Lädt den Ordner website/ per SFTP (oder FTPS) zu All-Inkl hoch.
# Lädt den Ordner website/ per FTPS (oder SFTP) 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
Expand All @@ -8,44 +8,96 @@
#
# 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)
# DEPLOY_PROTOCOL auto (Standard: erst SFTP, dann FTPS), sftp oder ftps
# DEPLOY_DIR Zielordner relativ zum Login; ohne Angabe visustruct.org
# oder der Startordner, je nachdem, wo die Webseite liegt
# SOURCE_DIR Standard website
# DRY_RUN=1 nur anzeigen, nichts hochladen oder löschen
set -euo pipefail

# Beim Einfügen ins Secret-Feld rutscht leicht ein Zeilenumbruch mit hinein
DEPLOY_USER="$(printf '%s' "${DEPLOY_USER:-}" | tr -d '\r\n' | sed 's/^[[:space:]]*//; s/[[:space:]]*$//')"
LFTP_PASSWORD="$(printf '%s' "${LFTP_PASSWORD:-}" | tr -d '\r\n')"
: "${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}"
PROTOCOL="${DEPLOY_PROTOCOL:-auto}"
REMOTE_DIR="${DEPLOY_DIR:-}"
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 ;;
"/"|"~"|*..*|*'"'*) 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
connect_for() {
local url settings
case "$1" 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 auto, sftp oder ftps sein" >&2; exit 1 ;;
esac
printf '%s' "$settings; set net:max-retries 3; set net:timeout 30; set cmd:fail-exit yes
open --env-password -u \"$DEPLOY_USER\" $url"
}

# auto: SFTP versuchen, bei All-Inkl geht das nur mit SSH-Zugang; sonst FTPS
if [ "$PROTOCOL" = "auto" ]; then
for p in sftp ftps; do
if lftp -c "$(connect_for $p); cls -1 >/dev/null" 2> "$work/probe-$p"; then
PROTOCOL=$p; break
fi
echo "$p: $(grep -v '^$' "$work/probe-$p" | tail -n 1)" >&2
done
if [ "$PROTOCOL" = "auto" ]; then
echo "::error::Anmeldung fehlgeschlagen. SFTP: $(grep -v '^$' "$work/probe-sftp" | tail -n 1) FTPS: $(grep -v '^$' "$work/probe-ftps" | tail -n 1)"
exit 1
fi
fi
echo "Verbindung über $PROTOCOL"

# Zielordner: ohne DEPLOY_DIR erst visustruct.org, dann der Startordner des
# Logins (FTP-Benutzer, die direkt in visustruct.org landen). Hochgeladen wird
# nur in einen Ordner, in dem schon VisuStruct liegt (index.html nennt
# VisuStruct oder ein früherer Lauf hat seine Dateiliste hinterlassen).
looks_like_site() {
lftp -c "$(connect_for "$PROTOCOL"); set cmd:fail-exit no; cd \"$1\" || exit 1; cat index.html" 2>/dev/null | grep -q VisuStruct \
|| lftp -c "$(connect_for "$PROTOCOL"); cd \"$1\"; cls -1 $MANIFEST" >/dev/null 2>&1
}
if [ -z "$REMOTE_DIR" ]; then
for d in visustruct.org .; do
if looks_like_site "$d"; then REMOTE_DIR="$d"; break; fi
done
if [ -z "$REMOTE_DIR" ]; then
echo "::error::Kein Zielordner gefunden: weder visustruct.org noch der Startordner des Logins enthalten die VisuStruct-Webseite. Bitte die Variable DEPLOY_DIR setzen."
exit 1
fi
elif ! looks_like_site "$REMOTE_DIR"; then
echo "::error::Im Zielordner '$REMOTE_DIR' liegt keine VisuStruct-Webseite (index.html), es wird nichts hochgeladen."
exit 1
fi
echo "Zielordner: $REMOTE_DIR"
connect="$(connect_for "$PROTOCOL")
cd \"$REMOTE_DIR\""

# Fehlermeldungen von lftp zusätzlich als Annotation ausgeben (in der Übersicht
# des Laufs sichtbar, ohne das Log zu öffnen)
fail() {
local msg
msg="$(grep -v '^$' "$work/err" | tail -n 3 | tr '\n' ' ')"
echo "::error::Upload fehlgeschlagen: ${msg:-unbekannter Fehler}"
exit 1
}

# Neue Dateiliste
(cd "$SOURCE_DIR" && find . -type f ! -name .DS_Store ! -name "$MANIFEST" | sed 's|^\./||' | LC_ALL=C sort) > "$work/new"

Expand Down Expand Up @@ -74,14 +126,14 @@ echo "Dateien: $(wc -l < "$work/new") hochladen, $(wc -l < "$work/rm.lftp") vera
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\" ."
lftp -c "$connect; mirror -R --dry-run --no-perms --exclude-glob .DS_Store \"$SOURCE_DIR\" ." 2> >(tee "$work/err" >&2) || fail
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 <<LFTP
lftp 2> >(tee "$work/err" >&2) <<LFTP || fail
$connect
mirror -R --no-perms --parallel=4 --exclude-glob .DS_Store --exclude-glob *.html "$SOURCE_DIR" .
mirror -R --no-perms --parallel=4 --exclude-glob .DS_Store "$SOURCE_DIR" .
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy-website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ jobs:
- name: Hochladen
env:
DEPLOY_HOST: ${{ vars.DEPLOY_HOST || 'w0103087.kasserver.com' }}
DEPLOY_PROTOCOL: ${{ vars.DEPLOY_PROTOCOL || 'sftp' }}
DEPLOY_DIR: ${{ vars.DEPLOY_DIR || 'visustruct.org' }}
DEPLOY_PROTOCOL: ${{ vars.DEPLOY_PROTOCOL || 'ftps' }}
DEPLOY_DIR: ${{ vars.DEPLOY_DIR }}
DEPLOY_USER: ${{ secrets.SFTP_USER }}
LFTP_PASSWORD: ${{ secrets.SFTP_PASSWORD }}
DRY_RUN: ${{ (inputs.dry_run || github.event_name == 'pull_request') && '1' || '0' }}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ git clone https://github.com/code4teaching/VisuStruct-SwiftUI.git

## 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`).
`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 FTPS, i.e. encrypted FTP (`.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`).
- **Optional variables:** `DEPLOY_HOST` (default `w0103087.kasserver.com`), `DEPLOY_DIR` (default: `visustruct.org` or the login's start folder, whichever holds the VisuStruct site), `DEPLOY_PROTOCOL` (default `ftps`; `sftp` or `auto` = try SFTP, then 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
Expand Down
Loading