# CLI reference

> Every apphelm command, with its flags, the scopes it needs, environment variables, the credentials file, exit codes and CI examples for GitHub Actions and GitLab.

Source: https://apphelm.dev/docs/cli

The `apphelm` command line tool ships in the JavaScript SDK package, `@sansavision/apphelm`. It connects a project, moves one off Sentry's SDKs, reads and changes product data over the [REST API](https://apphelm.dev/docs/api-overview), and does the build and CI work: releases, deploys, source maps, debug symbols, cron check-ins and test events.

## Run it

You don't need to install anything globally. It needs Node.js 20.19 or later.

```bash
npx @sansavision/apphelm help          # anywhere
npm install --save-dev @sansavision/apphelm
npx apphelm help                       # inside a project that has it installed
```

`apphelm help <command>` (or `apphelm <command> --help`) prints a command's options. The examples below write `apphelm`; use `npx @sansavision/apphelm` where it isn't installed.

## Sign in

Most commands call the API and need a **server key** (`ahl_live_…`). On your own computer, `apphelm login` creates one for you. In CI, set `APPHELM_API_KEY` instead.

### apphelm login

```bash
apphelm login [--base-url <url>] [--scopes a,b] [--no-browser] [--json]
```

1. The CLI prints an approval link and an eight-letter code such as `BCDF-GHJK`, and opens the link in your browser (not in CI, not without a terminal, not with `--no-browser`).
2. On that page, sign in, check that the code matches your terminal, choose the key's scopes and products, and approve. Only an owner or admin can approve, because it creates a server key.
3. The CLI waits (checking every 5 seconds) and saves the key. The login expires after 10 minutes.

`--scopes` preselects scopes on the approval page, comma- or space-separated, for example `--scopes events:write,issues:read`. Explicit-only scopes such as `flags:write` or `products:write` are in the key only if you tick them on the page. The key is named "CLI login (apphelm CLI on <your computer>)" and is listed with your other keys in Settings → API keys.

### apphelm whoami and apphelm logout

```bash
apphelm whoami [--json]   # workspace, key name, products, scopes, server, and where the key came from
apphelm logout            # forget the stored key on this computer
```

`logout` deletes the local file only. The key keeps working until you revoke it in Settings → API keys.

### Which key is used

1. `APPHELM_API_KEY`, when it is set.
2. Otherwise the key `apphelm login` stored.

`APPHELM_BASE_URL` points either at another server (the default is `https://apphelm.dev`). Commands that need no key say so below.

### The credentials file

