spackle

← Spackle home

CI

Spackle runs in CI two ways: through the GitHub Action in this repository, or as a plain binary in any other system. Both run the same spackle scan.

The default costs nothing. With no model configured a scan runs the deterministic stages only: the built-in rules and whichever external scanners are on the runner. Hosted runners have none of them, so in the Action that means the built-in rules alone unless you name scanners in the scanners input (see External scanners). It needs no key and calls no model. You add a model when you want leads investigated.

The GitHub Action

A complete workflow for pull requests:

name: spackle

on:
  pull_request:
  push:
    branches: [main]

permissions:
  contents: read
  security-events: write

jobs:
  scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: TMHSDigital/Spackle@v0.2.2
        with:
          version: v0.2.2
          fail-on: high

contents: read lets the job check out the code. security-events: write lets it upload the SARIF report to code scanning. Nothing else is needed.

uses: TMHSDigital/Spackle@v0.2.2 pins the action's own steps. The version input chooses which Spackle release those steps install, and its default is latest. Set both to the same tag when you want the run to be repeatable.

What the action does, in order:

  1. Downloads the release archive for the runner's operating system and architecture, and verifies it (see below).
  2. With scanners set, installs those scanners at their pinned versions, checking each download's SHA-256.
  3. Runs spackle scan <path> --yes --format sarif,markdown,json --out <temp dir> --fail-on <fail-on>, with --no-fix unless you set fix: true.
  4. Appends the Markdown report to the job summary.
  5. Uploads the SARIF report to code scanning, under the category spackle, or spackle-<path> for a scan of a subdirectory (see sarif-category).
  6. With upload-run: true, uploads the run directory as a workflow artifact.
  7. Fails the job with the scan's exit code. The uploads run first, so a failing scan still shows its alerts.

Release archives exist for Linux, macOS and Windows runners on x64 and arm64.

Inputs

Input Default Meaning
path . Directory to scan, relative to the workspace
version latest Spackle release to install, for example v0.2.2. latest resolves the newest release
fail-on high Lowest severity that fails the job: critical, high, medium, low or never. It is always passed to the scan, so fail_on in a committed spackle.toml does not apply in the Action
fail-on-confidence empty Lowest confidence a finding needs to count toward fail-on: plausible (every finding), high or demonstrated. Empty uses fail_on_confidence from a committed spackle.toml, whose default is plausible
upload-sarif true Upload the SARIF report to code scanning. Needs security-events: write
sarif-category empty Category the SARIF report is uploaded under. Code scanning keeps one analysis per category for a commit, so two uses of the action for one commit (two values of path, a matrix over services) need different categories, or the second upload replaces the first and its alerts are closed. Empty uses spackle when path is ., and otherwise spackle- followed by the path, with every character other than a letter, a digit, ., _ and - turned into -. On main, not in v0.2.2 yet
upload-run false Upload the run directory (ledger, reports, proofs, patches) as the artifact spackle-run-<run id>, so you can download it and run spackle report or spackle verify on it later. It holds code excerpts and proof output, so treat it as sensitive
provider empty Model provider: anthropic, openai, openai-compatible or ollama. Empty runs the deterministic stages only, unless a committed spackle.toml has a [model] table (see below)
model empty Model name for the provider
base-url empty Endpoint of the provider. Required for openai-compatible, optional for the others
budget-usd 2 Hard cap on model spend for the run, in USD. Used only when provider is set
fix false Write and verify fixes. Off by default in CI; findings are still reported
diff-base empty Report only on files changed since this revision. See Scan only what a pull request changed
diff-scope empty With diff-base: file (the default) reports every lead in a changed file, lines only the leads on the changed lines. See Scan only what a pull request changed
args empty Extra arguments passed to spackle scan, split on spaces and line breaks, so the value may span several lines. One argument cannot contain a space, and a value with a quote character is refused with exit code 2
scanners empty External scanners to install before the scan: a comma-separated list of gitleaks, hadolint, osv-scanner, trivy and semgrep, or all. Linux x64 runners only. Empty installs none. See External scanners
github-token the workflow token Used to download the release and the scanners, and to verify the release's provenance
spackle-dir empty Directory that already holds a spackle binary. When set, no release is downloaded or verified. Meant for testing a build from source

