Skip to content
This repository was archived by the owner on Nov 7, 2026. It is now read-only.

Commit 7e2eee8

Browse files
Webseite automatisch per SFTP zu All-Inkl veröffentlichen (#67)
* Webseite automatisch per SFTP zu All-Inkl veröffentlichen Neuer Workflow „Webseite veröffentlichen“: prüft die Web-App (Tests, website/app aktuell) und lädt website/ danach per lftp hoch. Start per Tag web-v… oder von Hand, mit Trockenlauf. Gelöscht werden nur Dateien früherer Läufe (Manifest) und veraltete Dateien in app/assets/. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NsC5RADQbU18ZDp4dq4M4L * Zielordner "." erlauben (FTP-Benutzer mit eigenem Startordner) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NsC5RADQbU18ZDp4dq4M4L * Trockenlauf gegen den Server bei PRs, die den Upload ändern Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NsC5RADQbU18ZDp4dq4M4L --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 124ab4f commit 7e2eee8

4 files changed

Lines changed: 180 additions & 0 deletions

File tree

‎.github/scripts/deploy-website.sh‎

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env bash
2+
# Lädt den Ordner website/ per SFTP (oder FTPS) zu All-Inkl hoch.
3+
#
4+
# Auf dem Server wird nur gelöscht, was ein früherer Lauf dieses Skripts selbst
5+
# hochgeladen hat (Liste in .visustruct-deploy-manifest.txt im Zielordner), und
6+
# veraltete Build-Dateien in app/assets/.
7+
# Fremde Dateien im Zielordner und alles außerhalb davon bleiben unangetastet.
8+
#
9+
# Umgebung:
10+
# DEPLOY_HOST, DEPLOY_USER, LFTP_PASSWORD Pflicht
11+
# DEPLOY_PROTOCOL sftp (Standard) oder ftps
12+
# DEPLOY_DIR Zielordner relativ zum Login, Standard visustruct.org
13+
# ("." wenn der FTP-Benutzer direkt in diesem Ordner landet)
14+
# SOURCE_DIR Standard website
15+
# DRY_RUN=1 nur anzeigen, nichts hochladen oder löschen
16+
set -euo pipefail
17+
18+
: "${DEPLOY_HOST:?DEPLOY_HOST fehlt}"
19+
: "${DEPLOY_USER:?DEPLOY_USER fehlt}"
20+
: "${LFTP_PASSWORD:?LFTP_PASSWORD fehlt}"
21+
export LFTP_PASSWORD
22+
23+
PROTOCOL="${DEPLOY_PROTOCOL:-sftp}"
24+
REMOTE_DIR="${DEPLOY_DIR:-visustruct.org}"
25+
SOURCE_DIR="${SOURCE_DIR:-website}"
26+
DRY_RUN="${DRY_RUN:-0}"
27+
MANIFEST=".visustruct-deploy-manifest.txt"
28+
29+
case "$REMOTE_DIR" in
30+
""|"/"|"~"|*..*|*'"'*) echo "Ungültiger Zielordner: '$REMOTE_DIR'" >&2; exit 1 ;;
31+
esac
32+
[ -f "$SOURCE_DIR/index.html" ] || { echo "$SOURCE_DIR/index.html fehlt" >&2; exit 1; }
33+
34+
case "$PROTOCOL" in
35+
sftp) URL="sftp://$DEPLOY_HOST"
36+
SETTINGS="set sftp:auto-confirm yes" ;;
37+
ftps) URL="ftp://$DEPLOY_HOST"
38+
SETTINGS="set ftp:ssl-force true; set ftp:ssl-protect-data true; set ssl:verify-certificate ${DEPLOY_VERIFY_CERT:-yes}" ;;
39+
*) echo "DEPLOY_PROTOCOL muss sftp oder ftps sein" >&2; exit 1 ;;
40+
esac
41+
42+
work="$(mktemp -d)"
43+
trap 'rm -rf "$work"' EXIT
44+
45+
connect="$SETTINGS; set net:max-retries 3; set net:timeout 30; set cmd:fail-exit yes
46+
open --env-password -u \"$DEPLOY_USER\" $URL
47+
cd \"$REMOTE_DIR\""
48+
49+
# Neue Dateiliste
50+
(cd "$SOURCE_DIR" && find . -type f ! -name .DS_Store ! -name "$MANIFEST" | sed 's|^\./||' | LC_ALL=C sort) > "$work/new"
51+
52+
# Alte Dateiliste vom Server (fehlt beim ersten Lauf)
53+
if ! lftp -c "$connect; get $MANIFEST -o \"$work/old\"" 2>/dev/null; then
54+
echo "Keine frühere Dateiliste auf dem Server gefunden, es wird nichts gelöscht."
55+
: > "$work/old"
56+
fi
57+
58+
# app/assets/ wird von Vite bei jedem Build komplett neu erzeugt (Dateinamen mit
59+
# Hash). Was dort auf dem Server liegt und nicht mehr zum Build gehört, ist veraltet,
60+
# auch wenn es noch von Hand hochgeladen wurde.
61+
lftp -c "$connect; cls -1 app/assets/" 2>/dev/null | sed 's|^.*/||; s|^|app/assets/|' | grep -v '/$' >> "$work/old" || true
62+
63+
# Dateien, die früher hochgeladen wurden und jetzt nicht mehr dazugehören
64+
LC_ALL=C sort -u "$work/old" | LC_ALL=C comm -23 - "$work/new" > "$work/stale"
65+
: > "$work/rm.lftp"
66+
while IFS= read -r f; do
67+
case "$f" in
68+
""|/*|*..*|*'"'*|*'\'*) echo "Überspringe verdächtigen Eintrag: '$f'" >&2; continue ;;
69+
esac
70+
echo "rm -f \"$f\"" >> "$work/rm.lftp"
71+
done < "$work/stale"
72+
73+
echo "Dateien: $(wc -l < "$work/new") hochladen, $(wc -l < "$work/rm.lftp") veraltete löschen (Ziel: $REMOTE_DIR)"
74+
sed 's/^rm -f / löschen: /' "$work/rm.lftp"
75+
76+
if [ "$DRY_RUN" = "1" ]; then
77+
lftp -c "$connect; mirror -R --dry-run --no-perms --exclude-glob .DS_Store \"$SOURCE_DIR\" ."
78+
echo "Trockenlauf: nichts geändert."
79+
exit 0
80+
fi
81+
82+
# Erst alles außer HTML (Skripte, Bilder, CSS), dann die Seiten selbst,
83+
# damit keine Seite live ist, deren Assets noch fehlen.
84+
lftp <<LFTP
85+
$connect
86+
mirror -R --no-perms --parallel=4 --exclude-glob .DS_Store --exclude-glob *.html "$SOURCE_DIR" .
87+
mirror -R --no-perms --parallel=4 --exclude-glob .DS_Store "$SOURCE_DIR" .
88+
source "$work/rm.lftp"
89+
put "$work/new" -o $MANIFEST
90+
LFTP
91+
echo "Fertig."
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Webseite veröffentlichen
2+
3+
# Lädt website/ nach All-Inkl (visustruct.org) hoch.
4+
# Start: Tag web-v… anlegen (z. B. web-v1.0, auch über „Draft a new release“)
5+
# oder von Hand unter Actions → „Webseite veröffentlichen“ → „Run workflow“.
6+
# Ändert ein PR den Upload selbst, läuft nur ein Trockenlauf gegen den Server.
7+
on:
8+
pull_request:
9+
paths:
10+
- '.github/workflows/deploy-website.yml'
11+
- '.github/scripts/deploy-website.sh'
12+
push:
13+
tags: ['web-v*']
14+
workflow_dispatch:
15+
inputs:
16+
dry_run:
17+
description: 'Trockenlauf: nur anzeigen, was hochgeladen und gelöscht würde'
18+
type: boolean
19+
default: false
20+
21+
permissions:
22+
contents: read
23+
24+
concurrency:
25+
group: deploy-website
26+
cancel-in-progress: false
27+
28+
jobs:
29+
check:
30+
runs-on: ubuntu-latest
31+
defaults:
32+
run:
33+
working-directory: web
34+
steps:
35+
- uses: actions/checkout@v4
36+
- uses: actions/setup-node@v4
37+
with:
38+
node-version: 22
39+
cache: npm
40+
cache-dependency-path: web/package-lock.json
41+
- run: npm ci
42+
- name: Test
43+
run: npm test
44+
- name: website/app ist aktuell
45+
run: |
46+
npm run build:site
47+
git diff --exit-code -- ../website/app || (echo "website/app ist veraltet: in web/ 'npm run build:site' ausführen und committen." && exit 1)
48+
test -z "$(git status --porcelain -- ../website/app)"
49+
50+
deploy:
51+
needs: check
52+
# PRs aus Forks bekommen keine Secrets
53+
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
54+
runs-on: ubuntu-latest
55+
steps:
56+
- uses: actions/checkout@v4
57+
- name: Zugangsdaten vorhanden?
58+
env:
59+
SFTP_USER: ${{ secrets.SFTP_USER }}
60+
SFTP_PASSWORD: ${{ secrets.SFTP_PASSWORD }}
61+
run: |
62+
if [ -z "$SFTP_USER" ] || [ -z "$SFTP_PASSWORD" ]; then
63+
echo "::error::Die Secrets SFTP_USER und SFTP_PASSWORD fehlen (Settings → Secrets and variables → Actions)."
64+
exit 1
65+
fi
66+
- name: lftp installieren
67+
run: sudo apt-get update -q && sudo apt-get install -y -q lftp
68+
- name: Hochladen
69+
env:
70+
DEPLOY_HOST: ${{ vars.DEPLOY_HOST || 'w0103087.kasserver.com' }}
71+
DEPLOY_PROTOCOL: ${{ vars.DEPLOY_PROTOCOL || 'sftp' }}
72+
DEPLOY_DIR: ${{ vars.DEPLOY_DIR || 'visustruct.org' }}
73+
DEPLOY_USER: ${{ secrets.SFTP_USER }}
74+
LFTP_PASSWORD: ${{ secrets.SFTP_PASSWORD }}
75+
DRY_RUN: ${{ (inputs.dry_run || github.event_name == 'pull_request') && '1' || '0' }}
76+
run: .github/scripts/deploy-website.sh

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is loosely inspired by Keep a Changelog.
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- **Website:** GitHub Actions workflow that publishes `website/` to visustruct.org via SFTP after the web tests pass (tag `web-v…` or manual start).
12+
913
### Changed
1014

1115
- **App:** the area below the diagram is headed “Object Inspector · <element kind>” (German „Objektinspektor · Verzweigung“ etc.), matching the web editor and the lessons. The palette keeps its heading “Elements”.

‎README.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ git clone https://github.com/code4teaching/VisuStruct-SwiftUI.git
2626

2727
**Remote:** [github.com/code4teaching/VisuStruct-SwiftUI](https://github.com/code4teaching/VisuStruct-SwiftUI)
2828

29+
## Website deployment
30+
31+
`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`).
32+
33+
- **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).
34+
- **Secrets** (*Settings → Secrets and variables → Actions*): `SFTP_USER`, `SFTP_PASSWORD`.
35+
- **Optional variables:** `DEPLOY_HOST` (default `w0103087.kasserver.com`), `DEPLOY_DIR` (default `visustruct.org`), `DEPLOY_PROTOCOL` (`sftp` or `ftps`).
36+
- 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.
37+
2938
## Changelog / release notes
3039

3140
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).

0 commit comments

Comments
 (0)