`apphelm login` writes `credentials.json` in `$XDG_CONFIG_HOME/apphelm/`, else `%APPDATA%\apphelm\` on Windows, else `~/.config/apphelm/`. The folder is created readable only by you (`0700`) and the file is `0600`. It holds the key, the server, the workspace and the key's scopes and products. Don't commit it or copy it to CI.

## Connect a project

### apphelm init

```bash
apphelm init [--dir <path>] [--platform <id>] [--product <prd_…>] [--workspace <org_…>]
             [--browser-key <ahl_pub_…>] [--server-key <ahl_live_…>] [--app-key <ahl_live_…>]
             [--create-browser-key --origin <https://…>] [--yes] [--dry-run] [--install] [--json]
```

`init` finds your framework, then adds AppHelm's environment variables and starter code: the same code the Setup wizard and [Install and configure](https://apphelm.dev/docs/install) give.

- **Platform.** Detected from `package.json` and the files in the folder, or chosen with `--platform`: `nextjs`, `react`, `vue`, `svelte`, `html`, `node`, `react-native`, `ios`, `android`, `python`, `jvm`, `go`, `ruby`, `php`, `flutter`, `dotnet`, `elixir`, `rust`.
- **Workspace and product.** From the logged-in key (it asks which product when the key sees several), or from `--workspace` and `--product`.
- **Keys.** `--browser-key` (or `APPHELM_BROWSER_KEY`), `--server-key` and `--app-key` fill in the matching variables; anything missing is written commented out, marked "fill in". `--create-browser-key --origin https://app.example.com` mints a browser key for that origin first, which needs a logged-in key with `products:write`.
- **Nothing is overwritten.** A variable that is already set is kept. A file that already exists is left alone and its snippet is printed for you to merge. A TypeScript snippet in a JavaScript project is printed, not written.
- **Secrets stay out of git.** Variables go to `.env.local` (Next.js, React, Vue, Svelte) or `.env` (Node, Python, JVM, React Native), and that file is added to `.gitignore` unless it is already ignored. Server keys are only ever written to an env file, never into code.
- **Asking first.** Without `--yes` it shows the plan and asks. Without a terminal (CI, a pipe) it prints the plan and writes nothing unless you pass `--yes`.
- `--dry-run` prints the plan and writes nothing. `--install` also runs the plan's `npm`, `pnpm`, `yarn`, `bun` or `pip install` commands, in the project's own package manager. `--json` prints `{ outcome, platform, install, actions, verify, written, … }`, where `outcome` is `dry-run`, `needs-confirmation`, `cancelled` or `applied`.

After it runs, use your app once and watch the first events with `apphelm events tail`.

### apphelm migrate-from-sentry

```bash
apphelm migrate-from-sentry [--dir <path>] [--write] [--json] [--workspace <org_…>] [--product <prd_…>]
```

Moves a project's code off Sentry's SDKs and onto AppHelm's. No key is needed. It is a dry run by default and prints a diff per file; `--write` applies it. JavaScript and TypeScript projects are rewritten; for Python, Swift, Kotlin, Flutter, Go, Ruby, PHP, .NET, Rust and Elixir it prints a call-by-call mapping and the init code. [Migrate from Sentry](https://apphelm.dev/docs/migrate-sentry#step-2-switch-to-the-apphelm-sdk) describes exactly what it changes and what it leaves.

## Product data

These print a table by default; add `--json` for the API's JSON.

### apphelm insights

| Command | Does | Scope |
| --- | --- | --- |
| `apphelm insights list [--product <id>] [--kind trend\|funnel\|retention\|path] [--search <text>] [--tag <tag>]` | Saved insights | `analytics:read` |
| `apphelm insights get <sin_…> [--run]` | One saved insight; `--run` adds its result now | `analytics:read` |
| `apphelm insights list --evidence [--product <id>]` | Evidence-backed insights instead | `insights:read` |

### apphelm flags

| Command | Does | Scope |
| --- | --- | --- |
| `apphelm flags list --product <id>` | Every flag of the product, without its salt | `products:read` |
| `apphelm flags get <flag>` | One flag. `<flag>` is its id (`flg_…`), or its key with `--product` | `products:read` |
| `apphelm flags create --product <id> --key <key> --name <name> [--rollout 0-100] [--type boolean\|multivariate] [--description <text>] [--active]` | Creates a flag. It is off until `--active` or `flags enable` | `flags:write` |
| `apphelm flags update <flag> [--name <name>] [--description <text>] [--rollout 0-100]` | Changes those fields | `flags:write` |
| `apphelm flags enable <flag>` / `disable <flag>` | Turns the flag on or off for live traffic | `flags:write` |
| `apphelm flags archive <flag>` | Archives it | `flags:write` |

Flag keys are lowercase letters, digits, `-` and `_`. `--rollout` is a whole number from 0 to 100. See [Feature flags](https://apphelm.dev/docs/feature-flags).

### apphelm experiments

| Command | Does | Scope |
| --- | --- | --- |
| `apphelm experiments list [--product <id>] [--no-analysis]` | Experiments; `--no-analysis` skips computing results | `experiments:read` |
| `apphelm experiments get <id>` / `results <id>` | One experiment, or only its results | `experiments:read` |
| `apphelm experiments launch <id>` / `stop <id>` | Starts or stops it (and its flag) | `experiments:write` |
| `apphelm experiments ship <id> --variant <key> --note <why>` | Ends it and rolls the flag out to that variant | `experiments:write` |

### apphelm surveys

| Command | Does | Scope |
| --- | --- | --- |
| `apphelm surveys list [--product <id>]` | Surveys | `surveys:read` |
| `apphelm surveys get <id>` / `results <id>` | One survey, or its results | `surveys:read` |
| `apphelm surveys launch <id>` / `stop <id>` / `archive <id>` | Shows, pauses or archives it | `surveys:write` |

### apphelm events tail

```bash
apphelm events tail [--product <id>] [--event <name>] [--interval <seconds>] [--limit <n>] [--once] [--json]
```

Prints the newest events (`--limit`, default 20), then new ones as they arrive, checking every `--interval` seconds (default 2, 1 to 300) until Ctrl-C. `--once` prints one page and exits; `--json` prints one JSON object per line. People appear only as hashes. Needs `analytics:read`.

### apphelm issues

| Command | Does | Scope |
| --- | --- | --- |
| `apphelm issues list --product <prd_…> [--status unresolved\|resolved\|ignored\|all] [--query <search>] [--limit 25]` | Error issues; `--query` takes the issue search language (`is:unresolved release:1.2.0 level:error`) | `issues:read` |
| `apphelm issues resolve <id>[,<id>…] [--in-next-release]` | Resolves up to 100 issues | `issues:write` |
| `apphelm issues reopen <id>[,<id>…]` / `ignore <id>[,<id>…]` | Reopens or ignores them | `issues:write` |

## Releases, builds and uploads

These commands take `--product prd_…`, or read `APPHELM_PRODUCT_ID` when you leave it out. Set `APPHELM_PRODUCT_ID` once in CI and every command below picks it up.

### apphelm releases

| Command | Does | Scope |
| --- | --- | --- |
| `apphelm releases new <version> [--ref <ref>] [--url <https://…>] [--finalize]` | Creates (or updates) a release before it ships | `events:write` |
| `apphelm releases finalize <version> [--released <ISO time>]` | Marks it released, now or at that time | `events:write` |
| `apphelm releases set-commits <version> --auto [--count 20]` | Records the last `--count` commits (1 to 1,000) of this git checkout | `events:write` |
| `apphelm releases set-commits <version> --commit <sha>[,<sha>…]` | Records the commits you name | `events:write` |
| `apphelm releases list [--query <text>] [--status open\|archived\|all] [--limit 25]` | Releases with commits, deploys and new issues | `issues:read` |
| `apphelm releases info <version>` | Crash-free rates, new and regressed issues, commits and deploys | `issues:read` |
| `apphelm releases archive <version>` / `restore <version>` | Hides it from `list`, or brings it back; nothing else changes | `events:write` |
| `apphelm releases delete <version>` | Deletes a release nothing refers to yet, with its commits and deploys | `events:write` |
| `apphelm releases propose-version [--json]` | Prints a release name for this build. No key needed | none |

The version is the release your app sends. `delete` refuses a release that issues, events, sessions or transactions already name; archive it instead. `propose-version` prints the first commit SHA it finds in `APPHELM_COMMIT_SHA`, `SOURCE_VERSION`, `HEROKU_SLUG_COMMIT`, `GITHUB_SHA`, `CI_COMMIT_SHA`, `CIRCLE_SHA1`, `BITBUCKET_COMMIT`, `CODEBUILD_RESOLVED_SOURCE_VERSION`, `VERCEL_GIT_COMMIT_SHA`, `CF_PAGES_COMMIT_SHA`, `BUILDKITE_COMMIT`, `TRAVIS_COMMIT` or `GIT_COMMIT`, else `git rev-parse HEAD`, and nothing else, so `RELEASE=$(apphelm releases propose-version)` works. [Releases and release health](https://apphelm.dev/docs/release-health) explains what releases give you.

### apphelm deploys

```bash
apphelm deploys new --release <version> --env <environment> [--url <https://…>] [--name <note>]   # events:write
apphelm deploys list --release <version> [--json]                                                 # issues:read
```

A deploy marks a release going out to an environment, on charts and for suspect commits. The commit comes from `APPHELM_COMMIT_SHA`, `GITHUB_SHA`, `CF_PAGES_COMMIT_SHA` or `VERCEL_GIT_COMMIT_SHA`. A product records at most 20 deploys an hour.

### apphelm sourcemaps

```bash
apphelm sourcemaps upload <dir> [--release <version>] [--url-prefix /] [--delete-after] [--dry-run]   # events:write
apphelm sourcemaps inject <dir>                                                                      # no key
apphelm sourcemaps upload --bundle <file> --sourcemap <file.map> [--release <version>] [--url-prefix /]
apphelm sourcemaps explain <event id> [--product <prd_…>] [--json]                                   # issues:read
```

- `upload <dir>` gives every built script in the folder a **debug id** (a line at the top, a `//# debugId=` comment, and the same id in its `.map`), then uploads the maps. An error from those files finds its map by that id, whatever the release or URL. **It changes the files in place, so run it on the build output before you deploy it.** A file that already has an id keeps it.
- `--url-prefix` is where the folder is served (default `/`). `--release` also stores the maps under that release. `--delete-after` deletes the `.map` files once they are uploaded, so they are not deployed. `--dry-run` only reports.
- `inject <dir>` adds the debug ids and uploads nothing, so it needs no key; upload the maps later with `upload`.
- `--bundle` and `--sourcemap` upload one map for a bundle that isn't a `.js` file, such as React Native's `index.android.bundle` or `main.jsbundle` (Hermes included). It needs `--release` (or `APPHELM_RELEASE`) unless the map carries a debug id.
- `explain <event id>` says, for each file in an error event's stack, which uploaded map matched (by debug id, or by release and path) or why none did, and what to upload or change.
- The form from before 0.8.0, `apphelm sourcemaps <prd_…> <release> <dir> [url-prefix]`, still works. It matches maps by release and file name only.

At most 600 source map uploads per product per hour. [Source maps and debug symbols](https://apphelm.dev/docs/source-maps) covers bundler plugins and how matching works.

### apphelm debug-files

```bash
apphelm debug-files upload <path>… [--release <version>] [--type dsym|proguard|breakpad] [--uuid <uuid>]   # events:write
apphelm debug-files check <path>… [--json]                                                                 # no key
```

`upload` takes:

- **dSYMs**: a `.dSYM` folder, or the Mach-O file inside it. Every architecture is read, so iOS and macOS crashes show function names, files and lines.
- **Breakpad `.sym` files** (from `dump_syms`), or a folder of them, for minidumps, sentry-native and Android NDK crashes. `--release` is only a label.
- **ProGuard/R8 `mapping.txt`**: needs `--release <version>` (the release your Android app sends), or `--uuid <uuid>` when your app reports a ProGuard UUID (Sentry's Android SDK does; `--sentry-uuid` computes it the way sentry-cli does). `--build <code>` stores a build number with a release-matched mapping.

The type is detected from the file; `--type` forces it. `check` reads files on your computer only and says what each one is, its debug ids per architecture, and whether `upload` takes it or what to run first (an ELF or a PDB needs `dump_syms`). It exits with code 1 when any file isn't usable, so it can gate a build.

### apphelm monitors

```bash
apphelm monitors run <slug> [--schedule "<crontab>" | --interval <minutes>] [--margin <minutes>] [--max-runtime <minutes>] -- <command> [args…]   # events:write
apphelm monitors list [--json]                                                                                                             # monitors:read
```

`run` checks in `in_progress`, runs the command with your terminal's input and output (no shell), then checks in `ok` (exit 0) or `error` with how long it took, and **exits with the command's exit code**. Everything after `--` is the command. `--schedule` (a five-field crontab in UTC) or `--interval` (minutes) creates or updates the monitor, so missed and overrunning runs alert. `--interval` is 1 to 10,080 minutes; `--margin` (default 5) and `--max-runtime` (default 30) are 1 to 1,440 minutes and are saved with the schedule, so they need `--schedule` or `--interval`. A failed check-in is printed and never stops the job. The slug is lowercase letters, digits, `-` and `_`, starting with a letter or digit, up to 64 characters. A slug, schedule or limit the server would refuse stops the command, with the fix, before the job runs.

`list` shows the product's monitors with their status, schedule, last check-in and next expected one; `--json` adds recent check-ins. See [Cron monitors, uptime and status pages](https://apphelm.dev/docs/crons-and-uptime).

### apphelm send-event, send-envelope and send-minidump

```bash
apphelm send-event --message <text> [--level fatal|error|warning|info|debug] [--release <v>] [--env <e>] [--tags key:value,…] [--fingerprint <text>]
apphelm send-envelope <file> [--json]
apphelm send-minidump <file> [--release <v>] [--env <e>]
```

All three need `events:write`.

- `send-event` sends one message event (level `error` by default), which becomes or joins an issue: the quickest end-to-end check of a key, a product and your alerts.
- `send-envelope` sends a Sentry envelope file (what a Sentry SDK writes to disk, or a test fixture) through the same ingest as AppHelm's Sentry-compatible DSN. A `.gz` file is sent compressed. No DSN is needed; the key names the product.
- `send-minidump` sends a native crash: a minidump (`.dmp`, from Crashpad, Breakpad or Electron) or an Android tombstone (`.pb`). It becomes a fatal issue, symbolicated with the Breakpad symbols you uploaded.

### apphelm bash-hook

```bash
eval "$(apphelm bash-hook [--product <prd_…>] [--release <version>] [--env <environment>] [--no-exit])"
```

Put this near the top of a bash script. When a command in the script fails, AppHelm gets an unhandled `ShellCommandFailed` error naming the command (scrubbed of secrets and emails), its exit status, the script, the line and the function call trace. The hook turns on `set -e`, so the script stops as it would have without the hook; `--no-exit` leaves your own `set -e` choice alone and reports every failure. At run time it needs `APPHELM_API_KEY` (with `events:write`), the product from `--product` or `APPHELM_PRODUCT_ID`, and the `apphelm` CLI on `PATH` (or its path in `APPHELM_CLI`). If the CLI is missing or the report fails, it prints a warning and the script carries on as before.

### apphelm react-native

```bash
apphelm react-native gradle [--product <prd_…>]   # a block for android/app/build.gradle
apphelm react-native xcode [--product <prd_…>]    # a Run Script build phase for Xcode
```

Prints what to add to a React Native app so release builds upload what AppHelm needs for readable stacks. No key is needed to print them.

- **gradle**: after each release variant's JS bundle, its source map goes up with `sourcemaps upload --bundle`; after R8, `mapping.txt` goes up with `debug-files upload --type proguard`.
- **xcode**: a build phase placed after "Bundle React Native code and images" that uploads the `main.jsbundle` map and then the dSYMs. Set `SOURCEMAP_FILE` in the bundle phase as the script's comments say.

Both read `APPHELM_API_KEY` and `APPHELM_PRODUCT_ID` from the build environment (in Xcode, from `ios/.xcode.env.local`), never from the file, and `APPHELM_RELEASE` for the release. The default release is `<app id>@<version>+<build>`; use the same value you pass to `createReactNativeSdk`. Debug builds upload nothing (Xcode: unless `APPHELM_UPLOAD_DEBUG` is set). An upload failure prints a warning and never fails the build. `APPHELM_CLI` overrides where the CLI is found.

## CI and operations

These print the API's JSON. `live` and `health` need no key; with a stored login they ask the server you logged in to.

| Command | Does | Scope |
| --- | --- | --- |
| `apphelm live` | Checks the AppHelm service is up | none |
| `apphelm health` | Checks its dependencies are ready; prints the report and exits with `1` when one isn't | none |
| `apphelm products` | Lists the products the key can see | `products:read` |
| `apphelm heartbeat <prd_…> [operational\|degraded\|major_outage\|maintenance] [message]` | Reports the product's status to its status page (default `operational`) | `status:write` |
| `apphelm deploy <prd_…> <release> [environment]` | Records a deploy (default environment `production`), with the commit from the environment and the link from `APPHELM_DEPLOY_URL` | `events:write` |
| `apphelm checkin <prd_…> <monitor> <in_progress\|ok\|error>` | Sends one cron check-in; `APPHELM_CHECKIN_ID` ties the start and the end of one run together | `events:write` |

`heartbeat` used to take a workspace id and send an analytics event. That form (`heartbeat org_… prd_… …`) is refused with the new form to use.

## Flags that work everywhere

| Flag | Meaning |
| --- | --- |
| `--json` | Print JSON instead of a table or text |
| `--help`, `-h` | Show the command's options |
| `--yes`, `-y` | Don't ask (for `init`) |
| `--name value` or `--name=value` | Both forms work. A flag that needs a value fails with "`--name needs a value`" when it has none |
| `--` | Ends the flags; for `monitors run`, everything after it is the command to run |

## Environment variables

| Variable | Used by | Meaning |
| --- | --- | --- |
| `APPHELM_API_KEY` | every command that calls the API | The server key. Wins over the stored login |
| `APPHELM_BASE_URL` | every command that calls the API, `login` | Another AppHelm server (default `https://apphelm.dev`) |
| `APPHELM_PRODUCT_ID` | `releases`, `deploys`, `sourcemaps`, `debug-files`, `monitors`, `issues list`, `send-*`, `bash-hook`, `react-native` | The product, when `--product` is left out |
| `APPHELM_BROWSER_KEY` | `init` | The browser key to write into the project |
| `APPHELM_RELEASE` | `sourcemaps upload --bundle`, `react-native` scripts | The release, when `--release` is left out |
| `APPHELM_COMMIT_SHA`, `GITHUB_SHA`, `CF_PAGES_COMMIT_SHA`, `VERCEL_GIT_COMMIT_SHA` | `deploy`, `deploys new` | The deployed commit (the first one set) |
| `APPHELM_DEPLOY_URL` | `deploy` | A link to the deploy |
| `APPHELM_CHECKIN_ID` | `checkin` | The run id that ties check-ins together |
| `APPHELM_CLI` | `bash-hook`, `react-native` scripts | Where the `apphelm` CLI is |
| `APPHELM_UPLOAD_DEBUG` | `react-native xcode` script | Also upload from Debug builds |
| `XDG_CONFIG_HOME`, `APPDATA`, `HOME` | `login`, `logout` | Where the credentials file is |
| `CI` | `login` | When set, no browser is opened |

## Exit codes

| Code | Meaning |
| --- | --- |
| `0` | Success |
| `1` | Any failure: a refused request, a bad argument, a network error, or (`debug-files check`) a file that isn't usable |
| `130` | Stopped with Ctrl-C |
| the job's code | `monitors run` exits with the command's own exit code, `127` when the command can't be started |

Every API error prints the server's code and message, what to do next, and the request id to quote to support:

| Answer | What the CLI tells you |
| --- | --- |
| `401` | The key was not accepted: run `apphelm login` again, or set `APPHELM_API_KEY` to a valid key |
| `403`, missing scope | "This key lacks `flags:write`", and how to get a key with it |
| `403`, other product | The key is limited to other products; `apphelm whoami` lists them |
| `403`, other | The key's creator can no longer do this in the app; ask an owner or admin |
| `404` | Check the id, and the list command that finds it |
| `409` | It changed or is in another state; read it again and retry |
| `400`, `422` | Check the arguments (`apphelm help <command>`) |
| `429` | Rate limited: wait a minute and retry |
| `5xx` | Retry in a moment; check https://apphelm.dev/status if it keeps failing |

## CI examples

Give CI its own server key with only the scopes the job needs (usually `events:write`, plus `issues:read` if a step reads releases), stored as a secret. Never run `apphelm login` in CI.

### GitHub Actions

.github/workflows/release.yml:
```yaml
name: Release
on:
  push:
    branches: [main]

jobs:
  release:
    runs-on: ubuntu-latest
    env:
      APPHELM_API_KEY: ${{ secrets.APPHELM_API_KEY }}
      APPHELM_PRODUCT_ID: prd_…
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 20            # history for releases set-commits --auto
      - uses: actions/setup-node@v4
        with:
          node-version: 22
      - run: npm ci
      - name: Name the release
        run: echo "RELEASE=$(npx @sansavision/apphelm releases propose-version)" >> "$GITHUB_ENV"
      - run: npm run build           # build with the same release your app sends (for example from $RELEASE)
      - name: Create the release and upload source maps
        run: |
          npx @sansavision/apphelm releases new "$RELEASE"
          npx @sansavision/apphelm releases set-commits "$RELEASE" --auto
          npx @sansavision/apphelm sourcemaps upload dist --release "$RELEASE" --delete-after
      - run: ./deploy.sh             # your deploy step
      - name: Record the deploy
        run: |
          npx @sansavision/apphelm releases finalize "$RELEASE"
          npx @sansavision/apphelm deploys new --release "$RELEASE" --env production
```

### GitLab CI

.gitlab-ci.yml:
```yaml
release:
  image: node:22
  stage: deploy
  variables:
    APPHELM_PRODUCT_ID: prd_…        # APPHELM_API_KEY is a masked CI/CD variable
    GIT_DEPTH: "20"
  script:
    - npm ci
    - export RELEASE=$(npx @sansavision/apphelm releases propose-version)   # reads CI_COMMIT_SHA
    - npm run build
    - npx @sansavision/apphelm releases new "$RELEASE"
    - npx @sansavision/apphelm releases set-commits "$RELEASE" --auto
    - npx @sansavision/apphelm sourcemaps upload dist --release "$RELEASE" --delete-after
    - ./deploy.sh
    - npx @sansavision/apphelm releases finalize "$RELEASE"
    - npx @sansavision/apphelm deploys new --release "$RELEASE" --env production
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
```

### A cron job

crontab:
```bash
0 3 * * * cd /srv/app && APPHELM_API_KEY=… npx apphelm monitors run nightly-backup --product prd_… --schedule "0 3 * * *" -- ./backup.sh
```

The first run creates the monitor with that schedule. From then on a run that doesn't start, fails or overruns raises an alert.

### Mobile builds

```bash
# iOS: after archiving
apphelm debug-files upload build/MyApp.xcarchive/dSYMs --product prd_…

# Android: after a release build with R8
apphelm debug-files upload app/build/outputs/mapping/release/mapping.txt --release "com.example.app@2.4.0+41" --product prd_…
```

## Troubleshooting

| Symptom | Likely cause | What to do |
| --- | --- | --- |
| `Not logged in. Run apphelm login, or set APPHELM_API_KEY` | No key in the environment and no stored login | Run `apphelm login` on your computer, or set `APPHELM_API_KEY` in CI |
| `… needs --product prd_… (or APPHELM_PRODUCT_ID)` | The command didn't get a product | Pass `--product`, or set `APPHELM_PRODUCT_ID`; `apphelm products` lists them |
| `apphelm login` never finishes | The approval page wasn't approved within 10 minutes, or you aren't an owner or admin | Run it again and approve within 10 minutes, or ask an owner or admin to approve it |
| `releases set-commits --auto` says git log failed | CI checked out one commit only | Fetch more history (`fetch-depth: 20`, `GIT_DEPTH: 20`), or pass `--commit <sha>` |
| `No *.js.map files under dist` | The build doesn't write source maps | Turn source maps on in your bundler (they can be hidden from users) and build again |
| Stacks are still minified after an upload | The files deployed are not the files `upload` gave debug ids to, or the release differs | Run `sourcemaps upload` before deploying the same folder; run `apphelm sourcemaps explain <event id>` |
| `debug-files upload` refuses an ELF or PDB file | AppHelm reads Breakpad symbols, not ELF or PDB directly | Run `dump_syms` on it and upload the `.sym`; `apphelm debug-files check <file>` prints the command |
| `--<flag> needs a value` | A flag that takes a value was last, or followed by another flag | Give it a value, or use `--flag=value` |
