# Git Integration

Connect GitHub repositories for automatic production deploys, per-PR preview URLs, build logs, and environment-scoped secrets.

Connect a GitHub repository through the **Skopik Platform GitHub App** in **Settings → Git** (or **New Worker → Import a Git repository**) to get push-to-deploy with no workflow files and no stored API keys.

## How Deployments Work

- **Production branch:** Every push builds changed services in a dedicated 2 vCPU / 2 GiB build Sandbox (`aarch64` Alpine with Node, npm, pnpm, yarn, Python 3, pip, gcc, and git), deploys to `production`, and reconciles any `crons` in `skopik.json`.
- **Pull requests:** Every PR builds changed services to a branch preview alias and posts one in-place comment with a table of preview URLs, GitHub deployments (**View deployment**), and check runs.
- **Cleanup:** Closing a pull request removes its preview aliases automatically. Deployments with no alias pointing at them are cleaned up after 30 days.
- **Forks:** Pull requests from forks pause in `waiting_for_approval` until a collaborator with write access clicks **Approve build** on the GitHub check run.

## Zero-Config Detection

If your repository has no `services` in a root `skopik.json`, Skopik auto-detects **Vite**, **Astro**, **Create React App**, **Node**, **Python**, and plain **static** sites. You can override the framework settings, build command, output directory, and non-secret build env vars on the Git link (`PATCH /v1/github/links/{owner}/{name}`).

## Environments & Encrypted Secrets

Worker secrets are encrypted with AWS KMS and never shown again after being set. Secrets can be scoped per environment (`production` and/or `preview`) and optionally exposed during builds:

:::tabs
::tab skopik
```bash
# Runtime secret for production
skopik set_secret --worker api --name DATABASE_TOKEN --value "sec_..."

# Opt-in build-time secret (value is scrubbed to *** in build logs)
skopik set_secret --worker web --name PUBLIC_KEY --value "pk_..." --build true
```
::tab curl
```bash
curl -X PUT https://api.platform.skopik.com/v1/workers/api/secrets/DATABASE_TOKEN \
  -H "Authorization: Bearer $SKOPIK_API_KEY" \
  -H "content-type: application/json" \
  -d '{"value": "sec_...", "environments": ["production"], "build": false}'
```
::tab MCP
```json
{
  "tool": "set_secret",
  "arguments": {
    "worker": "api",
    "name": "DATABASE_TOKEN",
    "value": "sec_...",
    "environments": ["production"]
  }
}
```
:::

> [!TIP]
> Runtime-only secrets (the default, `build: false`) are never injected into the build Sandbox. Any secret with `build: true` is automatically scrubbed to `***` in build logs.

## Inspecting Builds & Redeploying

Build logs are stored for 30 days (up to 4 MiB) and can be viewed in the console or via CLI/API:

```bash
skopik list_builds --worker api
skopik get_build_log --worker api --build bld_...
skopik redeploy_build --worker api --build bld_...
```
