# Prompt para Criar um Workflow de Deploy do GitHub Actions

> Prompt para agente de IA gerar um workflow CI/CD de produção do GitHub Actions para um aplicativo Next.js com etapas de type-check, teste, build e deploy.

**Type:** Prompt  
**Tools:** Cursor, Claude Code, Codex, Windsurf  
**Stack:** Next.js, TypeScript, Cloudflare  
**Difficulty:** medium  
**Updated:** 2026-06-08

---

Forneça este prompt ao seu agente para gerar um arquivo de workflow do GitHub Actions testado em batalha
que executa type-checking, testes e um build de produção antes de fazer o deploy — sem
commitar segredos ou usar versões de ações obsoletas.

## Prompt Principal

```txt title="Main Prompt"
You are working in a Next.js 15 project that uses TypeScript and Bun as the package manager.
Deployments go to Cloudflare Pages.

Task: create a GitHub Actions CI/CD workflow at `.github/workflows/deploy.yml`.

Requirements:
- Trigger on: `push` to `main` and `pull_request` targeting `main`.
- On pull_request: run only the `ci` job (lint, typecheck, build).
- On push to main: run `ci` then `deploy` (deploy only if ci passes).
- `ci` job:
  - Runner: `ubuntu-latest`.
  - Steps: checkout, setup Bun (`oven-sh/setup-bun@v2`), `bun install --frozen-lockfile`,
    `bun run typecheck`, `bun run build`.
  - Cache: use `actions/cache@v4` to cache `node_modules` keyed on `bun.lock` hash.
- `deploy` job:
  - needs: [ci]
  - if: `github.event_name == 'push'`
  - Deploy to Cloudflare Pages using `cloudflare/wrangler-action@v3`.
  - Secrets used: `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID` (from GitHub secrets — do NOT
    hard-code values).
  - Set `command: pages deploy .next --project-name=my-app --branch=main`.
- Add a concurrency group to cancel in-progress runs on the same branch.
- Do NOT pin to `@v1` of any action — use the versions specified above.
- Do NOT store any secret value in the YAML file.

Stop and show the complete workflow YAML before writing the file.
```

## Notas de Implementação

- `oven-sh/setup-bun@v2` instala a versão do Bun a partir de `.bun-version` ou `package.json#engines.bun`
  se presente — certifique-se de que um desses arquivos exista ou fixe com `bun-version: '1.x'`.
- `--frozen-lockfile` impede que o CI atualize dependências silenciosamente; falhar aqui significa que `bun.lock`
  está fora de sincronia localmente.
- Cloudflare Pages com `wrangler-action@v3` requer que o projeto exista no dashboard do Cloudflare
  primeiro — documente este pré-requisito em um comentário dentro do YAML.
- Concorrência: use `group: ${{ github.workflow }}-${{ github.ref }}` com `cancel-in-progress: true`.

## Alterações Esperadas nos Arquivos

```txt
.github/workflows/deploy.yml    (new)
```

## Critérios de Aceitação

- Um PR para `main` aciona apenas o job `ci` e publica uma verificação de status.
- O merge em `main` aciona `ci` e depois `deploy`, em ordem.
- Nenhum segredo aparece no arquivo YAML.
- Um segundo push para o mesmo branch cancela a execução anterior em andamento.

## Comandos de Teste

```bash
# validate YAML syntax locally
bun x @actions/validator .github/workflows/deploy.yml || true
# or use actionlint
docker run --rm -v "$(pwd):/repo" rhysd/actionlint:latest /repo/.github/workflows/deploy.yml
```

## Erros Comuns de IA

- Codificar o valor de `CLOUDFLARE_API_TOKEN` em vez de usar `${{ secrets.CLOUDFLARE_API_TOKEN }}`.
- Usar `actions/checkout@v2` ou `actions/cache@v2` obsoletos em vez da v4.
- Executar o job de deploy em eventos pull_request, fazendo deploy a partir de forks.
- Faltar `needs: [ci]` no job de deploy, permitindo deploys mesmo se os testes falharem.

## Prompt de Correção

```txt title="Fix Prompt"
The workflow deploys even when CI fails, or secrets are exposed. Fix in order:
1. Add `needs: [ci]` to the `deploy` job.
2. Add `if: github.event_name == 'push' && github.ref == 'refs/heads/main'` to the deploy job.
3. Replace any hard-coded token values with `${{ secrets.CLOUDFLARE_API_TOKEN }}`.
4. Upgrade any @v1/@v2 action references to the versions specified in the original prompt.
Show only the corrected YAML diff.
```