Outputs

Output Meaning
sarif Path of the SARIF report
exit-code Exit code of the scan: 0, 1, 2 or 3 (see Exit codes)
has-sarif true when the scan wrote a SARIF report
run-id Id of the stored run. Empty when the scan was refused before a run was stored
run-dir Directory of the stored run, in the workspace. It is gone when the job ends unless upload-run is set
critical, high, medium, low Number of findings of that severity in the report, not counting dismissed ones. Findings that are fixed or accepted by a baseline are counted, so these can be above zero on a job that passes

Give the step an id to read them:

      - id: spackle
        uses: TMHSDigital/Spackle@v0.2.2
        with:
          fail-on: never
      - run: echo "Spackle exited ${{ steps.spackle.outputs.exit-code }}"

Adding a model

Set provider and model, and pass the key through env from a repository secret. The action never takes a key as an input: Spackle reads keys only from environment variables.

      - uses: TMHSDigital/Spackle@v0.2.2
        with:
          version: v0.2.2
          provider: anthropic
          model: claude-opus-5-5
          budget-usd: '2'
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}

The variable depends on the provider:

Provider Variable
anthropic ANTHROPIC_API_KEY
openai OPENAI_API_KEY
openai-compatible SPACKLE_API_KEY, or the variable named by api_key_env in a file passed with args: --config

With a model, the run spends money, up to budget-usd. The action passes --yes, so nobody is asked to confirm the estimate: setting provider is the consent. If Spackle has no price for the model (every openai model, and most openai-compatible endpoints other than OpenRouter), the dollar cap cannot be enforced, so the scan is refused with exit code 2 and the message shows the [pricing] table to add to the config you pass with args: --config. To run under the token cap alone, set args: --allow-unpriced. See config.md.

A committed spackle.toml in the scanned repository's working directory is read, but as an untrusted file: anyone who can change the repository, a pull request included, can change it. Its endpoints and key variables, openai-compatible models, [pricing], [scope], sandbox images and network, pr, state_dir, [output] dir and budget raises are not applied (see config.md), and the job log names what was left out. To use them, keep a config the workflow trusts and point at it with args: --config path/to/spackle.toml; a file named with --config is applied in full, so it should not be one a pull request can change.

That file is read even when provider is empty. If it has a [model] table, the action runs that model, with --yes, under the file's [budget] (usd defaults to 5, and the file cannot raise it) instead of budget-usd, which is passed only when provider is set. The key variable for that provider must then be in the job's env, or every run exits 2 because the variable is not set. To keep a job free of model calls in a repository that commits a model, point args: --config at a file without a [model] table.

Scan only what a pull request changed

By default a scan reports on the whole path, so the first pull request on an existing codebase fails on findings that were there before it. diff-base makes the gate about the change under review: only leads in files the pull request added or changed are reported, and with a model only those files are planned for investigation.

      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          fetch-depth: 0
      - uses: TMHSDigital/Spackle@v0.2.2
        with:
          version: v0.2.2
          fail-on: high
          diff-base: ${{ github.event.pull_request.base.sha }}

fetch-depth: 0 matters: the default checkout holds one commit, and git cannot compare against a base it does not have. The scan is then refused with exit code 2 and a message that says so. On a push event the expression is empty and the whole path is scanned.

The diff-base input and the --since flag behind it are new in v0.2.0. The v0.1.0 binary does not know the flag and exits with a usage error.

What a diff scan does and does not do:

