Files
playbook/brooks-lint/.github/actions/brooks-lint/action.yml
T
2026-06-18 16:04:36 +00:00

126 lines
4.0 KiB
YAML

name: "Brooks-Lint Review"
description: "Run brooks-lint on PR changes and post results as a PR comment"
author: "hyhmrright"
inputs:
mode:
description: "Review mode: review, audit, debt, test, health, sweep"
default: "review"
anthropic-api-key:
description: "Anthropic API key"
required: true
fail-below:
description: "Fail the check if Health Score is below this threshold (0 = never fail)"
default: "0"
fail-on:
description: "Fail the check on findings at/above this severity: none, warning, or critical"
default: "none"
fail-on-regression:
description: "Fail the check if the Health Score dropped vs the last run (true/false)"
default: "false"
sarif-file:
description: "Path to write a SARIF report for GitHub Code Scanning (empty = skip SARIF)"
default: ""
model:
description: "Claude model to use"
default: "claude-sonnet-4-6"
outputs:
score:
description: "Health Score from the review (0-100)"
value: ${{ steps.score.outputs.score }}
branding:
icon: "shield"
color: "blue"
runs:
using: "composite"
steps:
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Cache SDK
id: cache
uses: actions/cache@v4
with:
path: ${{ github.action_path }}/node_modules
key: brooks-lint-sdk-${{ runner.os }}-${{ hashFiles(format('{0}/package.json', github.action_path)) }}
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
shell: bash
run: npm install --prefix "$GITHUB_ACTION_PATH" @anthropic-ai/sdk
- name: Run Brooks-Lint
shell: bash
env:
ANTHROPIC_API_KEY: ${{ inputs.anthropic-api-key }}
SARIF_FILE: ${{ inputs.sarif-file }}
MODE: ${{ inputs.mode }}
MODEL: ${{ inputs.model }}
run: |
sarif_arg=()
if [ -n "$SARIF_FILE" ]; then
sarif_arg=(--sarif-out "$SARIF_FILE")
fi
node "$GITHUB_ACTION_PATH/scripts/ci-review.mjs" \
--mode "$MODE" \
--model "$MODEL" \
--skills-dir "$GITHUB_ACTION_PATH/skills" \
--project-dir "$GITHUB_WORKSPACE" \
"${sarif_arg[@]}" \
> brooks-lint-report.json
- name: Parse Health Score
shell: bash
id: score
run: |
score=$(node --input-type=module -e "
import { readFileSync } from 'fs';
const r = JSON.parse(readFileSync('brooks-lint-report.json', 'utf8'));
console.log(r.score ?? 0);
")
echo "score=$score" >> "$GITHUB_OUTPUT"
- name: Post PR Comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const r = JSON.parse(fs.readFileSync('brooks-lint-report.json', 'utf8'));
const trend = r.trend ? `\n\n**Trend:** ${r.trend}` : '';
const body = `## Brooks-Lint Review\n\n${r.report}${trend}\n\n---\n_Automated by [brooks-lint](https://github.com/hyhmrright/brooks-lint)_`;
await github.rest.issues.createComment({
...context.repo,
issue_number: context.issue.number,
body
});
- name: Upload SARIF
if: inputs.sarif-file != ''
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ inputs.sarif-file }}
- name: Check Threshold
if: inputs.fail-below != '0'
shell: bash
run: |
if [ "${{ steps.score.outputs.score }}" -lt "${{ inputs.fail-below }}" ]; then
echo "Health Score ${{ steps.score.outputs.score }} is below threshold ${{ inputs.fail-below }}"
exit 1
fi
- name: Quality Gates
if: inputs.fail-on != 'none' || inputs.fail-on-regression == 'true'
shell: bash
run: |
node "$GITHUB_ACTION_PATH/scripts/ci-gate.mjs" \
--report brooks-lint-report.json \
--fail-on "${{ inputs.fail-on }}" \
--fail-on-regression "${{ inputs.fail-on-regression }}"