# .github/workflows/transparency-check.yml # ========================================= # Skill: lgpd-compliance (Parte 3) # # Valida em todo PR que: # 1. Não há campo no schema sem anotação @pii (em tabela @contains_pii) # 2. Toda @finalidade=X está em transparencia/finalidades.yaml # 3. Toda @compartilha=X está em transparencia/terceiros.yaml # 4. inventario.yaml está em dia com o código (sem drift) # 5. Se PR mexe em schema, inventario.yaml foi bumped na mesma PR # # Posta comentário no PR mostrando o diff do inventário público. name: Transparency Check on: pull_request: branches: [main, master, development] jobs: transparency: name: Verifica inventário de privacidade runs-on: ubuntu-latest services: postgres: image: postgres:16 env: POSTGRES_PASSWORD: postgres POSTGRES_DB: app_test ports: - 5432:5432 options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 # pra diff - name: Setup Python uses: actions/setup-python@v5 with: python-version: '3.12' - name: Instalar dependências run: | pip install --quiet psycopg2-binary pyyaml typer rich - name: Aplicar migrations no Postgres de teste env: DATABASE_URL: postgresql://postgres:postgres@localhost:5432/app_test run: | # Ajuste conforme stack (Prisma, Drizzle, Alembic, etc.) # Exemplos: # npx prisma migrate deploy # npx drizzle-kit push # alembic upgrade head # psql $DATABASE_URL -f migrations/*.sql echo "Aplicar migrations aqui, ajustar pro projeto" - name: Gerar inventário esperado a partir do código env: DATABASE_URL: postgresql://postgres:postgres@localhost:5432/app_test run: | python scripts/gerar-inventario.py --check - name: Verificar drift id: drift env: DATABASE_URL: postgresql://postgres:postgres@localhost:5432/app_test run: | python scripts/gerar-inventario.py --json > /tmp/inventario-gerado.json if ! diff -q transparencia/inventario.yaml /tmp/inventario-gerado.json > /dev/null 2>&1; then echo "drift=true" >> $GITHUB_OUTPUT echo "::warning::Inventário desatualizado. Rode 'python scripts/gerar-inventario.py' e commite." fi - name: Verificar bump de versão se mexeu em schema run: | if git diff --name-only origin/${{ github.base_ref }}..HEAD | grep -E '(migrations/|schema\.|prisma/)' > /dev/null; then if ! git diff origin/${{ github.base_ref }}..HEAD -- transparencia/inventario.yaml | grep -q 'versao:'; then echo "::error::PR mexe em schema mas não bumped transparencia/inventario.yaml#versao" exit 1 fi fi - name: Comentar diff do inventário público no PR if: steps.drift.outputs.drift == 'true' uses: actions/github-script@v7 with: script: | const fs = require('fs'); const atual = fs.readFileSync('transparencia/inventario.yaml', 'utf8'); const gerado = fs.readFileSync('/tmp/inventario-gerado.json', 'utf8'); const body = [ '## ⚠️ Inventário de privacidade desatualizado', '', 'Este PR muda código que afeta o `transparencia/inventario.yaml`,', 'mas o arquivo não foi regerado.', '', '**O que fazer:**', '```bash', 'python scripts/gerar-inventario.py', 'git add transparencia/inventario.yaml', 'git commit -m "chore(legal): atualiza inventário público"', '```', '', 'Esse arquivo é renderizado em `/transparencia/inventario` e é', 'fonte da verdade pública do que o app coleta. Não pode ficar fora de sync.', ].join('\n'); github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body });