Monitoramento - Calculadora de Cashback #18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Monitoramento - Calculadora de Cashback | |
| on: | |
| schedule: | |
| # Todos os dias às 10:00 no horário de Brasília (13:00 UTC) | |
| - cron: "0 13 * * *" | |
| workflow_dispatch: | |
| inputs: | |
| testar_alerta: | |
| description: "Simular uma falha para validar o alerta" | |
| required: false | |
| type: boolean | |
| default: false | |
| permissions: | |
| contents: read | |
| issues: write | |
| concurrency: | |
| group: monitoramento-calculadora-cashback | |
| cancel-in-progress: true | |
| jobs: | |
| verificar-aplicacao: | |
| name: Verificar site, API e banco | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 8 | |
| steps: | |
| - name: Verificar frontend na Vercel | |
| run: | | |
| curl --fail --show-error --silent --location \ | |
| --max-time 60 \ | |
| "https://calculadora-cashback-w34p.vercel.app" > /dev/null | |
| - name: Acordar e verificar backend no Render | |
| run: | | |
| curl --fail --show-error --silent --location \ | |
| --retry 3 --retry-delay 20 --retry-all-errors \ | |
| --max-time 180 \ | |
| "https://calculadora-cashback-csom.onrender.com/health" | |
| - name: Consultar histórico no Supabase | |
| run: | | |
| resposta="$(curl --fail --show-error --silent --location \ | |
| --retry 3 --retry-delay 20 --retry-all-errors \ | |
| --max-time 180 \ | |
| "https://calculadora-cashback-csom.onrender.com/historico")" | |
| RESPONSE="$resposta" python - <<'PY' | |
| import json | |
| import os | |
| dados = json.loads(os.environ["RESPONSE"]) | |
| historico = dados.get("historico") if isinstance(dados, dict) else None | |
| if not isinstance(historico, list): | |
| raise SystemExit("A API respondeu, mas o campo historico não retornou uma lista JSON.") | |
| print(f"Banco acessível. Registros encontrados: {len(historico)}") | |
| PY | |
| - name: Simular falha do alerta | |
| if: ${{ inputs.testar_alerta == true }} | |
| run: | | |
| echo "Falha simulada para validar a criação do alerta." | |
| exit 1 | |
| - name: Criar alerta no GitHub se houver falha | |
| if: ${{ failure() }} | |
| continue-on-error: true | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| titulo="Monitoramento: Calculadora de Cashback indisponível" | |
| issue="$(gh issue list --repo "$GITHUB_REPOSITORY" --state open --search "\"$titulo\" in:title" --json number --jq '.[0].number // empty')" | |
| if [ -z "$issue" ]; then | |
| gh issue create \ | |
| --repo "$GITHUB_REPOSITORY" \ | |
| --title "$titulo" \ | |
| --assignee "$GITHUB_REPOSITORY_OWNER" \ | |
| --body "A verificação automática encontrou uma falha no site, na API ou no banco Supabase. | |
| Acesse a execução com erro em: | |
| $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" | |
| else | |
| gh issue comment "$issue" \ | |
| --repo "$GITHUB_REPOSITORY" \ | |
| --body "A falha aconteceu novamente em $(date -u '+%d/%m/%Y %H:%M UTC'). | |
| Execução: | |
| $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" | |
| fi |