By default a lead anywhere in a changed file is reported, so touching one line of an old file reports every lead already in it. --diff-scope lines (the Action's diff-scope: lines) reports only the leads on lines the change added or modified, and the report says how many leads elsewhere in the changed files were left out. A deletion counts as touching the lines on either side of it. A lead with no line, such as a vulnerable dependency in a lockfile, is still reported when its file changed. With a model, the scope narrows the leads the investigations start from; a finding an investigation reaches is still reported where the flaw is. --diff-scope lines works with --changed too, where a new file counts as changed on every line. Like diff-base, it is new in v0.2.0.

To scan work you have not committed yet, use spackle scan . --changed instead of --since. It reports only on files that differ from the last commit, staged or not, and on new files git does not ignore.

A pre-commit hook should judge what is being committed, so use --staged there. It reports only on files whose staged version differs from the last commit: an untracked scratch file or an unstaged edit to a file you are not committing does not block the commit. The staged content is read from the index, so a risky line you staged and then fixed only in the working tree still fails the hook: Spackle exports the staged files into a temporary directory under the state directory, runs the built-in rules and the external scanners on that, and removes it when the scan ends. The report holds the repository's paths and says how many staged files also have unstaged edits, which were not scanned. --diff-scope lines takes the staged lines, numbered as in the staged version. With a model, a --staged scan writes no fixes, because a fix is built on the working tree; use --changed for fixes. A --staged run cannot be resumed. --since, --changed and --staged cannot be combined. As a git pre-commit hook (.git/hooks/pre-commit, made executable):

#!/bin/sh
exec spackle scan . --staged --offline --fail-on high --format terminal

With the pre-commit framework, add the hook from this repository to .pre-commit-config.yaml. The spackle hook builds Spackle from source with Go; spackle-system uses the spackle already on your PATH instead.

repos:
  - repo: https://github.com/TMHSDigital/Spackle
    rev: v0.2.2
    hooks:
      - id: spackle

--staged and the hooks file are new in v0.2.0. Reading the staged content from the index is on main and not in v0.2.2 yet: the v0.2.2 binary, and the hook at rev: v0.2.2, read the working-tree version of the staged files, and can act on the wrong repository when git starts the hook with GIT_DIR set. Both are fixed in the next release.

Pull requests from forks do not receive repository secrets, so a model step has no key there. Keep the deterministic default for those runs.

Proofs and fix checks need a container runtime on the runner. Without one, a model run still investigates and reports, and labels its findings as traced by reading the code.

Accept known findings with a baseline

A baseline file lets a team adopt the gate on an existing codebase without fail-on: never. A finding that matches one of its entries is reported with the status accepted and the entry's reason, in every format, but it does not fail the run. In SARIF it carries a suppression of kind external, which code scanning shows as dismissed.

  1. Scan the default branch and write the file from that run: spackle baseline latest --out .spackle-baseline.json --reason "existing before adoption". It holds one entry per open finding (and per finding with a patch available), with its id, fingerprint, class, title and location.
  2. Commit the file and point scans at it, with baseline = ".spackle-baseline.json" under [scan] in a committed spackle.toml, or --baseline .spackle-baseline.json (in the Action, args: --baseline .spackle-baseline.json). The path is relative to the working directory, like state_dir.
  3. Edit the reasons as you like. An entry may have "expires": "YYYY-MM-DD": from that day on it accepts nothing, so the finding fails the gate again. The date is a day in UTC on every machine, so the entry stops at 00:00 UTC of that day: in a time zone west of UTC that is the evening before, and east of UTC a few hours into the day. --expires 2027-03-01 writes that date on the entries the command adds.

To accept one finding of a later scan, a false positive for example, name it: spackle baseline latest --finding SPK-1A2B3C4D --reason "false positive: the value is a constant" --expires 2027-03-01. That adds an entry for the finding, or updates the one it already has (a reason or date you give replaces the old one), and leaves every other entry of the file as it is. --finding may be repeated. Without it the command rewrites the whole file from the run, which also accepts every other open finding of that run. --finding and --expires are on main and not in v0.2.2 yet.

Entries match by the finding's fingerprint, which is made from the flagged code and not its line number, so a finding that only moved stays accepted. Editing the flagged code changes the fingerprint, and the finding fails the gate again. Entries without a fingerprint match by finding id. A run lists the entries that matched no finding (the finding is gone or its code changed) and those that have expired, so the file can be kept current. Running spackle baseline again with the same --out rewrites the file from the newer run and keeps the reason and expiry of each entry that still matches. Entries that match nothing in that run are dropped, so the rewrite is refused when the run was a diff scan (--since, --changed or --staged) and entries would be lost: such a run holds only the findings of the changed files. Use --finding there. A baseline that cannot be read refuses the scan with exit code 2.

SARIF and code scanning

The report is SARIF 2.1.0. What it carries:

Set upload-sarif: false to skip the upload and handle the file yourself through the sarif output.

External scanners

Spackle runs Semgrep, gitleaks, osv-scanner, Trivy and hadolint when it finds them on PATH, and GitHub's hosted runners have none of them. The scanners input installs the ones you name, at the releases Spackle's adapters are tested against:

      - uses: TMHSDigital/Spackle@v0.2.2
        with:
          version: v0.2.2
          scanners: gitleaks,hadolint,osv-scanner

The scanners input is on main and not in v0.2.2 yet. The action at @v0.2.2 does not have it, so with that tag no scanner is installed and the scan runs the built-in rules alone. The example above works from the next release on.

The versions and SHA-256 hashes are pinned in .github/scanners/pins.env of the action, the same file the repository's own scanner tests install from, so uses: TMHSDigital/Spackle@<tag> pins the scanners too. gitleaks, hadolint, osv-scanner and Trivy are release files: each is downloaded with the GitHub CLI and checked against its pinned hash before it is extracted, and a file that does not match fails the job before anything runs. Semgrep is installed from PyPI with pipx at its pinned version; pip checks no hash for it or for its dependencies. The scanners go into the runner's temporary directory and are on PATH for the scan step only.

The pinned files are Linux x64 builds, so on any other runner a non-empty scanners fails the job with a message that says so. A name that is not one of the five, or all, fails it too.

gitleaks and hadolint work offline. osv-scanner and Trivy download vulnerability databases and Semgrep downloads its rules (unless [scan.semgrep] config names only local rule paths, see config.md), so those three need network access from the runner. Each scanner appears in the job summary's seeder table with its version, its lead count, and any error. [scan] scanners in the config still chooses which of the installed scanners run.

How the action verifies what it downloads

The install step does three things before it runs anything:

  1. Downloads the archive and checksums.txt from the release with the GitHub CLI.
  2. Checks the archive's SHA-256 against its line in checksums.txt.
  3. Runs gh attestation verify <archive> --repo TMHSDigital/Spackle --signer-workflow TMHSDigital/Spackle/.github/workflows/release.yml, which checks that the archive carries build provenance from this repository's release workflow and from no other workflow of the repository.

If either check fails, the step fails and Spackle is never run. Action inputs reach the scan through environment variables and as separate arguments. They are never interpolated into the script.

Exit codes

Code Meaning In the action
0 The scan ran. No unresolved finding at or above fail-on The job passes
1 The scan ran. At least one unresolved finding at or above fail-on The job fails, after the SARIF upload
2 Refused before running: bad arguments, bad configuration, or missing authorization The job fails
3 The run itself failed The job fails

A finding is unresolved when its status is open or patch-available. A patch that Spackle wrote and checked is not applied to the code that was scanned, so such a finding still fails the job until the patch is merged and a later scan or spackle verify no longer reproduces it. Fixed and dismissed findings do not count toward the threshold. The SARIF report agrees with this rule: unresolved findings keep the level of their severity, and a fixed finding is listed at level note. fail-on: never makes a successful scan exit 0 whatever it found.

fail-on-confidence (--fail-on-confidence, [output] fail_on_confidence) narrows the gate further: with high, only findings a model traced end to end or proved count, and unconfirmed leads are reported without failing the job; with demonstrated, only findings whose proof of concept ran. Without a model every finding is plausible, so high or demonstrated never fails a deterministic scan. SARIF levels still follow severity.

Other CI systems

Spackle is one static binary. Download a release archive, verify it, and run it.

# Verify, with the GitHub CLI
sha256sum --ignore-missing -c checksums.txt
gh attestation verify spackle_<version>_linux_amd64.tar.gz --repo TMHSDigital/Spackle \
  --signer-workflow TMHSDigital/Spackle/.github/workflows/release.yml

# Scan
spackle scan . --yes --format sarif,markdown --out spackle-report --fail-on high --no-fix

The reports land in spackle-report/report.sarif and spackle-report/report.md. Status lines go to standard error. Use the exit code to pass or fail the job. All six formats are also kept under .spackle/runs/<run-id>/reports/.

To add a model, export the key variable from your CI system's secret store and pass --provider, --model and --budget-usd, or commit a spackle.toml. To report only on what a change touched, pass --since <base revision> after fetching that revision.

GitLab CI

--format gitlab-sast writes report.gl-sast.json, a GitLab SAST report (schema 15.2.5). Attach it as a sast report and GitLab shows the findings in the merge request security widget and the project's vulnerability report. It holds the findings that can fail the job under --fail-on: open ones and ones with a patch available. Fixed, accepted and dismissed findings are left out.

spackle:
  stage: test
  image: debian:bookworm-slim
  variables:
    SPACKLE_VERSION: "0.2.2"
  script:
    - apt-get update -qq && apt-get install -y -qq --no-install-recommends ca-certificates curl git >/dev/null
    - base="https://github.com/TMHSDigital/Spackle/releases/download/v${SPACKLE_VERSION}"
    - curl -fsSLO "$base/spackle_${SPACKLE_VERSION}_linux_amd64.tar.gz"
    - curl -fsSLO "$base/checksums.txt"
    - sha256sum --ignore-missing -c checksums.txt
    - tar -xzf "spackle_${SPACKLE_VERSION}_linux_amd64.tar.gz" spackle
    - ./spackle scan . --yes --format gitlab-sast,markdown --out spackle-report --fail-on high --no-fix
  artifacts:
    when: always
    paths:
      - spackle-report/
    reports:
      sast: spackle-report/report.gl-sast.json

--format gitlab-sast is on main and not in v0.2.2 yet. The v0.2.2 binary refuses it as an unknown report format and exits with code 2, so this job works from the next release on; set SPACKLE_VERSION to that release.

when: always keeps the report when the scan fails the job. The merge request widget compares the report with the one from the target branch, so run the job on the default branch too.

Two rules for CI

--yes is required. CI has no terminal. Without --yes, a run that would call a paid model is refused, because a pipe is not consent to spend money. With --yes, Spackle never prompts: the budgets and any authorization must come from flags or from the config file. A deterministic scan of a directory does not prompt either way, but pass --yes so the job never waits on a question.

A running target in CI needs a committed scope file. A URL target always goes through the authorized-scope gate. With --yes, or with no terminal, the typed confirmation is not offered, so the scope must come from --authorize <scope-file> or a [scope] table in spackle.toml. Without one the run is refused with exit code 2 and nothing is sent.

spackle scan http://localhost:8081 --yes --authorize ci/scope.toml --format sarif --out spackle-report
# ci/scope.toml
hosts = ["localhost:8081"]
statement = "Ephemeral instance started by this CI job."

Commit the scope file so the authorization is reviewed like any other change. The file format and the matching rules are in config.md.

This page is rendered from docs/ci.md in the repository.