# GitHub & CI/CD

Three ways to deploy from GitHub.

**Option A, Dashboard + GitHub App (public + private repos, recommended).** Install the Percher GitHub App from the GitHub section at percher.app/account#github and pick which repos to grant. Then click Deploy on a repo; auto-deploy on push is active immediately, no webhook config. Every open PR also gets its own preview at `{app}-pr-{n}.percher.run` — Percher posts a sticky PR comment with the preview URL (updated on every push, edited to "torn down" when the PR closes) plus a check-run. AI agents can connect after the one-time install with `percher github connect https://github.com/owner/repo --app myapp` (a full HTTPS URL — the `owner/repo` shorthand is rejected). (The GitHub section only appears once the App is configured on the instance — see the operator runbook if it's missing.)

**Option B, Server-side webhook (public repos only).** Percher clones the repo and deploys on every push to the tracked branch, with no Actions runners or billing minutes. If the app doesn't exist yet, `github connect` creates it from the repo. Then:
```sh
bunx percher github connect https://github.com/owner/repo --branch main
```
It clones, queues a deploy, and prints a webhook secret. Add a GitHub webhook: Payload URL `https://api.percher.run/webhooks/github`, content type `application/json`, the printed secret (shown once), just the push event. Percher verifies the HMAC-SHA256 signature and ignores other branches. Recover a failed setup with `bunx percher github setup-webhook --app <name>`.

**Option C, GitHub Actions with PERCHER_TOKEN (public + private).** Create a token at percher.app/account → API token, add it as the Actions secret `PERCHER_TOKEN`, then run `bunx percher publish` in the workflow (use `--preview` on pull_request for preview deploys). The CLI auto-detects the branch from GITHUB_HEAD_REF / GITHUB_REF_NAME (also GitLab, Vercel, Netlify env vars) for the deploy note. Token auth works in any shell: `PERCHER_TOKEN=<token> bunx percher publish` or save it with `bunx percher login --token <token>`.

**Scoped tokens (recommended for CI).** A default token has full account access — more than a pipeline needs. Mint a least-privilege one instead:
```sh
bunx percher token create ci-deploy --scope deploy --app my-app --ttl-days 90
```
Scopes: `deploy` (the publish loop: publish, redeploy, rollback, logs, diagnostics — no env, domains, data, or account routes), `env` (env vars only), `read` (safe GETs only), `full`. `--app` binds the token to one app; `--ttl-days` gives it an expiry. Rotate by creating the replacement first, swapping the CI secret, then `percher token revoke <id>` (list ids with `percher token list`). The secret is shown once at create time.

Full guide: https://percher.app/docs/github-cicd
