# CI

Run Preflight in CI and a pull request can't merge a launch mistake. `--ci` turns off prompts, and the [exit code](https://preflight.sh/docs/scanning/#exit-codes) fails the step: `2` on an error, `1` on warnings only.

## GitHub Actions

With the install script:

```yaml
- name: Run Preflight
  run: |
    curl -fsSL https://preflight.sh/install.sh | sh
    preflight scan --ci
```

With npm:

```yaml
- name: Run Preflight
  run: |
    npm install -g @preflightsh/preflight
    preflight scan --ci
```

With Docker, mounting the checkout at `/app`:

```yaml
- name: Run Preflight
  run: docker run -v ${{ github.workspace }}:/app ghcr.io/preflightsh/preflight scan --ci --format json
```

The image holds the CLI and nothing else: no package managers and no git. The `vulnerability` check reports a missing audit tool as inconclusive, and so does the `secrets` check on a git checkout, because it cannot ask git which files are tracked. Use the install script or npm when you want those two checks to give an answer.

## Failing on errors only

A warning exits `1`, which fails a step. To fail only on errors, let `1` through:

```yaml
- name: Run Preflight
  run: |
    preflight scan --ci || [ $? -eq 1 ]
```

## Keeping a history

Add `--publish` and each CI run lands on your [dashboard](https://preflight.sh/docs/dashboard/), so you can see what changed between deploys. Publishing never fails a build: offline or signed out, the scan still runs and exits as it would have.

To sign the runner in, save a CLI token as a repository secret and pass it to `preflight auth login` in `PREFLIGHT_TOKEN` before the scan. A token comes from `preflight auth login` on your own machine, which stores it in `~/.preflight/credentials.json`; revoking it in the dashboard's settings signs out every place that uses it.

```yaml
- name: Run Preflight
  env:
    PREFLIGHT_TOKEN: ${{ secrets.PREFLIGHT_TOKEN }}
  run: |
    preflight auth login
    preflight scan --ci --publish
```

## Pull requests from forks

The `vulnerability` check runs the project's package manager, and project configuration can make a package manager run code. When CI scans a fork's pull request, add `--skip vulnerability`. [Checks](https://preflight.sh/docs/checks/#scanning-code-you-dont-trust) explains why.
