Skip to content

ci(bot): onboard distilled lessons and cross-review #1337

ci(bot): onboard distilled lessons and cross-review

ci(bot): onboard distilled lessons and cross-review #1337

Workflow file for this run

# Reviewer Bot — initial PR review.
#
# Own-job workflow. We do NOT use the engine's cross-repo actions/reusable
# workflows (`uses: databricks/databricks-bot-engine/...`): an external repo can't
# resolve the internal engine's Actions artifacts ("not found"). Instead the engine
# is pip-installed via the LOCAL ./.github/actions/bot-prelude -> install-bot-engine
# composites (local `./` refs always resolve). This file owns checkout, setup-jfrog,
# Setup Python, and the run; bot-prelude mints tokens + Node + installs the engine.
#
# Engine pin: the engine commit installed is bot-prelude's `engine-ref` default
# (single source of truth for all bots); bump it there, never @main.
#
# Auth: PAT-free — bot-prelude mints a short-lived, engine-scoped App token for the
# install (no stored PAT).
name: Reviewer Bot
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
workflow_dispatch:
inputs:
pr_number:
description: 'PR number to review'
required: true
type: string
dry_run:
description: 'Print what would be posted instead of posting'
required: false
default: 'true'
type: string
permissions:
contents: read
pull-requests: write
id-token: write # JFrog OIDC exchange for the engine/SDK/CLI install
jobs:
review:
# SECURITY FLOOR: manual dispatch, OR a non-draft, non-fork PR. fork == false
# keeps the App + model tokens off untrusted code.
if: >-
github.event_name == 'workflow_dispatch'
|| (github.event.pull_request.draft == false
&& github.event.pull_request.head.repo.fork == false)
# Collapse redundant reviews: this triggers on every `synchronize` (push to a
# PR), so rapid pushes would otherwise spawn overlapping runs against the same
# PR. cancel-in-progress: true — a review of a superseded head is wasted work.
concurrency:
group: reviewer-bot-pr-${{ github.event.pull_request.number || inputs.pr_number }}
cancel-in-progress: true
environment: azure-prod # DATABRICKS_HOST / DATABRICKS_TOKEN live here
runs-on:
group: databricks-protected-runner-group
labels: linux-ubuntu-latest
timeout-minutes: 30
steps:
# Install from trusted workflow source; read the resolved PR head separately.
# PR runs use the base pin; workflow_dispatch uses its selected ref's pin.
- name: Checkout trusted workflow source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event.pull_request.base.sha || github.sha }}
fetch-depth: 0
persist-credentials: false
# Route pip through the JFrog proxy (protected runner is egress-blocked). The
# reviewer reads code, it doesn't build the crate, so cargo isn't configured
# here — only the pip proxy the engine install needs. Exports PIP_INDEX_URL +
# JFROG_ACCESS_TOKEN; install-bot-engine reuses both. MUST run before bot-prelude.
- name: Set up JFrog (pip)
uses: ./.github/actions/setup-jfrog
with:
uv: "true"
# The reviewer reads code, it doesn't run the crate — so it needs only a
# Python interpreter (to run the engine), NOT the Rust toolchain.
- name: Setup Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: '3.11'
# Shared prelude: mint the review-bot token (posts findings) + the
# engine-scoped token, set up Node, install the pinned engine (PAT-free).
- name: Bot prelude (tokens + Node + engine install)
id: prelude
uses: ./.github/actions/bot-prelude
with:
app-id: ${{ secrets.REVIEW_BOT_APP_ID }}
private-key: ${{ secrets.REVIEW_BOT_APP_PRIVATE_KEY }}
# Engine pin lives in ONE place: bot-prelude's `engine-ref` default.
- name: Resolve trigger inputs
id: inputs
# SECURITY: dispatcher-supplied values pass via env, never interpolated into
# the script body (an inline expression would inject at assignment, before
# the digits-only check). Env values expand without re-parsing.
env:
GH_TOKEN: ${{ steps.prelude.outputs.token }}
EVENT_NAME: ${{ github.event_name }}
INPUT_PR: ${{ inputs.pr_number }}
INPUT_DRY_RUN: ${{ inputs.dry_run }}
EVENT_PR: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
run: |
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
RAW_PR="$INPUT_PR"; DRY_RUN="$INPUT_DRY_RUN"
else
RAW_PR="$EVENT_PR"; DRY_RUN="false"
fi
[[ "$RAW_PR" =~ ^[0-9]+$ ]] || { echo "::error::Invalid pr_number '$RAW_PR'"; exit 1; }
case "$DRY_RUN" in true|false) ;; *) DRY_RUN="true" ;; esac # fail safe
PR_JSON=$(gh api "repos/$REPO/pulls/$RAW_PR")
jq -e --arg repo "$REPO" '.state == "open" and .head.repo.full_name == $repo and .head.repo.fork == false' <<< "$PR_JSON" >/dev/null \
|| { echo "::error::Reviewer requires an open PR from this repository"; exit 1; }
HEAD_SHA=$(jq -r '.head.sha' <<< "$PR_JSON")
BASE_SHA=$(jq -r '.base.sha' <<< "$PR_JSON")
{ echo "pr_number=$RAW_PR"; echo "head_sha=$HEAD_SHA"; echo "base_sha=$BASE_SHA"; echo "dry_run=$DRY_RUN"; } >> "$GITHUB_OUTPUT"
- name: Checkout reviewed PR (read-only)
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ steps.inputs.outputs.head_sha }}
path: review-content
persist-credentials: false
- name: Run reviewer
env:
GH_TOKEN: ${{ steps.prelude.outputs.token }}
GITHUB_REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ steps.inputs.outputs.pr_number }}
HEAD_SHA: ${{ steps.inputs.outputs.head_sha }}
PR_BASE_SHA: ${{ steps.inputs.outputs.base_sha }}
DRY_RUN: ${{ steps.inputs.outputs.dry_run }}
REVIEW_CONTENT_ROOT: ${{ github.workspace }}/review-content
REVIEWER_BOT_MODEL_OVERRIDE: databricks-claude-opus-5-5
MODEL_ENDPOINT: https://${{ secrets.DATABRICKS_HOST }}/serving-endpoints/databricks-claude-opus-5-5/invocations
DATABRICKS_TOKEN: ${{ secrets.DATABRICKS_TOKEN }}
RUNNER_TEMP: ${{ runner.temp }}
# The reviewer's repo-specific ADDITIVE guidance, read from the TRUSTED
# checkout (run_review enforces containment). Engine owns the base prompt.
REVIEW_SYSTEM_PROMPT: .bot/prompts/review/system.md
run: python -m databricks_bot_engine.reviewer_bot.run_review