|
| 1 | +# Reviewer Bot — initial PR review. |
| 2 | +# |
| 3 | +# Own-job workflow. We do NOT use the engine's cross-repo actions/reusable |
| 4 | +# workflows (`uses: databricks/databricks-bot-engine/...`): an external repo |
| 5 | +# can't resolve the internal engine's Actions artifacts ("not found"). Instead |
| 6 | +# the engine is pip-installed via the LOCAL ./.github/actions/bot-prelude -> |
| 7 | +# install-bot-engine composites (local `./` refs always resolve). This file owns |
| 8 | +# checkout, Setup Python, and the run; bot-prelude mints tokens + Node + installs |
| 9 | +# the engine. |
| 10 | +# |
| 11 | +# Engine pin: the engine commit installed is bot-prelude's `engine-ref` default |
| 12 | +# (single source of truth for all four bots); bump it there, never @main. |
| 13 | +# |
| 14 | +# Auth: PAT-free — bot-prelude mints a short-lived, engine-scoped App token for |
| 15 | +# the install (no stored BOT_ENGINE_PAT). |
| 16 | +name: Reviewer Bot |
| 17 | + |
| 18 | +on: |
| 19 | + pull_request: |
| 20 | + types: [opened, synchronize, reopened, ready_for_review] |
| 21 | + workflow_dispatch: |
| 22 | + inputs: |
| 23 | + pr_number: |
| 24 | + description: 'PR number to review' |
| 25 | + required: true |
| 26 | + type: string |
| 27 | + dry_run: |
| 28 | + description: 'Print what would be posted instead of posting' |
| 29 | + required: false |
| 30 | + default: 'true' |
| 31 | + type: string |
| 32 | + |
| 33 | +permissions: |
| 34 | + contents: read |
| 35 | + pull-requests: write |
| 36 | + id-token: write # JFrog OIDC exchange for the engine/SDK/CLI install |
| 37 | + |
| 38 | +jobs: |
| 39 | + review: |
| 40 | + # SECURITY FLOOR (was the reusable's job `if:`): manual dispatch, OR a |
| 41 | + # non-draft, non-fork PR. fork == false keeps the App + model tokens off |
| 42 | + # untrusted code. |
| 43 | + if: >- |
| 44 | + github.event_name == 'workflow_dispatch' |
| 45 | + || (github.event.pull_request.draft == false |
| 46 | + && github.event.pull_request.head.repo.fork == false) |
| 47 | + # Collapse redundant reviews: this triggers on every `synchronize` (push to a |
| 48 | + # PR), so rapid pushes would otherwise spawn overlapping runs against the same |
| 49 | + # PR. cancel-in-progress: true — a review of a superseded head is wasted work |
| 50 | + # (unlike the followups, which use cancel-in-progress: false to avoid dropping |
| 51 | + # a reconcile mid-thread). Matches the sibling workflows' concurrency pattern. |
| 52 | + concurrency: |
| 53 | + group: reviewer-bot-pr-${{ github.event.pull_request.number || inputs.pr_number }} |
| 54 | + cancel-in-progress: true |
| 55 | + environment: azure-prod # DATABRICKS_HOST / DATABRICKS_TOKEN live here |
| 56 | + runs-on: |
| 57 | + group: databricks-protected-runner-group |
| 58 | + labels: [linux-ubuntu-latest] |
| 59 | + timeout-minutes: 30 |
| 60 | + steps: |
| 61 | + # Checkout FIRST. Default ref = the PR merge ref on pull_request, the |
| 62 | + # default branch on dispatch. persist-credentials:false — the reviewer |
| 63 | + # reads this tree via read_paths/grep, so no token may sit in .git/config. |
| 64 | + - name: Checkout |
| 65 | + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
| 66 | + with: |
| 67 | + fetch-depth: 0 |
| 68 | + persist-credentials: false |
| 69 | + |
| 70 | + # The reviewer reads code, it doesn't run the connector — so it needs only |
| 71 | + # a Python interpreter (to run the engine), NOT the connector's deps. |
| 72 | + - name: Setup Python |
| 73 | + uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0 |
| 74 | + with: |
| 75 | + python-version: '3.11' |
| 76 | + |
| 77 | + # Shared prelude: mint the review-bot token (posts findings) + the |
| 78 | + # engine-scoped token, set up Node, install the pinned engine (PAT-free). |
| 79 | + - name: Bot prelude (tokens + Node + engine install) |
| 80 | + id: prelude |
| 81 | + uses: ./.github/actions/bot-prelude |
| 82 | + with: |
| 83 | + app-id: ${{ secrets.REVIEW_BOT_APP_ID }} |
| 84 | + private-key: ${{ secrets.REVIEW_BOT_APP_PRIVATE_KEY }} |
| 85 | + # Engine pin lives in ONE place: bot-prelude's `engine-ref` default. |
| 86 | + # Bump it there to move all four bots in lockstep; override here only |
| 87 | + # to run this workflow against a different engine commit. |
| 88 | + |
| 89 | + - name: Resolve trigger inputs |
| 90 | + id: inputs |
| 91 | + # SECURITY: dispatcher-supplied values pass via env, never interpolated |
| 92 | + # into the script body (an inline expression would inject at assignment, |
| 93 | + # before the digits-only check). Env values expand without re-parsing. |
| 94 | + env: |
| 95 | + GH_TOKEN: ${{ steps.prelude.outputs.token }} |
| 96 | + EVENT_NAME: ${{ github.event_name }} |
| 97 | + INPUT_PR: ${{ inputs.pr_number }} |
| 98 | + INPUT_DRY_RUN: ${{ inputs.dry_run }} |
| 99 | + EVENT_PR: ${{ github.event.pull_request.number }} |
| 100 | + REPO: ${{ github.repository }} |
| 101 | + run: | |
| 102 | + if [ "$EVENT_NAME" = "workflow_dispatch" ]; then |
| 103 | + RAW_PR="$INPUT_PR"; DRY_RUN="$INPUT_DRY_RUN" |
| 104 | + else |
| 105 | + RAW_PR="$EVENT_PR"; DRY_RUN="false" |
| 106 | + fi |
| 107 | + [[ "$RAW_PR" =~ ^[0-9]+$ ]] || { echo "::error::Invalid pr_number '$RAW_PR'"; exit 1; } |
| 108 | + case "$DRY_RUN" in true|false) ;; *) DRY_RUN="true" ;; esac # fail safe |
| 109 | + HEAD_SHA=$(gh pr view "$RAW_PR" --repo "$REPO" --json headRefOid -q .headRefOid) |
| 110 | + { echo "pr_number=$RAW_PR"; echo "head_sha=$HEAD_SHA"; echo "dry_run=$DRY_RUN"; } >> "$GITHUB_OUTPUT" |
| 111 | +
|
| 112 | + - name: Run reviewer |
| 113 | + env: |
| 114 | + GH_TOKEN: ${{ steps.prelude.outputs.token }} |
| 115 | + GITHUB_REPOSITORY: ${{ github.repository }} |
| 116 | + PR_NUMBER: ${{ steps.inputs.outputs.pr_number }} |
| 117 | + HEAD_SHA: ${{ steps.inputs.outputs.head_sha }} |
| 118 | + DRY_RUN: ${{ steps.inputs.outputs.dry_run }} |
| 119 | + MODEL_ENDPOINT: https://${{ secrets.DATABRICKS_HOST }}/serving-endpoints/databricks-claude-opus-4-8/invocations |
| 120 | + DATABRICKS_TOKEN: ${{ secrets.DATABRICKS_TOKEN }} |
| 121 | + RUNNER_TEMP: ${{ runner.temp }} |
| 122 | + # The reviewer's repo-specific ADDITIVE guidance, read from the TRUSTED |
| 123 | + # checkout (run_review enforces containment). Engine owns the base prompt. |
| 124 | + REVIEW_SYSTEM_PROMPT: .bot/prompts/review/system.md |
| 125 | + run: python -m databricks_bot_engine.reviewer_bot.run_review |
0 commit comments