Files
Landwelle Server ae9a8843b7
Landwelle Gitea CI / JavaScript and deployment-script checks (push) Successful in 45s
Landwelle Gitea CI / Go tests and vet (push) Successful in 51s
Landwelle Gitea source ZIP / source-zip (push) Successful in 52s
Landwelle Gitea CI / Linux x64 production build (push) Successful in 1m2s
chore(repo): organize portal sources, web assets and tests under cmd/portal
Preserve application source, public asset URLs, migrations and runtime version. Update Gitea workflows, build paths and developer documentation; retain existing x64 update commands.
2026-12-03 02:49:33 +01:00

51 lines
3.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
mkdir -p "$ROOT_DIR/dist"
cd "$ROOT_DIR"
# Go compiles all .go files in the package directory, including untracked files.
# A stale local source (e.g. destination_one.go) can break an otherwise green CI.
# Refuse to build instead of silently deleting potentially valuable local work.
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
EXTRA_GO="$(git ls-files --others --exclude-standard -- '*.go' | grep -E '^([^/]+|cmd/portal/[^/]+)\.go$' || true)"
if [[ -n "$EXTRA_GO" ]]; then
printf 'Build abgebrochen: nicht versionierte Go-Dateien im Projektverzeichnis:\n%s\n' "$EXTRA_GO" >&2
echo "Bitte Dateien sichern und aus dem Projektverzeichnis verschieben, bevor du neu baust." >&2
exit 1
fi
fi
# Startkritische ServeMux-Routen vor dem Build statisch prüfen.
# contentPages() registriert seine Slugs später dynamisch als "/"+slug. Deshalb
# reicht ein grep nach wörtlichen HandleFunc-Aufrufen nicht aus: Ein Slug darf
# nicht gleichzeitig explizit in main.go registriert sein.
EXPLICIT_PUBLIC_ROUTES="$(grep -oE 'mux\.HandleFunc\("/[^"]+"' cmd/portal/main.go | sed -E 's/.*HandleFunc\("([^"]+)"/\1/' | sort -u)"
CONTENT_PAGE_SLUGS="$(sed -n '/^func contentPages()/,/^}/p' cmd/portal/content.go | sed -nE 's/^[[:space:]]*"([^"]+)"[[:space:]]*:.*/\1/p')"
while IFS= read -r slug; do
[[ -z "$slug" ]] && continue
if grep -Fxq "/$slug" <<<"$EXPLICIT_PUBLIC_ROUTES"; then
printf 'Build abgebrochen: Route /%s wird sowohl explizit als auch dynamisch über contentPages() registriert.\n' "$slug" >&2
exit 1
fi
done <<<"$CONTENT_PAGE_SLUGS"
# Alte Build-Artefakte vor einem neuen Build entfernen. So kann ein fehlgeschlagener
# Build niemals versehentlich ein altes Portal-Binary für das Update stehen lassen.
rm -f "$ROOT_DIR/dist/landwelle-portal-linux-arm64" "$ROOT_DIR/dist/landwelle-adminpass-linux-arm64"
go mod download
go mod verify
COMMIT="$(git rev-parse --short=12 HEAD 2>/dev/null || printf unknown)"
BUILD_TIME="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
LDFLAGS="-s -w -X main.buildCommit=$COMMIT -X main.buildTime=$BUILD_TIME"
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags="$LDFLAGS" -o dist/landwelle-portal-linux-arm64 ./cmd/portal
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags="-s -w" -o dist/landwelle-adminpass-linux-arm64 ./cmd/adminpass
SOURCE_VERSION="$(sed -nE 's/^[[:space:]]*applicationVersion[[:space:]]*=[[:space:]]*"([^"]+)".*/\1/p' cmd/portal/main.go | head -n1)"
BUILT_VERSION="$("$ROOT_DIR/dist/landwelle-portal-linux-arm64" --version 2>/dev/null || true)"
if [[ -z "$SOURCE_VERSION" || "$BUILT_VERSION" != "Landwelle v$SOURCE_VERSION" ]]; then
printf 'Build abgebrochen: Binary-Version passt nicht zum Quellstand (Quelle: %s, Binary: %s).\n' "${SOURCE_VERSION:-unbekannt}" "${BUILT_VERSION:-unbekannt}" >&2
rm -f "$ROOT_DIR/dist/landwelle-portal-linux-arm64"
exit 1
fi
printf '%s\n' "ARM64-Portal erstellt: $ROOT_DIR/dist/landwelle-portal-linux-arm64" "Version: $BUILT_VERSION" "Commit: $COMMIT" "Build-Zeit: $BUILD_TIME"