Skip to content

fix(ci): early-exit do types:gen no CI sem SUPABASE_PROJECT_ID#122

Merged
adm01-debug merged 1 commit into
mainfrom
fix/prebuild-ci-types-gen
May 9, 2026
Merged

fix(ci): early-exit do types:gen no CI sem SUPABASE_PROJECT_ID#122
adm01-debug merged 1 commit into
mainfrom
fix/prebuild-ci-types-gen

Conversation

@adm01-debug
Copy link
Copy Markdown
Owner

@adm01-debug adm01-debug commented May 9, 2026

🎯 Objetivo

Resolver o bug pré-existente do prebuild que vinha falhando em bun run build no CI test step, há vários PRs (todos os runs em main desde antes do #114). Padrão atual era contornar via --admin --squash.

🐛 Bug

$ bun run prebuild
$ bun run types:gen && bun run scripts/generate-component-registry.ts
$ bash scripts/validate-supabase-types.sh
⚠️ SUPABASE_PROJECT_ID not set. Type generation might fail if not using local Supabase.
🔄 Generating Supabase types...
WARN: no seed files matched pattern: supabase/seed.sql
Missing required field in config: project_id
error: script "types:gen" exited with code 1
error: script "prebuild" exited with code 1

🔍 Causa raiz

No validate-supabase-types.sh, o script tem 3 branches:

  1. PROJECT_ID + ACCESS_TOKEN setados → gen via --project-id (Supabase Cloud)
  2. -d supabase + docker ps → gen via --local (Supabase Cloud local)
  3. Else → skip + cp existing (CI sem credentials)

No GitHub Actions runner:

  • [ -d "supabase" ] é true (pasta existe)
  • docker ps &> /dev/null é true (runner tem docker daemon)

Cai no branch 2 → tenta supabase gen types typescript --local → falha porque não há instância Supabase rodando localmente (supabase start nunca foi chamado, config.toml não tem project_id — intencional desde a Onda 6 PR #115 do setup self-hosted).

✅ Fix (cirúrgico)

Early-exit no script quando CI=true e SUPABASE_PROJECT_ID não está setada.

Faz sentido porque:

  • O projeto é self-hosted (supabase/config.toml documenta isso desde a Onda 6)
  • types.ts é gerado localmente via supabase gen types typescript --db-url $SUPABASE_DB_URL e commitado (468KB, atualizado)
  • CI deve confiar no types.ts commitado, não tentar regenerar
# Early-exit for CI without remote credentials (self-hosted setup).
if [ "${CI:-}" = "true" ] && [ -z "${SUPABASE_PROJECT_ID:-}" ]; then
  if [ "$CHECK_MODE" = true ]; then
    # check-mode: ensure file is present and non-empty
    if [ -f "$TYPES_FILE" ] && [ -s "$TYPES_FILE" ]; then
      echo "✅ CI without SUPABASE_PROJECT_ID — committed file present"
      exit 0
    fi
    ...
  else
    # gen-mode (prebuild): trust committed file, skip generation
    if [ -f "$TYPES_FILE" ]; then
      echo "ℹ️  CI without SUPABASE_PROJECT_ID — using committed file"
      exit 0
    fi
    ...
  fi
fi

🛡️ Validações locais

Cenário Comportamento esperado Resultado
CI=true sem PROJECT_ID (cenário do bug) Early-exit 0, usa types.ts commitado
CI=true --check --summary (check-mode) Early-exit 0, valida file presente
Dev local sem CI setada Fluxo antigo preservado
CI=true bun run prebuild (full) Exit 0 + component registry gerado

📝 Diff

scripts/validate-supabase-types.sh | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)

Apenas adição de bloco no script bash. Zero impacto em arquivos TS, build, ou design system.

🎯 Resolve

1ª das 3 pendências mapeadas após Onda 8 fechada (#121):

  • Bug prebuild (SUPABASE_PROJECT_ID) ← este PR
  • ⏳ Falhas em whatsapp_reconcile_dispatch (pgsodium) — legado Onda 7
  • ⏳ Onda 9 (1.289 ESLint warnings)

🤖 Generated with Claude Code

Summary by CodeRabbit

Notas de Lançamento

  • Chores
    • Melhorias na validação de tipos durante o processo de integração contínua para garantir compilações mais confiáveis e rápidas em diferentes cenários de ambiente.

Review Change Stack

Bug pré-existente que vinha quebrando o CI test step (Build) há vários PRs:

  $ bash scripts/validate-supabase-types.sh
  ⚠️ SUPABASE_PROJECT_ID not set
  🔄 Generating Supabase types...
  WARN: no seed files matched pattern: supabase/seed.sql
  Missing required field in config: project_id
  error: script "types:gen" exited with code 1

Causa raiz: em CI, sem SUPABASE_PROJECT_ID setada, o script caía no branch
'elif [ -d supabase ] && docker ps' (pasta supabase/ existe + GitHub Actions
runner tem docker), tentando 'supabase gen types typescript --local'. Mas
--local exige uma instância Supabase rodando localmente (com 'supabase start')
que não existe no CI runner. Resultado: falha 'Missing required field in
config: project_id' e build aborted.

Fix: early-exit no script quando CI=true e SUPABASE_PROJECT_ID não está setada.
Confia no types.ts commitado (gerado localmente via --db-url, source-of-truth
do projeto self-hosted). Padrão coerente com supabase/config.toml que já
documenta o setup self-hosted desde a Onda 6 (PR #115).

Comportamentos validados localmente:
  ✅ CI=true sem PROJECT_ID (cenário do bug)     → exit 0 (usa types.ts commitado)
  ✅ CI=true --check --summary (check-mode)       → exit 0 (valida arquivo presente)
  ✅ Dev local (CI unset)                         → fluxo antigo preservado
  ✅ CI=true bun run prebuild (full)              → exit 0 + component registry OK

Resolve a 1ª das 3 pendências mapeadas após Onda 8 fechada.

Refs:
- Onda 6 PR #115 (config.toml self-hosted): 0f10ab4
- Onda 8 PR #121 (lint passing): 21fba6f
- Falhas em main desde antes do PR #114 (todos os builds falhavam por isso)
Copilot AI review requested due to automatic review settings May 9, 2026 18:34
@vercel
Copy link
Copy Markdown

vercel Bot commented May 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
zapp-web Ready Ready Preview, Comment May 9, 2026 6:35pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 9, 2026

Walkthrough

O script de validação de tipos Supabase agora inclui um branch antecipado em CI quando credenciais não estão disponíveis. Sem SUPABASE_PROJECT_ID em CI, trata o arquivo de tipos comprometido como canônico, validando existência ou conteúdo conforme o modo --check.

Alterações

Lógica de Saída Antecipada em CI

Layer / File(s) Resumo
Validação em CI sem Credenciais
scripts/validate-supabase-types.sh
Novo condicional que detecta CI=true sem SUPABASE_PROJECT_ID e valida o arquivo src/integrations/supabase/types.ts como fonte de verdade. Com --check, exige existência e conteúdo não-vazio; sem --check, apenas verifica existência e sai com sucesso.

Estimativa de Esforço de Review

🎯 2 (Simples) | ⏱️ ~8 minutos

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed O título refere-se ao fix implementado (early-exit em CI sem SUPABASE_PROJECT_ID), porém está em português incorreto/ambíguo ('do types:gen no CI sem' lê-se confuso). Descreve corretamente a mudança principal mas com redação confusa.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/prebuild-ci-types-gen

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/validate-supabase-types.sh`:
- Around line 58-64: The gen-mode early-exit currently uses a plain -f check
against TYPES_FILE which lets an empty/corrupt types.ts pass; change the
condition to test both existence and non-empty content (use -s "$TYPES_FILE") so
the CI prebuild path only succeeds when TYPES_FILE has size >0. Update the if
branch that checks "$TYPES_FILE" (the gen-mode block) to use -s instead of -f
and keep the same success/failure echo and exit behavior so downstream steps
won’t be masked by an empty file.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a1f21c33-3e3c-4ea9-8fe3-f4ee592479d0

📥 Commits

Reviewing files that changed from the base of the PR and between 21fba6f and 01c0030.

📒 Files selected for processing (1)
  • scripts/validate-supabase-types.sh

Comment on lines +58 to +64
# gen-mode (prebuild): trust committed file, skip generation
if [ -f "$TYPES_FILE" ]; then
echo "ℹ️ CI without SUPABASE_PROJECT_ID — using committed $TYPES_FILE (self-hosted setup, types are committed)."
exit 0
else
echo "❌ Error: $TYPES_FILE not found in CI and no SUPABASE_PROJECT_ID set."
exit 1
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Evite aceitar types.ts vazio no early-exit de gen-mode

No fluxo de prebuild em CI, o bloco de Line 59 valida só -f. Se types.ts existir mas estiver vazio/corrompido, o script sai com sucesso e pode esconder problema até etapas posteriores. Alinhe com o check-mode exigindo também -s.

Patch sugerido
-    if [ -f "$TYPES_FILE" ]; then
+    if [ -f "$TYPES_FILE" ] && [ -s "$TYPES_FILE" ]; then
       echo "ℹ️  CI without SUPABASE_PROJECT_ID — using committed $TYPES_FILE (self-hosted setup, types are committed)."
       exit 0
     else
-      echo "❌ Error: $TYPES_FILE not found in CI and no SUPABASE_PROJECT_ID set."
+      echo "❌ Error: $TYPES_FILE missing or empty in CI and no SUPABASE_PROJECT_ID set."
       exit 1
     fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# gen-mode (prebuild): trust committed file, skip generation
if [ -f "$TYPES_FILE" ]; then
echo "ℹ️ CI without SUPABASE_PROJECT_ID — using committed $TYPES_FILE (self-hosted setup, types are committed)."
exit 0
else
echo "❌ Error: $TYPES_FILE not found in CI and no SUPABASE_PROJECT_ID set."
exit 1
# gen-mode (prebuild): trust committed file, skip generation
if [ -f "$TYPES_FILE" ] && [ -s "$TYPES_FILE" ]; then
echo "ℹ️ CI without SUPABASE_PROJECT_ID — using committed $TYPES_FILE (self-hosted setup, types are committed)."
exit 0
else
echo "❌ Error: $TYPES_FILE missing or empty in CI and no SUPABASE_PROJECT_ID set."
exit 1
fi
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/validate-supabase-types.sh` around lines 58 - 64, The gen-mode
early-exit currently uses a plain -f check against TYPES_FILE which lets an
empty/corrupt types.ts pass; change the condition to test both existence and
non-empty content (use -s "$TYPES_FILE") so the CI prebuild path only succeeds
when TYPES_FILE has size >0. Update the if branch that checks "$TYPES_FILE" (the
gen-mode block) to use -s instead of -f and keep the same success/failure echo
and exit behavior so downstream steps won’t be masked by an empty file.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a CI failure in the prebuild pipeline by preventing scripts/validate-supabase-types.sh from attempting local Supabase type generation on CI runners when SUPABASE_PROJECT_ID isn’t configured (self-hosted setup), and instead trusting the committed src/integrations/supabase/types.ts.

Changes:

  • Add an early-exit branch for CI=true + missing SUPABASE_PROJECT_ID, skipping type generation.
  • In --check mode on CI, validate that the committed types file exists and is non-empty before exiting successfully.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +59 to +63
if [ -f "$TYPES_FILE" ]; then
echo "ℹ️ CI without SUPABASE_PROJECT_ID — using committed $TYPES_FILE (self-hosted setup, types are committed)."
exit 0
else
echo "❌ Error: $TYPES_FILE not found in CI and no SUPABASE_PROJECT_ID set."
Comment on lines +59 to +63
if [ -f "$TYPES_FILE" ]; then
echo "ℹ️ CI without SUPABASE_PROJECT_ID — using committed $TYPES_FILE (self-hosted setup, types are committed)."
exit 0
else
echo "❌ Error: $TYPES_FILE not found in CI and no SUPABASE_PROJECT_ID set."
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if [ -f "$TYPES_FILE" ]; then
echo "ℹ️ CI without SUPABASE_PROJECT_ID — using committed $TYPES_FILE (self-hosted setup, types are committed)."
exit 0
else
echo "❌ Error: $TYPES_FILE not found in CI and no SUPABASE_PROJECT_ID set."
if [ -f "$TYPES_FILE" ] && [ -s "$TYPES_FILE" ]; then
echo "ℹ️ CI without SUPABASE_PROJECT_ID — using committed $TYPES_FILE (self-hosted setup, types are committed)."
exit 0
else
echo "❌ Error: $TYPES_FILE not found or empty in CI and no SUPABASE_PROJECT_ID set."

GEN_MODE in validate-supabase-types.sh only checks if file exists, not if it's non-empty, allowing empty types.ts to be accepted during CI prebuild

Fix on Vercel

@adm01-debug
Copy link
Copy Markdown
Owner Author

🔍 Descoberta importante: este PR expôs SEGUNDO bug pré-existente

Após o fix do prebuild, o CI test agora avança até o step Vitest (Unit & Fuzz), onde falha com:

SyntaxError: The requested module 'vitest/node' does not provide an export named 'BaseCoverageProvider'
  ❯ loadProvider node_modules/@vitest/coverage-v8/dist/load-provider-CdgAx3rL.js:4:33

Causa raiz: version mismatch entre vitest@4.0.18 e @vitest/coverage-v8@4.1.5 (peer-dep estrita).

Tentei alinhar localmente (bun add -d vitest@^4.1.5): o erro BaseCoverageProvider desapareceu, mas expôs mais 1 camada de cebola:

Test Files  95 failed | 6 passed (101)
Tests       10 failed | 50 passed (60)

95 test files com erros (provavelmente import/setup/snapshot drift acumulado).

Decisão: PR mantido cirúrgico

Revertido o update do Vitest. Este PR fica APENAS com o fix do prebuild (1 arquivo, 26 linhas).

Próximas pendências mapeadas (atualizadas)

  • Bug prebuild (SUPABASE_PROJECT_ID) — este PR
  • 🆕 Vitest version mismatch + 95 test files broken ← nova pendência descoberta aqui
  • ⏳ Falhas em whatsapp_reconcile_dispatch (pgsodium) — legado Onda 7
  • ⏳ Onda 9 (1.289 ESLint warnings)

Status do CI test após este PR

CI test ainda red mas avançou 2 etapas.

@adm01-debug adm01-debug merged commit 2c80984 into main May 9, 2026
14 of 15 checks passed
@adm01-debug adm01-debug deleted the fix/prebuild-ci-types-gen branch May 9, 2026 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants