From 00a202ebbaaff8f848b05c25d7fa4ea31fedd04c Mon Sep 17 00:00:00 2001 From: Tarik Moussa Date: Wed, 10 Jun 2026 06:39:08 +0200 Subject: [PATCH] feat: global reusable workflows (workflow_call) + thin caller template Co-Authored-By: Claude Opus 4.8 --- .DS_Store | Bin 0 -> 6148 bytes .gitea/workflows/reusable-ai-review.yml | 39 +++++++++++ .gitea/workflows/reusable-security.yml | 84 ++++++++++++++++++++++++ README.md | 36 +++++++--- workflows/caller.example.yml | 29 ++++++++ 5 files changed, 180 insertions(+), 8 deletions(-) create mode 100644 .DS_Store create mode 100644 .gitea/workflows/reusable-ai-review.yml create mode 100644 .gitea/workflows/reusable-security.yml create mode 100644 workflows/caller.example.yml diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..aa88cc8424cf4a127637ef164777b8b809aacb73 GIT binary patch literal 6148 zcmeHKu};G<5IvVlw6JtUO#X%bfvLh5^arXWq977EBA~8W+4u#%hQB~8Y_Kx(&Sy$O z0%AfHx|7b&Ip5ir=g7_xky+g2bD|j$O`wdUDVhP{an_!UqU8W+!W?f$SePa zS9RWA?FrM+ls4p%>Lr~~f!^lhbCYxjhPx>ruZJgTr@eZ8d%Tmh2j(mNXX-zDcGGv9 zzKSxS3@8J;!2lodkjbH-w#tAqpbTso;Pb&k8C}FiFdQ9dLJ0sI!yE*Ct|d6eMsyJy zL5x6*gaReh#1g|uIP5n1xrmLRgp-NIhlwkjSfQA(I_9^*os1LIRvAzRx(w{es5Zje4H1Ioa^V!(`(WwO94#k;lla(vfX=nBfhevRNZ1f6gd! /tmp/gl.log 2>&1 + echo "code=$?" >> "$GITHUB_OUTPUT" + tail -n 3 /tmp/gl.log; cat /tmp/gl.log >> /tmp/scan.log + + - name: Trivy (IaC/config, leicht) + id: tv + continue-on-error: true + run: | + set +e + curl -sSL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh \ + | sh -s -- -b /usr/local/bin + cd src + trivy config --severity HIGH,CRITICAL --exit-code 1 . > /tmp/tv.log 2>&1 + echo "code=$?" >> "$GITHUB_OUTPUT" + tail -n 8 /tmp/tv.log; cat /tmp/tv.log >> /tmp/scan.log + + - name: Gate — hart blockieren bei Funden + run: | + echo "gitleaks=${{ steps.gl.outputs.code }} trivy=${{ steps.tv.outputs.code }}" + if [ "${{ steps.gl.outputs.code }}" != "0" ] || [ "${{ steps.tv.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 (bei Fehler; skippt sauber ohne Key) + if: failure() + continue-on-error: true + 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 diff --git a/README.md b/README.md index 8af93d5..07d9552 100644 --- a/README.md +++ b/README.md @@ -24,20 +24,40 @@ scripts/ context.py Gitea-Actions-Event-Kontext (GITHUB_*-Vars) ai_review.py Feature A ai_explain.py Features B & C -workflows/ Beispiel-Workflows zum Kopieren in Ziel-Repos +.gitea/workflows/ + reusable-security.yml on: workflow_call — zentraler Security-Scan + reusable-ai-review.yml on: workflow_call — zentraler PR-Review +workflows/ + caller.example.yml der EINE 12-Zeiler fürs Ziel-Repo (empfohlen) + *.example.yml standalone-Workflows (Alternative: kopieren) ``` Keine Abhängigkeiten — reine Python-Standardbibliothek, kein `pip install`. ## In ein Repo einbauen -1. Beispiel aus `workflows/` nach `.gitea/workflows/` im Ziel-Repo kopieren. -2. Im Repo (oder org-weit) die **Actions-Unit** aktivieren. -3. **Actions-Secret** `ANTHROPIC_API_KEY` setzen. Kommentiert wird per Auto-Token - (`${{ github.token }}`); reichen dessen Rechte nicht, ein `GITEA_BOT_TOKEN` - (PAT mit `write:issue`) als Secret hinterlegen. -4. Für „hart blockieren": in der Branch-Protection den `Security`-Check als - *required* markieren. +### Empfohlen: globaler Aufruf (reusable workflow) + +Nur **eine** Datei ins Ziel-Repo: `workflows/caller.example.yml` → +`.gitea/workflows/ci-ai.yml`. Sie ruft die zentrale Logik aus diesem Repo auf +(`uses: user2595/ci-ai/.gitea/workflows/reusable-*.yml@main` + `secrets: inherit`). +Logik-Updates passieren **einmal hier**, alle Repos ziehen automatisch nach. + +Einmalig zentral einzurichten: + +1. Runner **instanzweit** registrieren (Admin → Actions → Runners), Label `eulernest` + — sonst haben Repos außerhalb der org keinen Runner. +2. **Anonymen Clone für public Repos** erlauben (`REQUIRE_SIGNIN_VIEW=false`) — der Job + klont `ci-ai` für die Skripte. +3. `ANTHROPIC_API_KEY` als **Org-/Instanz-Actions-Secret** (KI-Schritte; ohne ihn laufen + die Scans normal, die KI-Teile überspringen sich sauber). +4. Für „hart blockieren": `security`-Check in der Branch-Protection als *required*. + +### Alternative: standalone (kopieren) + +`workflows/ai-review.example.yml` + `workflows/security.example.yml` direkt nach +`.gitea/workflows/` kopieren. Enthält die volle Logik (klont die Skripte selbst) — +mehr Copy-Paste, aber unabhängig von reusable-workflow-Support. ## Umstieg auf den Jetson (später) diff --git a/workflows/caller.example.yml b/workflows/caller.example.yml new file mode 100644 index 0000000..7367654 --- /dev/null +++ b/workflows/caller.example.yml @@ -0,0 +1,29 @@ +# GLOBALER CI-AI-Aufruf — das EINZIGE, was ein Ziel-Repo braucht. +# Kopie nach: /.gitea/workflows/ci-ai.yml +# +# Holt die komplette Logik zentral aus user2595/ci-ai (reusable workflows) — keine +# Skripte/Workflows ins Repo kopieren. Update der Logik passiert einmal in ci-ai. +# +# Voraussetzungen (einmalig zentral eingerichtet): +# 1. Runner instanzweit registriert (Label `eulernest`) +# 2. anonymer Clone für public Repos erlaubt +# 3. ANTHROPIC_API_KEY als Org-/Instanz-Actions-Secret (für die KI-Schritte; +# ohne ihn laufen die Scans, die KI-Teile überspringen sich sauber) +# 4. für „hart blockieren": den `security`-Check in der Branch-Protection +# als required markieren +name: CI-AI + +on: + pull_request: + push: + branches: [main, master] + +jobs: + security: + uses: user2595/ci-ai/.gitea/workflows/reusable-security.yml@main + secrets: inherit + + review: + if: github.event_name == 'pull_request' + uses: user2595/ci-ai/.gitea/workflows/reusable-ai-review.yml@main + secrets: inherit