rd13_copilot_setup/scripts/deploy.sh
Conrad Schulz 0d42b4fb55 feat: copilot-update.sh + git copilot-update alias + post-merge auto-deploy
- scripts/copilot-update.sh: zieht Setup-Repo (SSH+HTTP-Fallback) in ~/.copilot-setup/,
  aktualisiert ~/.git-templates/, VS Code Prompts und repo-lokale Git-Hooks;
  copilot-instructions.md nur bei TODO-Erkennung (mit .bak Backup)
- scripts/copilot-update.fish: Fish-Variante desselben Scripts
- git-templates/hooks/post-merge: opt-in Template-Hook (ruft copilot-update.sh auf)
- scripts/deploy.sh: installiert copilot-update.sh/.fish, setzt 'git copilot-update'
  Alias, installiert post-merge Hook im Setup-Repo selbst (auto-deploy nach git pull)
- scripts/deploy.fish: analog
- scripts/copilot-bootstrap.sh: --with-update-hook Flag + post-commit Hook Installation
2026-06-02 10:36:16 +00:00

111 lines
5.8 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# deploy.sh Copilot-Setup auf macOS oder Linux mit bash deployen
# Usage: bash scripts/deploy.sh
set -euo pipefail
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
echo "=== Copilot Setup Deploy (bash) ==="
echo "Source: $REPO_DIR"
# ── 1. VS Code User-Verzeichnis ermitteln ─────────────────────────────────────
if [[ "$OSTYPE" == "darwin"* ]]; then
VSCODE_USER="$HOME/Library/Application Support/Code/User"
# VS Code Server (Cursor, Codium, etc.)
VSCODE_USER_ALT="$HOME/Library/Application Support/Cursor/User"
elif [[ -d "$HOME/.vscode-server/data/User" ]]; then
# Remote / VS Code Server
VSCODE_USER="$HOME/.vscode-server/data/User"
else
VSCODE_USER="$HOME/.config/Code/User"
fi
echo "VS Code User dir: $VSCODE_USER"
mkdir -p "$VSCODE_USER"
# ── 2. User settings.json ─────────────────────────────────────────────────────
if [[ -f "$VSCODE_USER/settings.json" ]]; then
echo " ─ settings.json exists skipping (merge manually if needed)"
echo " Reference: $REPO_DIR/user-settings/settings.json"
else
cp "$REPO_DIR/user-settings/settings.json" "$VSCODE_USER/settings.json"
echo " ✓ settings.json deployed"
fi
# ── 3. Prompt Files ───────────────────────────────────────────────────────────
mkdir -p "$VSCODE_USER/prompts"
for f in "$REPO_DIR/prompts/"*.prompt.md; do
fname="$(basename "$f")"
if [[ -f "$VSCODE_USER/prompts/$fname" ]]; then
echo " ─ prompts/$fname already exists, skipping"
else
cp "$f" "$VSCODE_USER/prompts/$fname"
echo " ✓ prompts/$fname deployed"
fi
done
# ── 4. Git-Templates ──────────────────────────────────────────────────────────
GIT_TEMPLATE_DIR="$HOME/.git-templates"
mkdir -p "$GIT_TEMPLATE_DIR/.github" "$GIT_TEMPLATE_DIR/.vscode" \
"$GIT_TEMPLATE_DIR/hooks" "$GIT_TEMPLATE_DIR/docs" \
"$GIT_TEMPLATE_DIR/history/summary"
cp "$REPO_DIR/git-templates/.github/copilot-instructions.md" "$GIT_TEMPLATE_DIR/.github/"
cp "$REPO_DIR/git-templates/.vscode/settings.json" "$GIT_TEMPLATE_DIR/.vscode/"
cp "$REPO_DIR/git-templates/.vscode/extensions.json" "$GIT_TEMPLATE_DIR/.vscode/"
cp "$REPO_DIR/git-templates/hooks/pre-commit" "$GIT_TEMPLATE_DIR/hooks/"
chmod +x "$GIT_TEMPLATE_DIR/hooks/pre-commit"
cp "$REPO_DIR/git-templates/docs/USER.md" "$GIT_TEMPLATE_DIR/docs/"
cp "$REPO_DIR/git-templates/docs/ADMIN.md" "$GIT_TEMPLATE_DIR/docs/"
cp "$REPO_DIR/git-templates/docs/MAINTAINER.md" "$GIT_TEMPLATE_DIR/docs/"
cp "$REPO_DIR/git-templates/history/summary/PROJECT_CONTEXT.md" "$GIT_TEMPLATE_DIR/history/summary/"
git config --global init.templateDir "$GIT_TEMPLATE_DIR"
echo " ✓ git-templates deployed → $GIT_TEMPLATE_DIR"
echo " ✓ git config init.templateDir set"
# ── 5. Bootstrap- & Update-Skripte ───────────────────────────────────────────
mkdir -p "$HOME/.local/bin"
cp "$REPO_DIR/scripts/copilot-bootstrap.sh" "$HOME/.local/bin/copilot-bootstrap.sh"
chmod +x "$HOME/.local/bin/copilot-bootstrap.sh"
echo " ✓ copilot-bootstrap.sh installed to ~/.local/bin/"
if [[ -f "$REPO_DIR/scripts/copilot-bootstrap.fish" ]]; then
cp "$REPO_DIR/scripts/copilot-bootstrap.fish" "$HOME/.local/bin/copilot-bootstrap.fish"
chmod +x "$HOME/.local/bin/copilot-bootstrap.fish"
echo " ✓ copilot-bootstrap.fish installed to ~/.local/bin/"
fi
cp "$REPO_DIR/scripts/copilot-update.sh" "$HOME/.local/bin/copilot-update.sh"
chmod +x "$HOME/.local/bin/copilot-update.sh"
echo " ✓ copilot-update.sh installed to ~/.local/bin/"
if [[ -f "$REPO_DIR/scripts/copilot-update.fish" ]]; then
cp "$REPO_DIR/scripts/copilot-update.fish" "$HOME/.local/bin/copilot-update.fish"
chmod +x "$HOME/.local/bin/copilot-update.fish"
echo " ✓ copilot-update.fish installed to ~/.local/bin/"
fi
# ── 6. Git-Aliase: init → auto-bootstrap | copilot-update → updater ──────────
# Verwendet git --exec-path um Rekursion zu vermeiden (kein Alias-Loop).
git config --global alias.init '!f() { dir=.; for a in "$@"; do case "$a" in -*) ;; *) dir="$a" ;; esac; done; "$(git --exec-path)/git-init" "$@" && "$HOME/.local/bin/copilot-bootstrap.sh" "$dir"; }; f'
echo " ✓ git alias 'init' gesetzt (führt copilot-bootstrap.sh automatisch aus)"
git config --global alias.copilot-update '!~/.local/bin/copilot-update.sh'
echo " ✓ git alias 'copilot-update' gesetzt (aktualisiert Templates & Prompts)"
# ── 7. post-merge Hook für dieses Setup-Repo ─────────────────────────────────
# Nach jedem 'git pull' auf dem Setup-Repo selbst wird deploy.sh automatisch
# ausgeführt, sodass Templates immer auf dem neuesten Stand sind.
SELF_HOOKS_DIR="$REPO_DIR/.git/hooks"
if [[ -d "$SELF_HOOKS_DIR" ]]; then
cat > "$SELF_HOOKS_DIR/post-merge" << 'HOOK'
#!/usr/bin/env sh
# post-merge Auto-Deploy nach git pull auf dem Setup-Repo
echo ""
echo " [post-merge] Setup-Repo aktualisiert deploye Templates neu..."
SCRIPT_DIR="$(cd "$(dirname "$0")/../../scripts" && pwd)"
bash "$SCRIPT_DIR/deploy.sh"
HOOK
chmod +x "$SELF_HOOKS_DIR/post-merge"
echo " ✓ post-merge Hook im Setup-Repo installiert (auto-deploy nach git pull)"
fi
echo ""
echo "=== Done ==="
echo "Next: Activate Settings Sync in VS Code (Cmd+Shift+P → 'Settings Sync: Turn On')"
echo " Templates aktuell halten: git copilot-update (in jedem Repo)"