Skip to content

Automate

Run the CLI in CI

Fail a pipeline on the observations you care about, using a service token instead of a person's sign-in.

On this page

Create a service token

  1. Create the token

    In grcHero, open Settings, API tokens. Create a service token with the contributor role and the Command line scans permission.

  2. Store it as a secret

    Save it in your CI provider's secret store as GRCHERO_API_TOKEN, masked from logs. Save your workspace ID as GRCHERO_ORGANIZATION_ID.

Note: A service token is its own identity, named on the CLI page and in the activity log, and keeps working when people leave. It needs no browser sign-in.

Add a job

name: grcHero review
on: pull_request
permissions:
  contents: read
jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: curl -fsSL https://grchero.dev/install.sh | sh
      - run: ~/.local/bin/grchero scan . --fail-on medium
        env:
          GRCHERO_API_TOKEN: ${{ secrets.GRCHERO_API_TOKEN }}
          GRCHERO_ORGANIZATION_ID: ${{ vars.GRCHERO_ORGANIZATION_ID }}

Show observations in pull requests

--format sarif writes SARIF 2.1.0, which GitHub code scanning and other tools show inline on the changed lines. Each observation carries a stable fingerprint, so an alert stays the same alert across runs.

GitHub Actions
permissions:
  contents: read
  security-events: write
steps:
  - uses: actions/checkout@v4
  - run: curl -fsSL https://grchero.dev/install.sh | sh
  - run: ~/.local/bin/grchero scan . --format sarif > grchero.sarif
    env:
      GRCHERO_API_TOKEN: ${{ secrets.GRCHERO_API_TOKEN }}
      GRCHERO_ORGANIZATION_ID: ${{ vars.GRCHERO_ORGANIZATION_ID }}
  - uses: github/codeql-action/upload-sarif@v3
    with:
      sarif_file: grchero.sarif

Fail only on new observations

Adopting checks on an existing project should not block every pull request. Save a report once, commit it as your baseline, and only observations that are not in it count for --fail-on. The output marks known ones as "in baseline".

An observation is matched by its rule, file and wording, not its line, so moving code around does not make an old observation new.

Terminal
grchero scan . --output .grchero-baseline.json
grchero scan . --baseline .grchero-baseline.json --fail-on medium

Choose when to fail

Observations do not fail the command unless you set --fail-on. high fails on high observations, medium on medium and high, low on all. A preview never fails on observations.

Exit codes

CodeMeaning
0Review finished below the threshold, or another command succeeded
1Review finished with observations at or above --fail-on, or grcHero refused the request or could not be reached
2Invalid options, configuration, scope, report or sign-in, or a file error
3Waiting for a person to confirm in the browser
4Not allowed for this token, role or agent setting
130Cancelled with Ctrl+C
grcHero CLI 0.7.3. Local checks, human review, verifiable evidence.