{
  "id": "create-a-github-actions-deploy-workflow",
  "type": "prompts",
  "category": "prompts",
  "locale": "en",
  "url": "/prompts/create-a-github-actions-deploy-workflow",
  "title": "Prompt to Create a GitHub Actions Deploy Workflow",
  "description": "AI agent prompt to generate a production GitHub Actions CI/CD workflow for a Next.js app with type-check, test, build, and deploy steps.",
  "tools": [
    "Cursor",
    "Claude Code",
    "Codex",
    "Windsurf"
  ],
  "stack": [
    "Next.js",
    "TypeScript",
    "Cloudflare"
  ],
  "tags": [
    "deploy",
    "nextjs",
    "typescript",
    "cloudflare"
  ],
  "difficulty": "medium",
  "updated": "2026-06-08",
  "markdown": "Give this prompt to your agent to generate a battle-tested GitHub Actions workflow file\nthat runs type-checking, tests, and a production build before deploying — without\ncommitting secrets or using deprecated action versions.\n\n## Main Prompt\n\n```txt title=\"Main Prompt\"\nYou are working in a Next.js 15 project that uses TypeScript and Bun as the package manager.\nDeployments go to Cloudflare Pages.\n\nTask: create a GitHub Actions CI/CD workflow at `.github/workflows/deploy.yml`.\n\nRequirements:\n- Trigger on: `push` to `main` and `pull_request` targeting `main`.\n- On pull_request: run only the `ci` job (lint, typecheck, build).\n- On push to main: run `ci` then `deploy` (deploy only if ci passes).\n- `ci` job:\n  - Runner: `ubuntu-latest`.\n  - Steps: checkout, setup Bun (`oven-sh/setup-bun@v2`), `bun install --frozen-lockfile`,\n    `bun run typecheck`, `bun run build`.\n  - Cache: use `actions/cache@v4` to cache `node_modules` keyed on `bun.lock` hash.\n- `deploy` job:\n  - needs: [ci]\n  - if: `github.event_name == 'push'`\n  - Deploy to Cloudflare Pages using `cloudflare/wrangler-action@v3`.\n  - Secrets used: `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID` (from GitHub secrets — do NOT\n    hard-code values).\n  - Set `command: pages deploy .next --project-name=my-app --branch=main`.\n- Add a concurrency group to cancel in-progress runs on the same branch.\n- Do NOT pin to `@v1` of any action — use the versions specified above.\n- Do NOT store any secret value in the YAML file.\n\nStop and show the complete workflow YAML before writing the file.\n```\n\n## Implementation Notes\n\n- `oven-sh/setup-bun@v2` installs the Bun version from `.bun-version` or `package.json#engines.bun`\n  if present — make sure one of those files exists or pin with `bun-version: '1.x'`.\n- `--frozen-lockfile` prevents the CI from silently upgrading deps; failing here means `bun.lock`\n  is out of sync locally.\n- Cloudflare Pages with `wrangler-action@v3` requires the project to exist in the Cloudflare\n  dashboard first — document this prerequisite in a comment inside the YAML.\n- Concurrency: use `group: ${{ github.workflow }}-${{ github.ref }}` with `cancel-in-progress: true`.\n\n## Expected File Changes\n\n```txt\n.github/workflows/deploy.yml    (new)\n```\n\n## Acceptance Criteria\n\n- A PR to `main` triggers only the `ci` job and posts a status check.\n- Merging to `main` triggers `ci` then `deploy`, in order.\n- No secrets appear in the YAML file.\n- A second push to the same branch cancels the previous in-progress run.\n\n## Test Commands\n\n```bash\n# validate YAML syntax locally\nbun x @actions/validator .github/workflows/deploy.yml || true\n# or use actionlint\ndocker run --rm -v \"$(pwd):/repo\" rhysd/actionlint:latest /repo/.github/workflows/deploy.yml\n```\n\n## Common AI Mistakes\n\n- Hard-coding `CLOUDFLARE_API_TOKEN` value instead of using `${{ secrets.CLOUDFLARE_API_TOKEN }}`.\n- Using deprecated `actions/checkout@v2` or `actions/cache@v2` instead of v4.\n- Running the deploy job on pull_request events, deploying from forks.\n- Missing `needs: [ci]` on the deploy job, allowing deploys even if tests fail.\n\n## Fix Prompt\n\n```txt title=\"Fix Prompt\"\nThe workflow deploys even when CI fails, or secrets are exposed. Fix in order:\n1. Add `needs: [ci]` to the `deploy` job.\n2. Add `if: github.event_name == 'push' && github.ref == 'refs/heads/main'` to the deploy job.\n3. Replace any hard-coded token values with `${{ secrets.CLOUDFLARE_API_TOKEN }}`.\n4. Upgrade any @v1/@v2 action references to the versions specified in the original prompt.\nShow only the corrected YAML diff.\n```"
}