# Building, running and CI

Three everyday commands go past checking the code: `jadpo build` writes
the programs you deploy, `jadpo dev` runs the app on your machine, and
`jadpo ci` runs everything a change must pass before it merges.

| Command | What it does |
|---|---|
| [`jadpo build`](/docs/jadpo-build.md) | Build the app to deploy. |
| [`jadpo dev`](/docs/jadpo-dev.md) | Run the app and reload on every save. |
| [`jadpo ci`](/docs/jadpo-ci.md) | Run what a change must pass. |

## `jadpo build`

`jadpo build` writes the runnable app into `build/target/`, with each
API's `<api>.failures.<locale>.json` beside its OpenAPI document
([Failures for client apps](/docs/failures-for-client-apps.md)). It takes
`--json`. It first checks as `jadpo check` does, writing the same files,
and stops at the errors.

- An app that declares no deployables builds its one deployable, `app`,
  natively: the binary `build/target/app/app`, and `build/target/app/openapi/`
  with each API's document and failure files. It is built with the
  toolchain and lock this Jadpo pins ([A native
  deployable](/docs/a-native-deployable.md)).
- An app that declares deployables builds every one, or the one you name,
  each into `build/target/<deployable>/` beside only its own APIs'
  documents ([Declared deployables](/docs/declared-deployables.md)).
- A deployable built for `Target.wasm` is a WebAssembly module with
  Jadpo's module shim and a Wrangler file, and the screen gives the
  module's size ([A Workers deployable](/docs/a-workers-deployable.md)).

## `jadpo dev`

`jadpo dev` runs your app locally and keeps it up to date as you edit. It
runs the app in the interpreter at `http://localhost:3000` (`--port`
changes it) and prints one line per request with its request id.

Each save that checks cleanly serves the next request. While a save has
errors, the last good version keeps serving. `--no-run` only checks on
every save and writes `build/`, and `--json` writes one envelope per line.

An editor that saves a file in place first empties it, then writes its
text. So a save that leaves a file empty that had text isn't taken as
finished yet: the reload waits up to 2 seconds for the file's text. An
empty routes file checks cleanly, with no routes, so this keeps a
half-saved file from replacing the version serving. A file still empty
after that reloads as saved. `jadpo test --watch` waits the same way.

**Settings.** The settings `config.jadpo` declares are read from the
environment, then `.env.local`, and checked before the app starts. A
missing or invalid value stops it starting, and the screen names the
setting and its variable, never the value. A save of `.env.local` is
checked like a save of source, so the last good version keeps serving.

