ci-ai: KI-Schicht für die Gitea-CI (PR-Review, Security-Erklärung, CI-Failure-Analyse)

Provider-agnostische LLM-Anbindung (Anthropic jetzt, Jetson/Ollama später per
Env-Var umschaltbar). Stdlib-only Skripte + Beispiel-Workflows. GitLab-Duo-Parität
für self-hosted Gitea + act_runner.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-09 15:38:53 +02:00
commit daf89ff8b9
10 changed files with 592 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
# Feature A — KI-PR-Review + Summary.
# In ein Ziel-Repo kopieren nach: .gitea/workflows/ai-review.yml
#
# Nutzt KEINE JS-Actions (kein node nötig): schlankes python-Image, ci-ai wird
# manuell geklont. GITHUB_REPOSITORY / GITHUB_EVENT_PATH setzt Gitea automatisch.
name: AI PR Review
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
review:
runs-on: eulernest
container: python:3.12-slim
steps:
- name: Tooling (git)
run: apt-get update -qq && apt-get install -y -qq --no-install-recommends git ca-certificates
- name: ci-ai-Skripte holen
run: git clone --depth 1 https://git.eulernest.eu/user2595/ci-ai.git /opt/ci-ai
- name: KI-Review
env:
AI_PROVIDER: anthropic
AI_MODEL: claude-3-5-haiku-latest
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
# Kommentieren: Actions-Auto-Token. Reicht dessen Schreibrecht nicht,
# stattdessen GITEA_BOT_TOKEN (PAT) als Repo-/Org-Secret setzen.
GITEA_TOKEN: ${{ github.token }}
GITEA_API: https://git.eulernest.eu/api/v1
run: python /opt/ci-ai/scripts/ai_review.py
# ─────────────────────────────────────────────────────────────────────────────
# Späterer Umstieg auf den Jetson (lokales Ollama) — NUR diese env-Werte ändern,
# kein Code-Change:
# AI_PROVIDER: ollama
# AI_MODEL: qwen-light
# AI_BASE_URL: http://192.168.178.20:11434/v1
# JETSON_API_KEY: ${{ secrets.JETSON_API_KEY }}

View File

@@ -0,0 +1,41 @@
# Feature C — KI-Analyse fehlgeschlagener CI-Jobs.
# KEIN eigenständiger Workflow, sondern ein MUSTER: diesen if:failure()-Job ans
# Ende eines echten Build/Test-Workflows hängen (needs: auf die CI-Jobs setzen).
# Er nimmt das geteilte Job-Log und lässt die KI die Ursache erklären.
#
# Beispiel-Einbettung in einen vorhandenen Workflow:
#
# jobs:
# build:
# runs-on: eulernest
# container: ghcr.io/catthehacker/ubuntu:act-latest
# steps:
# - uses: actions/checkout@v4
# - name: Build
# run: |
# set -o pipefail
# make 2>&1 | tee /tmp/ci.log # <-- Log mitschneiden
#
# explain-on-failure:
# needs: [build]
# if: failure()
# runs-on: eulernest
# container: python:3.12-slim
# steps:
# - name: Tooling
# run: apt-get update -qq && apt-get install -y -qq --no-install-recommends git ca-certificates
# - name: KI-Analyse
# env:
# AI_PROVIDER: anthropic
# AI_MODEL: claude-3-5-haiku-latest
# ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
# GITEA_TOKEN: ${{ github.token }}
# GITEA_API: https://git.eulernest.eu/api/v1
# run: |
# git clone --depth 1 https://git.eulernest.eu/user2595/ci-ai.git /opt/ci-ai
# python /opt/ci-ai/scripts/ai_explain.py ci-failure /tmp/ci.log
#
# Hinweis: /tmp wird zwischen Jobs NICHT automatisch geteilt. Für echtes Cross-
# Job-Log-Sharing das Log als actions/upload-artifact hochladen und im Folge-Job
# wieder herunterladen — ODER (einfacher) den explain-Schritt als if:failure()
# direkt in DENSELBEN Job hängen, wie in security.example.yml gezeigt.

View File

@@ -0,0 +1,60 @@
# Feature B (+C) — Security-Scan, HART blockierend, mit KI-Klartext-Erklärung.
# In ein Ziel-Repo kopieren nach: .gitea/workflows/security.yml
#
# Ablauf: scannen (ohne sofort abzubrechen) -> Gate (failt hart bei Funden) ->
# bei Fehler erklärt die KI die Funde im PR. So failt der Check verlässlich UND
# der Erklär-Schritt sieht beide Reports.
name: Security
on:
pull_request:
push:
branches: [main, master]
jobs:
scan:
runs-on: eulernest
container: ghcr.io/catthehacker/ubuntu:act-latest
steps:
- name: Checkout (volle Historie für Gitleaks)
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Gitleaks (Secret-Scan)
id: gitleaks
continue-on-error: true
run: |
curl -sSL https://github.com/gitleaks/gitleaks/releases/latest/download/gitleaks_linux_x64.tar.gz \
| tar -xz -C /usr/local/bin gitleaks
gitleaks detect --source . --report-format json --report-path /tmp/gitleaks.json --no-banner \
| tee /tmp/gitleaks.txt; echo "code=${PIPESTATUS[0]}" >> "$GITHUB_OUTPUT"
- name: Trivy (fs + IaC, HIGH/CRITICAL)
id: trivy
continue-on-error: true
run: |
curl -sSL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh \
| sh -s -- -b /usr/local/bin
trivy fs --scanners vuln,secret,misconfig --severity HIGH,CRITICAL \
--exit-code 1 --no-progress . | tee /tmp/trivy.txt; echo "code=${PIPESTATUS[0]}" >> "$GITHUB_OUTPUT"
- name: Gate — hart blockieren bei Funden
run: |
cat /tmp/gitleaks.txt /tmp/trivy.txt > /tmp/scan.log 2>/dev/null || true
if [ "${{ steps.gitleaks.outputs.code }}" != "0" ] || [ "${{ steps.trivy.outputs.code }}" != "0" ]; then
echo "Security-Funde — Check schlägt fehl (hart blockierend)."; exit 1
fi
echo "Keine HIGH/CRITICAL-Funde."
- name: KI erklärt die Funde (nur bei Fehler)
if: failure()
env:
AI_PROVIDER: anthropic
AI_MODEL: claude-3-5-haiku-latest
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
GITEA_TOKEN: ${{ github.token }}
GITEA_API: https://git.eulernest.eu/api/v1
run: |
git clone --depth 1 https://git.eulernest.eu/user2595/ci-ai.git /opt/ci-ai
python3 /opt/ci-ai/scripts/ai_explain.py security /tmp/scan.log