Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

ai-review.yml

92 lines3.9 KB

1name: AI review
2​
3# The reviewer runs trusted main code. Signal metadata identifies the PR.
4# A maintainer can request one review with /ai-review or workflow_dispatch.
5#
6# Every trigger here runs in the default-branch cache scope, and the agent
7# reads text a fork controls. Never add pull_request_target, a cache step,
8# or id-token: write to this workflow. Never run the agent outside Docker.
9# See https://tanstack.com/blog/npm-supply-chain-compromise-postmortem
10​
11# The host checks out and builds main only and never runs PR files. PR code
12# runs only in the Docker sandbox, which gets XAI_API_KEY and no GitHub token.
13on: # zizmor: ignore[dangerous-triggers] The host uses no artifacts and runs no PR files.
14 workflow_run:
15 workflows: ['AI review signal']
16 types: [completed]
17 workflow_dispatch:
18 inputs:
19 pr_number:
20 description: Pull request number
21 required: true
22 type: string
23 issue_comment:
24 types: [created]
25​
26permissions: {}
27​
28jobs:
29 review:
30 name: Review
31 # Keep the login list in sync with .github/maintainers.json.
32 if: >
33 github.repository_owner == 'TanStack'
34 && ((github.event_name == 'workflow_run'
35 && github.event.workflow_run.conclusion == 'success')
36 || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main')
37 || (github.event_name == 'issue_comment'
38 && github.event.issue.pull_request
39 && startsWith(github.event.comment.body, '/ai-review')
40 && contains(fromJSON('["tombeckenham","AlemTuzlak","jherr"]'), github.event.comment.user.login)))
41 concurrency:
42 group: ai-review-${{ github.event_name == 'workflow_run' && 'source' || 'pr' }}-${{ github.event.workflow_run.head_repository.id || github.repository_id }}-${{ github.event.workflow_run.head_branch || github.event.issue.number || github.event.inputs.pr_number }}
43 cancel-in-progress: true
44 runs-on: ubuntu-latest
45 timeout-minutes: 30
46 permissions:
47 contents: read
48 steps:
49 # `ref: main` pins the checkout to trusted code for every trigger.
50 # Never build or run the PR head on the host. The script fetches the base
51 # and head commits as objects (no checkout). It creates the .pr-head
52 # worktree only for a polish patch that passed the host scan.
53 - name: Checkout
54 uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
55 with:
56 ref: main
57 fetch-depth: 0
58 persist-credentials: false
59 - name: Setup Tools
60 uses: TanStack/config/.github/setup@190f659075ff0845850e330883eb26d7ffd0671f # main
61 - name: Build packages
62 run: pnpm exec nx run-many -t build -p @tanstack/ai-grok-build @tanstack/ai-sandbox-docker
63 - name: Guard review
64 id: guard
65 env:
66 AI_REVIEW_TOKEN: ${{ secrets.AI_REVIEW_TOKEN }}
67 XAI_API_KEY: ${{ secrets.XAI_API_KEY }}
68 GH_TOKEN: ${{ secrets.AI_REVIEW_TOKEN }}
69 shell: bash
70 run: |
71 # Every trigger here runs in TanStack with secrets, so a missing
72 # secret is a broken setup. Fail red, or fork PRs go unreviewed.
73 fail() {
74 echo "::error::AI review cannot run: $1"
75 exit 1
76 }
77 if [ -z "${AI_REVIEW_TOKEN}" ] || [ -z "${XAI_API_KEY}" ]; then
78 fail "missing AI_REVIEW_TOKEN or XAI_API_KEY"
79 fi
80 MACHINE="$(gh api user --jq .login)"
81 LOGIN_PATTERN='^[A-Za-z0-9]([A-Za-z0-9-]{0,37}[A-Za-z0-9])?$'
82 if ! [[ "${MACHINE}" =~ ${LOGIN_PATTERN} ]]; then
83 fail "invalid GitHub login"
84 fi
85 echo "machine_user=${MACHINE}" >> "${GITHUB_OUTPUT}"
86 - name: Run review
87 run: pnpm ai-review
88 env:
89 AI_REVIEW_TOKEN: ${{ secrets.AI_REVIEW_TOKEN }}
90 XAI_API_KEY: ${{ secrets.XAI_API_KEY }}
91 AI_REVIEW_WORKTREE: ${{ github.workspace }}/.pr-head
92 AI_REVIEW_MACHINE_USER: ${{ steps.guard.outputs.machine_user }}