# CI integration

Run Lafke in GitHub Actions and pre-commit so trust drift and findings fail the build.

Any CI system can run `lafke verify` after installing Lafke. Exit code `1` means a trust violation or a finding, and `2` means an operational error. For GitHub, Lafke provides an Action and a pre-commit hook.

## GitHub Action

```yaml
steps:
  - uses: actions/checkout@v4
  - uses: lafke/lafke@v0.1.0
    with:
      command: security
```

The `command` input takes `scan`, `verify`, `diff`, `audit`, `sast`, `security`, `both` (`diff` and `verify`), or `all` (`scan`, `diff`, and `verify`). The default is `all`.

### Inputs

| Input | Default | What it does |
| --- | --- | --- |
| `path` | `.` | The project directory. |
| `command` | `all` | The command to run. |
| `policy` | | Path to a policy file. Not combinable with `profile`. |
| `profile` | | Built-in policy profile: `default` or `strict`. Not combinable with `policy`. |
| `offline` | `false` | Skips remote vulnerability lookups. |
| `reachability` | `false` | Passes `--reachability`, so vulnerabilities in development-only dependencies are marked and lowered by `audit`. |
| `sarif` | `false` | Uploads the report to GitHub code scanning. Needs the `security-events: write` permission. |
| `sbom` | `false` | Writes the lockfile as a CycloneDX SBOM and returns its path in the `sbom-file` output. |
| `report-format` | `text` | Format of the report in the job summary and pull request comment: `text` or `markdown`. |
| `comment` | `true` | Comments a trust report on pull requests. |
| `token` | `${{ github.token }}` | GitHub token for pull request comments and release downloads. |
| `version` | | The Lafke release tag to install. |
| `engine-version` | | The analysis engine release tag to install and use. |

The Action also has `min-release-age`, `prioritize`, `scorecard`, `min-scorecard`, and `import-sarif` inputs for `audit`, `sast`, and `security`. They are listed in [`action.yml`](https://github.com/lafke/lafke/blob/main/action.yml).

The Action installs the analysis engine only for `sast` and `security`, or when `engine-version` is set. Without `engine-version`, it installs the newest engine that speaks this Lafke's protocol.

### Outputs

| Output | What it holds |
| --- | --- |
| `sarif-file` | The path of the SARIF report, when `sarif` is enabled. |
| `sbom-file` | The path of the CycloneDX SBOM, when `sbom` is enabled. |

### Upload to code scanning

```yaml
permissions:
  contents: read
  security-events: write

steps:
  - uses: actions/checkout@v4
  - uses: lafke/lafke@v0.1.0
    with:
      command: security
      sarif: "true"
```

## pre-commit

A [pre-commit](https://pre-commit.com) configuration can run two hooks:

```yaml
repos:
  - repo: https://github.com/lafke/lafke
    rev: v0.1.0
    hooks:
      - id: lafke-verify
      - id: lafke-audit
```

| Hook | What it does |
| --- | --- |
| `lafke-verify` | Fails when dependencies drift from `lafke.lock`. |
| `lafke-audit` | Fails on dependency findings at or above high severity. |

Both hooks run only when a lockfile, `lafke.lock`, or the exceptions file is staged. They check the whole project: the staged files say when to look, not what to look at.

The hooks look packages up online, like the CLI. Add `args: [--offline]` to skip that, which leaves remote evidence `unknown`.

## Other CI systems

Install Lafke, then run `verify`:

```sh
curl -fsSL https://lafke.sh/install | sh
```

```sh
lafke verify .
```

Use `--format sarif`, `junit`, or `markdown` to write a report in the format your CI expects, and `--output` to write it to a file.
