-
Notifications
You must be signed in to change notification settings - Fork 0
322 lines (279 loc) · 11.4 KB
/
structure-analysis.yml
File metadata and controls
322 lines (279 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
name: "Análise de Estrutura do Projeto"
on:
push:
branches: [main, develop]
paths:
- "app/**"
pull_request:
branches: [main, develop]
paths:
- "app/**"
schedule:
- cron: "0 8 * * 1" # toda segunda às 8h UTC
workflow_dispatch:
permissions:
contents: read
issues: write
pull-requests: write
jobs:
analyze-structure:
name: Análise de Estrutura
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Verificar estrutura esperada
id: structure
run: |
WARNINGS=""
ERRORS=""
INFO=""
echo "🔍 Analisando estrutura do projeto CodeFocus..."
# --- Verificar diretórios obrigatórios (Next.js) ---
REQUIRED_DIRS=(
"app/components"
"app/pages"
"app/pages/api"
"app/lib"
"app/context"
"app/hooks"
"app/utils"
"app/public"
"app/supabase"
)
for dir in "${REQUIRED_DIRS[@]}"; do
if [ ! -d "$dir" ]; then
WARNINGS+="⚠️ Diretório ausente: \`$dir\`\n"
fi
done
# --- Verificar arquivos críticos (Next.js) ---
REQUIRED_FILES=(
"app/package.json"
"app/next.config.js"
"app/pages/_app.js"
"app/pages/index.js"
)
for file in "${REQUIRED_FILES[@]}"; do
if [ ! -f "$file" ]; then
ERRORS+="❌ Arquivo crítico ausente: \`$file\`\n"
fi
done
# --- Verificar arquivos de config na raiz ---
ROOT_FILES=(".gitignore" "README.md")
for file in "${ROOT_FILES[@]}"; do
if [ ! -f "$file" ]; then
WARNINGS+="⚠️ Arquivo recomendado ausente na raiz: \`$file\`\n"
fi
done
# --- Contar arquivos por tipo ---
JSX_COUNT=$(find app -name "*.jsx" 2>/dev/null | wc -l)
JS_COUNT=$(find app -name "*.js" 2>/dev/null | wc -l)
CSS_COUNT=$(find app -name "*.css" 2>/dev/null | wc -l)
SQL_COUNT=$(find app/supabase -name "*.sql" 2>/dev/null | wc -l)
INFO+="### 📊 Métricas do Projeto\n\n"
INFO+="| Tipo | Quantidade |\n"
INFO+="|------|------------|\n"
INFO+="| Componentes (.jsx) | $JSX_COUNT |\n"
INFO+="| JavaScript (.js) | $JS_COUNT |\n"
INFO+="| CSS (.css) | $CSS_COUNT |\n"
INFO+="| Migrations SQL | $SQL_COUNT |\n\n"
# --- Verificar arquivos grandes (>300 linhas) ---
LARGE_FILES=""
while IFS= read -r file; do
if [ -f "$file" ]; then
LINES=$(wc -l < "$file")
if [ "$LINES" -gt 300 ]; then
LARGE_FILES+="⚠️ \`$file\` — $LINES linhas (considerar dividir)\n"
fi
fi
done < <(find app -name "*.jsx" -o -name "*.js" 2>/dev/null)
if [ -n "$LARGE_FILES" ]; then
WARNINGS+="\n### 📏 Arquivos Grandes (>300 linhas)\n\n$LARGE_FILES\n"
fi
# --- Verificar se .env está no repo ---
if [ -f "app/.env" ]; then
ERRORS+="❌ **SEGURANÇA:** \`app/.env\` está no repositório! Adicione ao .gitignore\n"
fi
if [ -f "app/.env.local" ]; then
ERRORS+="❌ **SEGURANÇA:** \`app/.env.local\` está no repositório! Adicione ao .gitignore\n"
fi
if [ -f ".env" ]; then
ERRORS+="❌ **SEGURANÇA:** \`.env\` está no repositório! Adicione ao .gitignore\n"
fi
# --- Verificar dependências esperadas ---
if [ -f "app/package.json" ]; then
HAS_SUPABASE=$(grep -c "supabase" app/package.json || true)
HAS_NEXT=$(grep -c "\"next\"" app/package.json || true)
HAS_TAILWIND=$(grep -c "tailwindcss" app/package.json || true)
if [ "$HAS_SUPABASE" -eq 0 ]; then
WARNINGS+="⚠️ \`@supabase/supabase-js\` não encontrado no package.json\n"
fi
if [ "$HAS_NEXT" -eq 0 ]; then
WARNINGS+="⚠️ \`next\` não encontrado no package.json\n"
fi
if [ "$HAS_TAILWIND" -eq 0 ]; then
WARNINGS+="⚠️ \`tailwindcss\` não encontrado no package.json\n"
fi
fi
# --- Verificar estrutura de migrations ---
if [ -d "app/supabase/migrations" ]; then
MIGRATION_COUNT=$(ls app/supabase/migrations/*.sql 2>/dev/null | wc -l)
INFO+="### 🗃️ Migrations Supabase\n\n"
if [ "$MIGRATION_COUNT" -gt 0 ]; then
INFO+="| Migration | Arquivo |\n"
INFO+="|-----------|----------|\n"
for f in app/supabase/migrations/*.sql; do
[ -f "$f" ] || continue
NAME=$(basename "$f")
INFO+="| ✅ | \`$NAME\` |\n"
done
INFO+="\n"
else
WARNINGS+="⚠️ Nenhuma migration SQL encontrada em \`app/supabase/migrations/\`\n"
fi
fi
# --- Verificar componentes esperados do CodeFocus ---
EXPECTED_COMPONENTS=("Timer" "Dashboard" "SettingsScreen" "LoginScreen" "RegisterScreen" "Navigation")
MISSING_COMPONENTS=""
for comp in "${EXPECTED_COMPONENTS[@]}"; do
if [ ! -f "app/components/${comp}.jsx" ] && [ ! -f "app/components/${comp}.js" ]; then
MISSING_COMPONENTS+="⚠️ Componente não implementado: \`${comp}\`\n"
fi
done
if [ -n "$MISSING_COMPONENTS" ]; then
WARNINGS+="\n### 🧩 Componentes Esperados\n\n$MISSING_COMPONENTS\n"
fi
# --- Verificar hooks esperados ---
EXPECTED_HOOKS=("useKeyboardShortcuts")
MISSING_HOOKS=""
for hook in "${EXPECTED_HOOKS[@]}"; do
if [ ! -f "app/hooks/${hook}.js" ] && [ ! -f "app/hooks/${hook}.jsx" ]; then
MISSING_HOOKS+="⚠️ Hook não implementado: \`${hook}\`\n"
fi
done
if [ -n "$MISSING_HOOKS" ]; then
WARNINGS+="\n### 🪝 Hooks Esperados\n\n$MISSING_HOOKS\n"
fi
# --- Verificar API routes esperadas ---
EXPECTED_API=("auth/login" "auth/register" "cycles/index" "settings/index")
MISSING_API=""
for api in "${EXPECTED_API[@]}"; do
if [ ! -f "app/pages/api/${api}.js" ]; then
MISSING_API+="⚠️ API route não implementada: \`/api/${api}\`\n"
fi
done
if [ -n "$MISSING_API" ]; then
WARNINGS+="\n### 🔌 API Routes Esperadas\n\n$MISSING_API\n"
fi
# --- Montar resultado final ---
HAS_ERRORS="false"
if [ -n "$ERRORS" ]; then
HAS_ERRORS="true"
fi
HAS_WARNINGS="false"
if [ -n "$WARNINGS" ]; then
HAS_WARNINGS="true"
fi
echo "has_errors=$HAS_ERRORS" >> $GITHUB_OUTPUT
echo "has_warnings=$HAS_WARNINGS" >> $GITHUB_OUTPUT
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
BODY="## 🏗️ Análise de Estrutura — CodeFocus\n\n"
BODY+="**Branch:** \`${{ github.ref_name }}\`\n"
BODY+="**Data:** $(date '+%Y-%m-%d %H:%M UTC')\n\n"
BODY+="---\n\n"
BODY+="$INFO"
if [ -n "$ERRORS" ]; then
BODY+="### ❌ Erros Críticos\n\n$ERRORS\n"
fi
if [ -n "$WARNINGS" ]; then
BODY+="### ⚠️ Avisos e Melhorias\n\n$WARNINGS\n"
fi
if [ -z "$ERRORS" ] && [ -z "$WARNINGS" ]; then
BODY+="### ✅ Tudo OK!\n\nA estrutura do projeto está alinhada com a arquitetura definida.\n"
fi
BODY+="\n---\n"
BODY+="*Análise automática baseada na estrutura do CodeFocus*"
echo "body<<$EOF" >> $GITHUB_OUTPUT
echo -e "$BODY" >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
- name: Criar/Atualizar Issue de Estrutura
if: (steps.structure.outputs.has_errors == 'true' || steps.structure.outputs.has_warnings == 'true') && github.event_name != 'pull_request'
env:
STRUCTURE_BODY: ${{ toJSON(steps.structure.outputs.body) }}
uses: actions/github-script@v7
with:
script: |
const body = JSON.parse(process.env.STRUCTURE_BODY);
const existingIssues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
labels: 'structure,ci-automated'
});
const title = '🏗️ Análise de Estrutura — Pendências Detectadas';
const structureIssue = existingIssues.data.find(
i => i.title.includes('Análise de Estrutura')
);
if (structureIssue) {
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: structureIssue.number,
body
});
console.log(`Issue #${structureIssue.number} atualizada`);
} else {
const issue = await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title,
body,
labels: ['structure', 'ci-automated']
});
console.log(`Issue #${issue.data.number} criada`);
}
- name: Comentar no PR
if: github.event_name == 'pull_request'
env:
STRUCTURE_BODY: ${{ toJSON(steps.structure.outputs.body) }}
uses: actions/github-script@v7
with:
script: |
const body = JSON.parse(process.env.STRUCTURE_BODY);
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body
});
- name: Fechar issue se tudo OK
if: steps.structure.outputs.has_errors == 'false' && steps.structure.outputs.has_warnings == 'false' && github.event_name != 'pull_request'
uses: actions/github-script@v7
with:
script: |
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
labels: 'structure,ci-automated'
});
for (const issue of issues.data) {
if (issue.title.includes('Análise de Estrutura')) {
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed'
});
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: '✅ **Estrutura OK!** Todas as pendências foram resolvidas.'
});
}
}
- name: Resumo
run: |
echo "📋 Análise de estrutura concluída"
echo "Erros: ${{ steps.structure.outputs.has_errors }}"
echo "Avisos: ${{ steps.structure.outputs.has_warnings }}"