**Databases.** Each database opens at the address its connection's `url:`
setting holds, or the one `--url` names. A store whose address no
variable gives gets a disposable PostgreSQL for the session. Jadpo starts
that from PostgreSQL's own programs (`initdb`, `pg_ctl` and `postgres`), so
PostgreSQL has to be installed on your machine; you don't create a
database or set a password. Pending migrations are applied as they appear, and
the erasure log is replayed as it starts ([What erasure doesn't
rewrite](/docs/erasure-after-the-commit.md#what-erasure-doesnt-rewrite)).
While it runs, the address of each database it started is in
`build/dev/stores.json`, for `jadpo schedules` and `jadpo why`.

**External tokens.** An app that signs in with `external_token` gets a
local issuer in place of the configured one, and `jadpo dev token
<user-id>` prints a bearer token for that user from it
([External tokens in tests and `jadpo dev`](/docs/ways-to-sign-in.md#external-tokens-in-tests-and-jadpo-dev)).
The ready screen says so on its `tokens` line. The token is printed alone,
so it goes straight into a header, and signs in for an hour:

```sh
curl -H "Authorization: Bearer $(jadpo dev token <user-id>)" localhost:3000/staff/me
```

With `--json` it gives the token, its `subject` and `expiresAt`. It needs
a running `jadpo dev` in the project, whose key it signs with: the key is
made for the session, kept in `build/dev/issuer.json`, readable only by
you, while it runs, and removed when it stops.

**Sign-in providers.** An app that signs in through a provider
([Providers](/docs/checking-the-person-sign-in.md#providers)) gets the local issuer in each
provider's place, so none of the provider's settings is needed. Its start
route sends the browser to the local issuer's account-chooser page, on
its own port beside the app, which the ready screen gives on its
`sign-in` line (`signIn` with `--json`). There you choose a test account
or add one (subject, email, whether it is verified, name) and come back
signed in, or cancel and come back refused
([In `jadpo dev`](/docs/checking-the-person-sign-in.md#in-jadpo-dev)). The accounts are kept in
`build/dev/accounts.json` for the next session.

**Background work.** Each schedule run and each skipped tick (a paused
schedule's, once) gets a line with its trace's id, its outcome, what it
emitted or its failure, and its time. Each alert gets a line when it
starts. Each step reached by an action with several changing calls is a
line under its request's line. A delivery whose action reached steps gets
a line of its own, with `jadpo deliveries show <id>` when it needs an
operator ([Background work](/docs/jobs-and-events.md)).

**Provider calls.** Every call to an outside provider is faked by default,
so you need no credential. A connection's `development: { sandbox: }`
lets calls through to the provider's sandbox, never to its live service.
`--fake <connection>` and `--sandbox <operation>` change which for one
session only. Each request's line lists its calls, and each call is logged
for `jadpo calls` ([Provider calls in
development](/docs/provider-calls-in-development.md)).

**Telemetry.** Every request's trace, metrics and log events are kept on
your machine for `jadpo traces`, `jadpo metrics` and `jadpo logs`.
`--export-telemetry` also sends them where the `telemetry:` section
says, and stops the start when it has nowhere to send
([Telemetry](/docs/telemetry.md)).

**Stopping.** Ctrl-c or SIGTERM stops it cleanly: the server finishes the
requests it has, its background work gives back what it holds, and it
exits 0. A second signal ends it at once ([Running background
work](/docs/where-events-travel.md#running-background-work)).

**Timelines.** Each request's timeline is kept in
`build/dev/timelines.jsonl`, the last 500, for `jadpo trace`, and a request
that ran more than one query, or a query no index serves, is flagged on
its line ([The request timeline in
`jadpo dev`](/docs/the-request-timeline-in-jadpo-dev.md)).

Not built yet:

- `jadpo dev` starting the services the app's connections declare
  ([External services](/docs/external-services.md)).

## `jadpo ci`

`jadpo ci` runs `jadpo check`, `jadpo fmt --check`, every test, every
deployable's build and, when the app has a package from the registry,
`jadpo package audit`, in that order, each with `CI` set, and stops at
the first that fails ([Generated CI](/docs/tools-for-agents.md#generated-ci)). Run it before you
push, or in the job of any CI service. `jadpo ci init github` and
`jadpo ci init gitlab` write the file that runs it on GitHub or GitLab.

The screen is the failing step's own findings, as that command shows
them, then each step and its state, the footer, and the failing step's
own hint, if it has one. A step that passes keeps only its notices and
alerts:

```text
✗ error  This file isn't formatted
  domains/hello/actions/greet.jadpo:5:7
  …

Steps
  step         state
  check        ✓ passed   8 files
  fmt --check  ✗ failed   1 not formatted · 7 already formatted
  test         – not run
  build        – not run

✗ ci stopped  fmt --check failed · 1 of 4 steps passed in 0.4 s
```

A run that passes is the table and `✓ ci passed  4 steps in 41.2 s`.
Where stderr doesn't animate, as in CI, each step says it is starting
there (`Running jadpo test`), so a long run shows how far it has got.

With `--json`, `data.steps` holds each step in order: its `step`,
`command` and `state` (`passed`, `failed` or `skipped`), and for each
step that ran its `durationMs` and its own `data`. `data.failed` names
the step that failed, and the document's `diagnostics` are that step's.
It exits as the failing step does.
