# Prompt zum Erstellen eines GitHub Actions Deploy-Workflows

> KI-Agent-Prompt zum Generieren eines produktionsreifen GitHub Actions CI/CD-Workflows für eine Next.js-App mit Type-Check, Test, Build und Deploy-Schritten.

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

---

Geben Sie diesen Prompt Ihrem Agenten, um eine kampferprobte GitHub Actions-Workflow-Datei zu generieren,
die Type-Checking, Tests und einen Production-Build vor dem Deployment ausführt – ohne
Secrets zu committen oder veraltete Action-Versionen zu verwenden.

## Haupt-Prompt

```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.
```

## Implementierungshinweise

- `oven-sh/setup-bun@v2` installiert die Bun-Version aus `.bun-version` oder `package.json#engines.bun`
  falls vorhanden – stellen Sie sicher, dass eine dieser Dateien existiert oder legen Sie die Version mit `bun-version: '1.x'` fest.
- `--frozen-lockfile` verhindert, dass die CI stillschweigend Abhängigkeiten aktualisiert; ein Fehler hier bedeutet, dass `bun.lock`
  lokal nicht synchron ist.
- Cloudflare Pages mit `wrangler-action@v3` erfordert, dass das Projekt zuerst im Cloudflare-Dashboard
  existiert – dokumentieren Sie diese Voraussetzung in einem Kommentar innerhalb der YAML.
- Parallelität: Verwenden Sie `group: ${{ github.workflow }}-${{ github.ref }}` mit `cancel-in-progress: true`.

## Erwartete Dateiänderungen

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

## Akzeptanzkriterien

- Ein PR zu `main` löst nur den `ci`-Job aus und sendet einen Status-Check.
- Ein Merge zu `main` löst nacheinander `ci` und dann `deploy` aus.
- Keine Secrets erscheinen in der YAML-Datei.
- Ein zweiter Push in denselben Branch bricht den vorherigen laufenden Durchlauf ab.

## Testbefehle

```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
```

## Häufige KI-Fehler

- Hartcodierung des `CLOUDFLARE_API_TOKEN`-Werts anstelle von `${{ secrets.CLOUDFLARE_API_TOKEN }}`.
- Verwendung veralteter `actions/checkout@v2` oder `actions/cache@v2` anstelle von v4.
- Ausführen des Deploy-Jobs bei pull_request-Events, Deployment von Forks.
- Fehlendes `needs: [ci]` im Deploy-Job, was Deployments auch bei Testfehlern erlaubt.

## Fix-Prompt

```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.
```