Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
87a71255ce | ||
|
|
1ac3170d94 | ||
|
|
0e3ef69847 | ||
|
|
36b2a228e4 | ||
|
|
c3532e0ae1 | ||
|
|
7de27f79fe | ||
|
|
54c9d985c7 | ||
|
|
22e42b2858 | ||
|
|
b4717eba19 |
+214
-45
@@ -1,6 +1,8 @@
|
||||
name: OpenCode Gitea Integration
|
||||
|
||||
on:
|
||||
issues:
|
||||
types: [opened]
|
||||
issue_comment:
|
||||
types: [created]
|
||||
pull_request_review_comment:
|
||||
@@ -15,17 +17,21 @@ jobs:
|
||||
opencode-gitea:
|
||||
if: |
|
||||
github.event_name == 'workflow_dispatch' ||
|
||||
contains(github.event.comment.body, '/oc') ||
|
||||
contains(github.event.comment.body, '/opencode')
|
||||
(github.event_name == 'issues' &&
|
||||
(contains(github.event.issue.body, '/oc') || contains(github.event.issue.body, '/opencode'))) ||
|
||||
(github.event_name != 'issues' &&
|
||||
github.event.comment.user.login != 'opencode-bot' &&
|
||||
(contains(github.event.comment.body, '/oc') || contains(github.event.comment.body, '/opencode')))
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 20
|
||||
timeout-minutes: 40
|
||||
|
||||
env:
|
||||
GITEA_API_URL: "https://gitea.maribit.it"
|
||||
GITEA_TOKEN: ${{ secrets.BOT_GITEA_TOKEN }}
|
||||
REPO_FULL_NAME: ${{ github.repository }}
|
||||
COMMENT_BODY: ${{ github.event.comment.body || github.event.inputs.prompt }}
|
||||
COMMENT_AUTHOR: ${{ github.event.comment.user.login || github.actor }}
|
||||
COMMENT_BODY: ${{ github.event.comment.body || github.event.issue.body || github.event.inputs.prompt }}
|
||||
COMMENT_AUTHOR: ${{ github.event.comment.user.login || github.event.issue.user.login || github.actor }}
|
||||
COMMENT_ID: ${{ github.event.comment.id }}
|
||||
IS_PR_EVENT: ${{ github.event_name == 'pull_request_review_comment' }}
|
||||
IS_MANUAL: ${{ github.event_name == 'workflow_dispatch' }}
|
||||
PR_NUMBER_FROM_EVENT: ${{ github.event.pull_request.number }}
|
||||
@@ -34,14 +40,16 @@ jobs:
|
||||
ISSUE_TITLE: ${{ github.event.issue.title }}
|
||||
ISSUE_BODY: ${{ github.event.issue.body }}
|
||||
RUN_NUMBER: ${{ github.run_number }}
|
||||
# --- OpenCode ---
|
||||
OPENCODE_ZEN_API_KEY: ${{ secrets.OPENCODE_ZEN_API_KEY }}
|
||||
OPENCODE_API_BASE: https://opencode.ai
|
||||
OPENCODE_MODEL: opencode/big-pickle
|
||||
MAX_ITERATIONS: "4"
|
||||
|
||||
steps:
|
||||
- name: Verifica autorizzazione utente
|
||||
run: |
|
||||
# Whitelist esplicita: nessuna esecuzione automatica per utenti non fidati.
|
||||
ALLOWED_USERS="maria nicola"
|
||||
# L'esecuzione manuale (workflow_dispatch) è già ristretta a chi ha
|
||||
# permessi di scrittura sul repo, quindi la lasciamo passare.
|
||||
if [ "$IS_MANUAL" = "true" ]; then
|
||||
exit 0
|
||||
fi
|
||||
@@ -50,6 +58,27 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Feedback immediato: 👀 sul commento (o sulla issue). Le reazioni NON generano
|
||||
# eventi issue_comment -> nessun doppio run.
|
||||
- name: Reagisci al comando (👀)
|
||||
id: react
|
||||
run: |
|
||||
API="$GITEA_API_URL/api/v1/repos/$REPO_FULL_NAME"
|
||||
if [ -n "$COMMENT_ID" ]; then
|
||||
RPATH="issues/comments/$COMMENT_ID/reactions"
|
||||
elif [ -n "$ISSUE_NUMBER" ]; then
|
||||
RPATH="issues/$ISSUE_NUMBER/reactions"
|
||||
else
|
||||
RPATH=""
|
||||
fi
|
||||
echo "path=$RPATH" >> "$GITHUB_OUTPUT"
|
||||
if [ -n "$RPATH" ]; then
|
||||
curl -s -X POST "$API/$RPATH" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"content":"eyes"}' >/dev/null || true
|
||||
fi
|
||||
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
@@ -60,6 +89,31 @@ jobs:
|
||||
curl -fsSL https://opencode.ai/install | bash
|
||||
echo "$HOME/.opencode/bin" >> "$GITHUB_PATH"
|
||||
|
||||
# Agent "reviewer" read-only: legge ed esegue i test (bash), MAI edita.
|
||||
# Creato solo nel runner ed escluso dai commit, così non sporca il repo.
|
||||
- name: Configura agent reviewer (read-only)
|
||||
run: |
|
||||
mkdir -p .opencode/agents
|
||||
cat > .opencode/agents/reviewer.md <<'EOF'
|
||||
---
|
||||
description: Revisore read-only che verifica gli acceptance criteria eseguendo i test, senza modificare il codice.
|
||||
mode: primary
|
||||
permission:
|
||||
edit: deny
|
||||
webfetch: deny
|
||||
bash: allow
|
||||
tools:
|
||||
write: false
|
||||
edit: false
|
||||
bash: true
|
||||
---
|
||||
Sei un revisore di codice rigoroso in SOLA LETTURA.
|
||||
Non modificare mai i file: puoi solo leggere il codice ed eseguire comandi
|
||||
di verifica (build, lint, test). Stabilisci se ogni Acceptance Criterion
|
||||
del piano è oggettivamente soddisfatto sul codice attuale.
|
||||
EOF
|
||||
grep -qxF '.opencode/' .git/info/exclude 2>/dev/null || echo '.opencode/' >> .git/info/exclude
|
||||
|
||||
- name: Determina contesto (issue / PR / manuale) e branch di lavoro
|
||||
id: ctx
|
||||
run: |
|
||||
@@ -70,20 +124,15 @@ jobs:
|
||||
API="$GITEA_API_URL/api/v1/repos/$REPO_FULL_NAME"
|
||||
|
||||
if [ "$IS_MANUAL" = "true" ]; then
|
||||
# Esecuzione manuale: nessuna issue/PR di contesto, branch dedicato.
|
||||
IS_PR=false
|
||||
PR_NUMBER=""
|
||||
BRANCH_NAME="opencode-manual-$RUN_NUMBER"
|
||||
elif [ "$IS_PR_EVENT" = "true" ]; then
|
||||
# Commento inline su una review: PR e branch noti dal payload.
|
||||
IS_PR=true
|
||||
PR_NUMBER="$PR_NUMBER_FROM_EVENT"
|
||||
BRANCH_NAME="$PR_HEAD_REF_FROM_EVENT"
|
||||
else
|
||||
# issue_comment: può essere una issue "pura" o un commento su una PR.
|
||||
ISSUE_JSON=$(curl -s -H "Authorization: token $GITEA_TOKEN" "$API/issues/$ISSUE_NUMBER")
|
||||
# NB: l'API Gitea restituisce SEMPRE la chiave "pull_request",
|
||||
# ma vale null per le issue normali: va controllato il VALORE, non la chiave.
|
||||
if [ "$(echo "$ISSUE_JSON" | jq -r '.pull_request // empty')" != "" ]; then
|
||||
IS_PR=true
|
||||
PR_NUMBER="$ISSUE_NUMBER"
|
||||
@@ -96,29 +145,30 @@ jobs:
|
||||
fi
|
||||
fi
|
||||
|
||||
# Rete di sicurezza contro branch vuoti / "null".
|
||||
if [ -z "$BRANCH_NAME" ] || [ "$BRANCH_NAME" = "null" ]; then
|
||||
echo "BRANCH_NAME non valido ('$BRANCH_NAME'): impossibile determinare il contesto. Interrompo."
|
||||
echo "BRANCH_NAME non valido ('$BRANCH_NAME'). Interrompo."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Chiave univoca per il file di piano (branch con '/' -> '-').
|
||||
PLAN_KEY=$(printf '%s' "$BRANCH_NAME" | tr '/' '-')
|
||||
|
||||
echo "is_pr=$IS_PR" >> "$GITHUB_OUTPUT"
|
||||
echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
|
||||
echo "branch_name=$BRANCH_NAME" >> "$GITHUB_OUTPUT"
|
||||
echo "plan_key=$PLAN_KEY" >> "$GITHUB_OUTPUT"
|
||||
|
||||
if [ "$IS_PR" = "true" ]; then
|
||||
# Continua sullo STESSO branch della PR esistente (loop di review).
|
||||
git fetch origin "$BRANCH_NAME"
|
||||
git checkout -B "$BRANCH_NAME" "origin/$BRANCH_NAME"
|
||||
elif git ls-remote --exit-code --heads origin "$BRANCH_NAME" >/dev/null 2>&1; then
|
||||
# Un run precedente ha già creato questo branch: riprendilo.
|
||||
git fetch origin "$BRANCH_NAME"
|
||||
git checkout -B "$BRANCH_NAME" "origin/$BRANCH_NAME"
|
||||
else
|
||||
git checkout -b "$BRANCH_NAME"
|
||||
fi
|
||||
|
||||
- name: Raccogli contesto aggiuntivo (diff + commenti di review, se PR)
|
||||
- name: Raccogli contesto aggiuntivo (diff + commenti, se PR)
|
||||
run: |
|
||||
API="$GITEA_API_URL/api/v1/repos/$REPO_FULL_NAME"
|
||||
: > /tmp/context.txt
|
||||
@@ -136,60 +186,179 @@ jobs:
|
||||
CLEAN_PROMPT=$(printf '%s' "$COMMENT_BODY" | sed -e 's|/opencode||g' -e 's|/oc||g')
|
||||
printf '%s' "$CLEAN_PROMPT" > /tmp/clean_prompt.txt
|
||||
|
||||
- name: Esegui OpenCode
|
||||
env:
|
||||
OPENCODE_ZEN_API_KEY: ${{ secrets.OPENCODE_ZEN_API_KEY }}
|
||||
OPENCODE_API_BASE: https://opencode.ai
|
||||
OPENCODE_MODEL: opencode/big-pickle
|
||||
- name: "Fase 1 — Plan (analisi read-only)"
|
||||
if: steps.ctx.outputs.is_pr != 'true'
|
||||
run: |
|
||||
CLEAN_PROMPT=$(cat /tmp/clean_prompt.txt)
|
||||
CONTEXT=$(cat /tmp/context.txt 2>/dev/null || true)
|
||||
opencode run \
|
||||
--model "$OPENCODE_MODEL" \
|
||||
"Contesto della Issue/PR: $ISSUE_TITLE - $ISSUE_BODY
|
||||
mkdir -p issue_plans
|
||||
PLAN_FILE="issue_plans/${{ steps.ctx.outputs.plan_key }}.md"
|
||||
|
||||
opencode run --agent plan --model "$OPENCODE_MODEL" \
|
||||
"Sei in modalità PLAN (SOLA LETTURA): NON modificare alcun file.
|
||||
Analizza il codebase e la richiesta, poi produci un piano di lavoro in Markdown
|
||||
con questa struttura ESATTA:
|
||||
|
||||
# Piano
|
||||
## Obiettivo
|
||||
## Task
|
||||
(elenco numerato di task atomici; per ciascuno i file coinvolti)
|
||||
## Acceptance Criteria
|
||||
(checklist '- [ ] ...' di criteri oggettivi e verificabili)
|
||||
## Verifica
|
||||
(come testare: comandi da lanciare, cosa controllare)
|
||||
|
||||
Richiesta ($COMMENT_AUTHOR): $CLEAN_PROMPT
|
||||
Contesto: $ISSUE_TITLE - $ISSUE_BODY
|
||||
$CONTEXT
|
||||
|
||||
Richiesta specifica dell'utente ($COMMENT_AUTHOR): $CLEAN_PROMPT
|
||||
Restituisci SOLO il documento Markdown del piano." | tee "$PLAN_FILE"
|
||||
|
||||
Se stai lavorando su una PR già aperta, applica solo le modifiche richieste dal feedback di review, senza riscrivere lavoro già approvato."
|
||||
cp "$PLAN_FILE" /tmp/plan.md
|
||||
git add "$PLAN_FILE"
|
||||
git commit -m "OpenCode: piano di lavoro (${{ steps.ctx.outputs.plan_key }})" || echo "Nessun piano da committare."
|
||||
|
||||
- name: "Fase 2 — Build & Review loop"
|
||||
run: |
|
||||
CLEAN_PROMPT=$(cat /tmp/clean_prompt.txt)
|
||||
CONTEXT=$(cat /tmp/context.txt 2>/dev/null || true)
|
||||
PLAN=""; [ -f /tmp/plan.md ] && PLAN="$(cat /tmp/plan.md)"
|
||||
REVIEW_FEEDBACK="(prima iterazione: nessun feedback)"
|
||||
|
||||
for i in $(seq 1 "$MAX_ITERATIONS"); do
|
||||
echo "::group::Iterazione $i — BUILD"
|
||||
opencode run --agent build --auto --model "$OPENCODE_MODEL" \
|
||||
"Sei in modalità BUILD. Implementa il piano completando TUTTI i task e
|
||||
soddisfacendo TUTTI gli Acceptance Criteria. Applica le modifiche ai file.
|
||||
|
||||
=== PIANO ===
|
||||
${PLAN:-Nessun piano formale. Richiesta: $CLEAN_PROMPT}
|
||||
|
||||
=== CONTESTO (diff/commenti PR, se presente) ===
|
||||
$CONTEXT
|
||||
|
||||
=== FEEDBACK DELLA REVIEW PRECEDENTE (correggi SOLO questi punti) ===
|
||||
$REVIEW_FEEDBACK"
|
||||
echo "::endgroup::"
|
||||
|
||||
echo "::group::Iterazione $i — REVIEW"
|
||||
opencode run --agent reviewer --auto --model "$OPENCODE_MODEL" \
|
||||
"Verifica sul codice ATTUALE se OGNI Acceptance Criterion del piano è
|
||||
soddisfatto. Puoi eseguire build/lint/test ma NON modificare i file.
|
||||
|
||||
=== PIANO ===
|
||||
${PLAN:-Richiesta originale: $CLEAN_PROMPT}
|
||||
|
||||
Scrivi come ULTIMA riga ESATTAMENTE una di queste:
|
||||
- 'VERDICT: PASS' se tutti i criteri sono soddisfatti
|
||||
- 'VERDICT: FAIL' altrimenti, seguita da un elenco puntato dei criteri NON
|
||||
soddisfatti e di cosa manca." | tee /tmp/review.txt
|
||||
echo "::endgroup::"
|
||||
|
||||
if grep -q 'VERDICT: PASS' /tmp/review.txt; then
|
||||
echo "✅ Acceptance criteria soddisfatti all'iterazione $i."
|
||||
exit 0
|
||||
fi
|
||||
REVIEW_FEEDBACK="$(cat /tmp/review.txt)"
|
||||
echo "⚠️ Criteri non ancora soddisfatti: procedo con l'iterazione $((i+1))."
|
||||
done
|
||||
|
||||
echo "Raggiunto il tetto di $MAX_ITERATIONS iterazioni senza PASS completo:"
|
||||
echo "le modifiche parziali verranno comunque pushate per revisione umana."
|
||||
|
||||
- name: Pusha modifiche e apri/aggiorna la PR
|
||||
id: push
|
||||
run: |
|
||||
API="$GITEA_API_URL/api/v1/repos/$REPO_FULL_NAME"
|
||||
BRANCH_NAME="${{ steps.ctx.outputs.branch_name }}"
|
||||
|
||||
if [ -z "$(git status --porcelain)" ]; then
|
||||
echo "Nessuna modifica rilevata da OpenCode."
|
||||
git add .
|
||||
git commit -m "OpenCode (big-pickle): $BRANCH_NAME" || echo "Niente di nuovo da committare oltre al loop."
|
||||
|
||||
if git diff --quiet origin/main..HEAD 2>/dev/null; then
|
||||
echo "Nessuna modifica rispetto a main: niente da pushare."
|
||||
echo "pr_number=" >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
git add .
|
||||
git commit -m "OpenCode (big-pickle): $BRANCH_NAME"
|
||||
git push origin "$BRANCH_NAME"
|
||||
|
||||
# Apri una PR solo se stiamo partendo da zero (issue o run manuale),
|
||||
# non se stiamo già iterando su una PR esistente.
|
||||
if [ "${{ steps.ctx.outputs.is_pr }}" != "true" ]; then
|
||||
TITLE="PR Automatica OpenCode: $BRANCH_NAME"
|
||||
curl -s -X POST "$API/pulls" \
|
||||
if [ "${{ steps.ctx.outputs.is_pr }}" = "true" ]; then
|
||||
PR_NUMBER="${{ steps.ctx.outputs.pr_number }}"
|
||||
else
|
||||
RESP=$(curl -s -X POST "$API/pulls" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"base\":\"main\",\"head\":\"$BRANCH_NAME\",\"title\":\"$TITLE\",\"body\":\"Generata da big-pickle su richiesta di @$COMMENT_AUTHOR.\"}"
|
||||
-d "{\"base\":\"main\",\"head\":\"$BRANCH_NAME\",\"title\":\"PR Automatica OpenCode: $BRANCH_NAME\",\"body\":\"Generata da big-pickle su richiesta di @$COMMENT_AUTHOR. Piano: issue_plans/${{ steps.ctx.outputs.plan_key }}.md\"}")
|
||||
PR_NUMBER=$(echo "$RESP" | jq -r '.number // empty')
|
||||
# Se la PR per questo branch esiste già, recuperane il numero.
|
||||
if [ -z "$PR_NUMBER" ]; then
|
||||
PR_NUMBER=$(curl -s -H "Authorization: token $GITEA_TOKEN" "$API/pulls?state=open&limit=50" \
|
||||
| jq -r --arg b "$BRANCH_NAME" '.[] | select(.head.ref==$b) | .number' | head -n1)
|
||||
fi
|
||||
fi
|
||||
echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Commenta l'esito
|
||||
# Passo finale: la review dell'agente viene postata come REVIEW sulla PR
|
||||
# (event COMMENT: evita i vincoli sul self-approve del proprio branch).
|
||||
- name: Posta la review sulla PR
|
||||
if: always()
|
||||
continue-on-error: true
|
||||
run: |
|
||||
API="$GITEA_API_URL/api/v1/repos/$REPO_FULL_NAME"
|
||||
TARGET="${{ steps.ctx.outputs.pr_number || env.ISSUE_NUMBER }}"
|
||||
# Su esecuzione manuale non c'è una issue/PR di partenza su cui commentare.
|
||||
if [ -z "$TARGET" ]; then
|
||||
echo "Nessun target su cui commentare (probabile run manuale). Salto."
|
||||
PR_NUMBER="${{ steps.push.outputs.pr_number }}"
|
||||
[ -z "$PR_NUMBER" ] && PR_NUMBER="${{ steps.ctx.outputs.pr_number }}"
|
||||
if [ -z "$PR_NUMBER" ] || [ ! -s /tmp/review.txt ]; then
|
||||
echo "Nessuna PR o nessuna review da postare."
|
||||
exit 0
|
||||
fi
|
||||
curl -sS -X POST "$API/issues/$TARGET/comments" \
|
||||
|
||||
# Il verdetto guida lo stato nativo della review.
|
||||
if grep -q 'VERDICT: PASS' /tmp/review.txt; then
|
||||
EVENT="APPROVE"
|
||||
else
|
||||
EVENT="REQUEST_CHANGES"
|
||||
fi
|
||||
|
||||
BODY=$(jq -Rs . < /tmp/review.txt) # encoding JSON-safe del testo review
|
||||
|
||||
post_review() {
|
||||
curl -s -o /tmp/review_resp.json -w '%{http_code}' \
|
||||
-X POST "$API/pulls/$PR_NUMBER/reviews" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"body\":\"🤖 OpenCode ha completato l'elaborazione della richiesta di @$COMMENT_AUTHOR.\"}"
|
||||
-d "{\"body\":$BODY,\"event\":\"$1\"}"
|
||||
}
|
||||
|
||||
CODE=$(post_review "$EVENT")
|
||||
echo "Review '$EVENT' -> HTTP $CODE"
|
||||
|
||||
# Gitea rifiuta APPROVE/REQUEST_CHANGES sulla PR di cui il bot è autore:
|
||||
# in quel caso ripiega su un commento di review (event=COMMENT).
|
||||
if [ "$CODE" -ge 300 ]; then
|
||||
echo "Fallback a event=COMMENT (probabile self-review su PR del bot). Risposta:"
|
||||
cat /tmp/review_resp.json 2>/dev/null || true
|
||||
echo
|
||||
CODE=$(post_review "COMMENT")
|
||||
echo "Review 'COMMENT' -> HTTP $CODE"
|
||||
fi
|
||||
|
||||
- name: Reazione finale 🚀
|
||||
if: success() && steps.react.outputs.path != ''
|
||||
continue-on-error: true
|
||||
run: |
|
||||
API="$GITEA_API_URL/api/v1/repos/$REPO_FULL_NAME"
|
||||
curl -s -X POST "$API/${{ steps.react.outputs.path }}" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"content":"rocket"}' >/dev/null || true
|
||||
|
||||
- name: Reazione in caso di errore 😕
|
||||
if: failure() && steps.react.outputs.path != ''
|
||||
continue-on-error: true
|
||||
run: |
|
||||
API="$GITEA_API_URL/api/v1/repos/$REPO_FULL_NAME"
|
||||
curl -s -X POST "$API/${{ steps.react.outputs.path }}" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"content":"confused"}' >/dev/null || true
|
||||
@@ -0,0 +1,97 @@
|
||||
name: Publish Docker Image
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
proxy_mode:
|
||||
description: 'Proxy mode (nginx o traefik)'
|
||||
required: true
|
||||
default: 'nginx'
|
||||
type: choice
|
||||
options:
|
||||
- nginx
|
||||
- traefik
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
env:
|
||||
IMAGE_NAME: ${{ gitea.repository }}
|
||||
IMAGE_TAG: ${{ gitea.ref_name }}
|
||||
# Registry (default Docker Hub, cambia con un secret se usi un registry privato)
|
||||
REGISTRY: ${{ secrets.DOCKER_REGISTRY || 'docker.io' }}
|
||||
# Modalità proxy
|
||||
PROXY_MODE: ${{ inputs.proxy_mode || 'nginx' }}
|
||||
# Container name sulla VPS
|
||||
CONTAINER_NAME: test-app
|
||||
# Porta host per modalità nginx
|
||||
HOST_PORT: ${{ secrets.HOST_PORT || '8080' }}
|
||||
|
||||
jobs:
|
||||
build-and-publish:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to container registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
|
||||
|
||||
- name: Deploy to VPS via SSH
|
||||
uses: appleboy/ssh-action@v1
|
||||
with:
|
||||
host: ${{ secrets.VPS_HOST }}
|
||||
username: ${{ secrets.VPS_USER }}
|
||||
key: ${{ secrets.VPS_SSH_KEY }}
|
||||
port: ${{ secrets.VPS_PORT || '22' }}
|
||||
envs: IMAGE_NAME,IMAGE_TAG,REGISTRY,PROXY_MODE,CONTAINER_NAME,HOST_PORT
|
||||
script: |
|
||||
set -e
|
||||
|
||||
FULL_IMAGE="$REGISTRY/$IMAGE_NAME:$IMAGE_TAG"
|
||||
|
||||
echo "=== Pull immagine ==="
|
||||
echo "$DOCKER_PASSWORD" | docker login "$REGISTRY" -u "$DOCKER_USERNAME" --password-stdin 2>/dev/null || true
|
||||
docker pull "$FULL_IMAGE"
|
||||
|
||||
echo "=== Ferma e rimuovi container esistente ==="
|
||||
docker stop "$CONTAINER_NAME" 2>/dev/null || true
|
||||
docker rm "$CONTAINER_NAME" 2>/dev/null || true
|
||||
|
||||
echo "=== Avvia container (proxy: $PROXY_MODE) ==="
|
||||
|
||||
if [ "$PROXY_MODE" = "traefik" ]; then
|
||||
docker run -d \
|
||||
--name "$CONTAINER_NAME" \
|
||||
--network traefik \
|
||||
--label "traefik.enable=true" \
|
||||
--label "traefik.http.routers.$CONTAINER_NAME.rule=Host(\`${{ secrets.DOMAIN }}\`)" \
|
||||
--label "traefik.http.services.$CONTAINER_NAME.loadbalancer.server.port=80" \
|
||||
"$FULL_IMAGE"
|
||||
else
|
||||
docker run -d \
|
||||
--name "$CONTAINER_NAME" \
|
||||
-p "$HOST_PORT:80" \
|
||||
"$FULL_IMAGE"
|
||||
fi
|
||||
|
||||
echo "=== Pulizia ==="
|
||||
docker image prune -f
|
||||
|
||||
echo "=== Deploy completato ==="
|
||||
echo "Immagine: $FULL_IMAGE"
|
||||
echo "Proxy: $PROXY_MODE"
|
||||
@@ -0,0 +1,8 @@
|
||||
FROM nginx:stable-alpine
|
||||
|
||||
COPY index.html /usr/share/nginx/html/index.html
|
||||
COPY contatti.html /usr/share/nginx/html/contatti.html
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
@@ -3,3 +3,45 @@
|
||||
Questo repository è un test per verificare il funzionamento delle **Actions** e dell'**automazione agentica** collegata a eventi su Gitea.
|
||||
|
||||
Lo scopo è sperimentare l'esecuzione automatica di workflow in risposta a eventi come push, pull request e altri trigger, utilizzando agenti AI per operazioni di review, merge e gestione del repository.
|
||||
|
||||
## Workflow: `Gitea Actions Demo` (`.gitea/workflows/demo.yml`)
|
||||
|
||||
Workflow dimostrativo che si attiva ad ogni **push** su qualsiasi branch. Esegue su un container `node:20-alpine` e stampa una serie di messaggi informativi via `echo` per illustrare il funzionamento base di Gitea Actions:
|
||||
- Mostra l'evento che ha scatenato il workflow (`gitea.event_name`)
|
||||
- Mostra il runner OS e il branch/repository coinvolto
|
||||
- Fa il checkout del codice tramite `actions/checkout@v4`
|
||||
- Elenca i file nella workspace
|
||||
- Comunica lo stato finale del job (`job.status`)
|
||||
|
||||
Non esegue operazioni di modifica o deploy: è puramente a scopo educativo/dimostrativo.
|
||||
|
||||
## Workflow: `OpenCode Gitea Integration` (`.gitea/workflows/opencode.yml`)
|
||||
|
||||
Workflow di automazione agentica che integra **OpenCode** (agente AI) con Gitea. Si attiva su quattro eventi:
|
||||
|
||||
| Evento | Descrizione |
|
||||
|---|---|
|
||||
| `issues: [opened]` | Apertura di una nuova issue |
|
||||
| `issue_comment: [created]` | Nuovo commento su una issue |
|
||||
| `pull_request_review_comment: [created]` | Nuovo commento su una PR (review) |
|
||||
| `workflow_dispatch` | Esecuzione manuale tramite UI / API |
|
||||
|
||||
Il workflow procede solo se il corpo della issue/commento contiene `/oc` o `/opencode` (oppure se è un'esecuzione manuale). L'autore deve essere tra gli utenti autorizzati (`maria`, `nicola`), altrimenti il job viene interrotto.
|
||||
|
||||
### Schema di esecuzione
|
||||
|
||||
1. **Autorizzazione** — Verifica che l'utente sia nella whitelist.
|
||||
2. **Reazione 👀** — Aggiunge una reazione "eyes" al commento/issue di trigger (feedback visivo immediato senza generare nuovi eventi).
|
||||
3. **Checkout** — Clona il repository con storia completa (`fetch-depth: 0`).
|
||||
4. **Installazione OpenCode** — Scarica e installa la CLI di OpenCode via `curl | bash`.
|
||||
5. **Determinazione contesto** — Capisce se si è in una issue, in una PR o in esecuzione manuale:
|
||||
- **PR**: fa il fetch e checkout del branch della PR.
|
||||
- **Issue**: crea un nuovo branch `opencode-issue-<N>` a partire da `main`.
|
||||
- **Manuale**: crea un branch `opencode-manual-<run_number>`.
|
||||
6. **Raccolta contesto** — Se si tratta di una PR, scarica il **diff** e i **commenti** recenti per fornire contesto all'agente.
|
||||
7. **Pulizia comando** — Rimuove `/oc` o `/opencode` dal prompt, lasciando solo le istruzioni utente.
|
||||
8. **Esecuzione OpenCode** — Lancia l'agente AI con modello `opencode/big-pickle`, passando il contesto raccolto e la richiesta dell'utente. L'agente può leggere, modificare e creare file nel repository.
|
||||
9. **Push e PR** — Se ci sono modifiche, le committa e le pusha sul branch. Se si sta lavorando su una issue (non PR), apre automaticamente una **Pull Request** verso `main`.
|
||||
10. **Reazione finale** — Aggiunge una reazione 🚀 in caso di successo o 😕 in caso di fallimento.
|
||||
|
||||
Il workflow è progettato per evitare auto-trigger: le reazioni alle issue/commenti non generano eventi `issue_comment`, e il workflow non scrive mai commenti (solo reazioni), prevenendo loop infiniti.
|
||||
+160
@@ -0,0 +1,160 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Contatti</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: rgba(255, 255, 255, 0.95);
|
||||
backdrop-filter: blur(10px);
|
||||
border-radius: 24px;
|
||||
padding: 3rem 3.5rem;
|
||||
max-width: 480px;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
box-shadow:
|
||||
0 20px 60px rgba(0, 0, 0, 0.15),
|
||||
0 1px 3px rgba(0, 0, 0, 0.08);
|
||||
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
||||
}
|
||||
|
||||
.card:hover {
|
||||
transform: translateY(-4px);
|
||||
box-shadow:
|
||||
0 30px 80px rgba(0, 0, 0, 0.2),
|
||||
0 1px 3px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.icon {
|
||||
width: 72px;
|
||||
height: 72px;
|
||||
margin: 0 auto 1.5rem;
|
||||
background: linear-gradient(135deg, #667eea, #764ba2);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 1.75rem;
|
||||
font-weight: 700;
|
||||
color: #1a1a2e;
|
||||
margin-bottom: 0.75rem;
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
|
||||
.divider {
|
||||
width: 48px;
|
||||
height: 4px;
|
||||
margin: 0 auto 2rem;
|
||||
background: linear-gradient(90deg, #667eea, #764ba2);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.info-list {
|
||||
list-style: none;
|
||||
text-align: left;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.info-list li {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 0.75rem 0;
|
||||
border-bottom: 1px solid rgba(102, 126, 234, 0.15);
|
||||
color: #555;
|
||||
font-size: 0.95rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.info-list li:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.info-list .info-icon {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
min-width: 36px;
|
||||
background: linear-gradient(135deg, #667eea, #764ba2);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.home-link {
|
||||
display: inline-block;
|
||||
padding: 0.6rem 1.6rem;
|
||||
background: linear-gradient(135deg, #667eea, #764ba2);
|
||||
color: #fff;
|
||||
border-radius: 100px;
|
||||
font-size: 0.85rem;
|
||||
font-weight: 600;
|
||||
text-decoration: none;
|
||||
letter-spacing: 0.02em;
|
||||
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
||||
}
|
||||
|
||||
.home-link:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 8px 24px rgba(102, 126, 234, 0.4);
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.card {
|
||||
padding: 2rem 1.5rem;
|
||||
border-radius: 16px;
|
||||
}
|
||||
h1 {
|
||||
font-size: 1.4rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="card">
|
||||
<div class="icon">📞</div>
|
||||
<div class="divider"></div>
|
||||
<h1>Contatti</h1>
|
||||
<ul class="info-list">
|
||||
<li>
|
||||
<span class="info-icon">✉️</span>
|
||||
<span>info@esempio.it</span>
|
||||
</li>
|
||||
<li>
|
||||
<span class="info-icon">📱</span>
|
||||
<span>+39 012 345 6789</span>
|
||||
</li>
|
||||
<li>
|
||||
<span class="info-icon">📍</span>
|
||||
<span>Via Roma 1, 00100 Roma (RM)</span>
|
||||
</li>
|
||||
</ul>
|
||||
<a href="index.html" class="home-link">Torna alla Home</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -109,6 +109,7 @@
|
||||
<h1>Pagina di prova</h1>
|
||||
<p>Questa è una pagina HTML di test realizzata con cura per un aspetto più elegante e moderno.</p>
|
||||
<span class="badge">HTML · CSS · Design</span>
|
||||
<a href="contatti.html" class="badge" style="margin-top: 1rem; text-decoration: none; display: block; width: fit-content; margin-left: auto; margin-right: auto; cursor: pointer;">Contatti</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# Piano
|
||||
|
||||
## Obiettivo
|
||||
Creare una pagina di contatti (`contatti.html`) coerente con il design esistente (glassmorphism, gradienti viola, font Inter), collegata alla pagina principale tramite un link di navigazione.
|
||||
|
||||
## Task
|
||||
1. **Creare `contatti.html`** — Nuova pagina HTML con stessa struttura CSS di `index.html` (gradienti, card glassmorphism, responsive). Contenuto: icona contatto, titolo "Contatti", sezione con info (email, telefono, indirizzo), link/bottone per tornare alla home.
|
||||
- File: `contatti.html` (nuovo)
|
||||
|
||||
2. **Aggiungere navigazione in `index.html`** — Inserire un link/bottone nella card che punta a `contatti.html`, mantenendo lo stile badge esistente.
|
||||
- File: `index.html`
|
||||
|
||||
3. **Aggiornare `Dockerfile`** — Aggiungere una riga `COPY` per servire anche `contatti.html` via nginx.
|
||||
- File: `Dockerfile`
|
||||
|
||||
## Acceptance Criteria
|
||||
- [ ] `contatti.html` esiste e contiene informazioni di contatto (email, telefono, indirizzo)
|
||||
- [ ] La pagina di contatti usa lo stesso design system (gradienti `#667eea`→`#764ba2`, card glassmorphism, font Inter, `border-radius: 24px`)
|
||||
- [ ] `contatti.html` è responsive (media query `max-width: 480px`)
|
||||
- [ ] `index.html` contiene un link visibile che naviga a `contatti.html`
|
||||
- [ ] `contatti.html` contiene un link per tornare alla home (`index.html`)
|
||||
- [ ] Il `Dockerfile` copia entrambi i file HTML nella directory nginx
|
||||
- [ ] La pagina è in italiano (`lang="it"`)
|
||||
|
||||
## Verifica
|
||||
- Aprire `index.html` nel browser e verificare che il link alla pagina contatti sia visibile e cliccabile
|
||||
- Verificare che `contatti.html` si apre correttamente con le info di contatto
|
||||
- Verificare che il link "torna alla home" in `contatti.html` funziona
|
||||
- Verificare il layout responsive ridimensionando la finestra sotto 480px
|
||||
- Eseguire `docker build -t test-app .` per confermare che il build Docker riesce senza errori
|
||||
Reference in New Issue
Block a user