mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-04 21:04:37 +08:00
## 🤖 Installing Claude Code GitHub App This PR adds a GitHub Actions workflow that enables Claude Code integration in our repository. ### What is Claude Code? [Claude Code](https://claude.ai/code) is an AI coding agent that can help with: - Bug fixes and improvements - Documentation updates - Implementing new features - Code reviews and suggestions - Writing tests - And more! ### How it works Once this PR is merged, we'll be able to interact with Claude by mentioning @claude in a pull request or issue comment. Once the workflow is triggered, Claude will analyze the comment and surrounding context, and execute on the request in a GitHub action. ### Important Notes - **This workflow won't take effect until this PR is merged** - **@claude mentions won't work until after the merge is complete** - The workflow runs automatically whenever Claude is mentioned in PR or issue comments - Claude gets access to the entire PR or issue context including files, diffs, and previous comments ### Security - Our Anthropic API key is securely stored as a GitHub Actions secret - Only users with write access to the repository can trigger the workflow - All Claude runs are stored in the GitHub Actions run history - Claude's default tools are limited to reading/writing files and interacting with our repo by creating comments, branches, and commits. - We can add more allowed tools by adding them to the workflow file like: ``` allowed_tools: Bash(npm install),Bash(npm run build),Bash(npm run lint),Bash(npm run test) ``` There's more information in the [Claude Code action repo](https://github.com/anthropics/claude-code-action). After merging this PR, let's try mentioning @claude in a comment on any PR to get started!
113 lines
4.7 KiB
YAML
113 lines
4.7 KiB
YAML
name: "all-good: Did all the other checks pass?"
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- dev
|
|
pull_request:
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/dev' }}
|
|
|
|
jobs:
|
|
all-good:
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
REPO: ${{ github.repository }}
|
|
COMMIT: ${{ github.sha }}
|
|
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
|
|
steps:
|
|
- name: Wait for 60 seconds
|
|
run: sleep 60
|
|
|
|
- name: Poll Checks API until complete
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
echo "Checking check runs for commit ${COMMIT} in repo ${REPO}..."
|
|
|
|
function get_check_runs() {
|
|
local endpoint=$1
|
|
local response
|
|
response=$(curl -s -f -H "Authorization: Bearer ${GITHUB_TOKEN}" "$endpoint")
|
|
if [ $? -ne 0 ]; then
|
|
echo "Error fetching from $endpoint" >&2
|
|
echo "{}"
|
|
return 1
|
|
fi
|
|
echo "$response"
|
|
}
|
|
|
|
function count_pending_checks() {
|
|
local response=$1
|
|
echo "$response" | jq '([.check_runs[]? | select(.status != "completed" and .name != "all-good" and .name != "claude-review")] | length) // 0'
|
|
}
|
|
|
|
function count_failed_checks() {
|
|
local response=$1
|
|
echo "$response" | jq '([.check_runs[]? | select(.conclusion != "success" and .conclusion != "skipped" and .conclusion != "neutral" and .name != "all-good" and .name != "claude-review")] | length) // 0'
|
|
}
|
|
|
|
while true; do
|
|
# Always check the current commit's checks
|
|
commit_response=$(get_check_runs "https://api.github.com/repos/${REPO}/commits/${COMMIT}/check-runs")
|
|
commit_total=$(echo "$commit_response" | jq -r '.total_count // 0')
|
|
|
|
# If this is a PR, check the PR's head commit checks
|
|
pr_total=0
|
|
if [ -n "$PR_HEAD_SHA" ] && [ "$PR_HEAD_SHA" != "$COMMIT" ]; then
|
|
pr_response=$(get_check_runs "https://api.github.com/repos/${REPO}/commits/${PR_HEAD_SHA}/check-runs")
|
|
pr_total=$(echo "$pr_response" | jq -r '.total_count // 0')
|
|
echo "Found ${commit_total} current commit checks and ${pr_total} PR head commit checks"
|
|
else
|
|
echo "Found ${commit_total} commit checks"
|
|
fi
|
|
|
|
# If no checks found at all, wait and retry
|
|
if [ "$commit_total" -eq 0 ] && { [ -z "$PR_HEAD_SHA" ] || [ "$pr_total" -eq 0 ]; }; then
|
|
echo "No check runs found. Waiting..."
|
|
sleep 10
|
|
continue
|
|
fi
|
|
|
|
# Check for pending runs in both current and PR head commit checks
|
|
commit_pending=$(count_pending_checks "$commit_response")
|
|
pr_pending=0
|
|
if [ -n "$PR_HEAD_SHA" ] && [ "$PR_HEAD_SHA" != "$COMMIT" ]; then
|
|
pr_pending=$(count_pending_checks "$pr_response")
|
|
fi
|
|
|
|
total_pending=$((commit_pending + pr_pending))
|
|
if [ "$total_pending" -gt 0 ]; then
|
|
echo "$total_pending check run(s) still in progress. Waiting..."
|
|
sleep 10
|
|
continue
|
|
fi
|
|
|
|
# Check for failures in both current and PR head commit checks
|
|
commit_failed=$(count_failed_checks "$commit_response")
|
|
pr_failed=0
|
|
if [ -n "$PR_HEAD_SHA" ] && [ "$PR_HEAD_SHA" != "$COMMIT" ]; then
|
|
pr_failed=$(count_failed_checks "$pr_response")
|
|
fi
|
|
|
|
total_failed=$((commit_failed + pr_failed))
|
|
if [ "$total_failed" -eq 0 ]; then
|
|
echo "All check runs passed!"
|
|
exit 0
|
|
else
|
|
echo "The following check run(s) failed:"
|
|
# Failed checks on the current commit (excluding claude-review)
|
|
echo "$commit_response" | jq -r '.check_runs[] | select(.conclusion != "success" and .conclusion != "skipped" and .conclusion != "neutral" and .name != "claude-review") | .name' | sed 's/^/ - /'
|
|
# Failed checks on the PR head commit (if different, excluding claude-review)
|
|
if [ -n "$PR_HEAD_SHA" ] && [ "$PR_HEAD_SHA" != "$COMMIT" ]; then
|
|
echo "$pr_response" | jq -r '.check_runs[] | select(.conclusion != "success" and .conclusion != "skipped" and .conclusion != "neutral" and .name != "claude-review") | .name' | sed 's/^/ - /'
|
|
fi
|
|
echo "$commit_response"
|
|
echo "$pr_response"
|
|
exit 1
|
|
fi
|
|
done
|