Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 7 additions & 57 deletions .github/workflows/gh-aw-estc-pr-buildkite-detective.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 26 additions & 26 deletions .github/workflows/gh-aw-estc-pr-buildkite-detective.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,27 @@ steps:
- name: Resolve event context
run: |
set -euo pipefail
echo "BK_EVENT_NAME=$GITHUB_EVENT_NAME" >> "$GITHUB_ENV"
if [ "$GITHUB_EVENT_NAME" = "status" ]; then
echo "BK_EVENT_ID=$(jq -r '.id' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV"
echo "BK_FAILURE_STATE=$(jq -r '.state' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV"
echo "BK_COMMIT_SHA=$(jq -r '.commit.sha' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV"
echo "BK_TARGET_URL=$(jq -r '.target_url // empty' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV"
echo "BK_BRANCHES=$(jq -c '[(.branches // [])[].name]' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV"
echo "BK_PR_NUMBERS=" >> "$GITHUB_ENV"
else
echo "BK_EVENT_ID=$(jq -r '.check_run.id' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV"
echo "BK_FAILURE_STATE=$(jq -r '.check_run.conclusion' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV"
echo "BK_COMMIT_SHA=$(jq -r '.check_run.head_sha' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV"
echo "BK_TARGET_URL=$(jq -r '.check_run.details_url // empty' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV"
echo "BK_BRANCHES=" >> "$GITHUB_ENV"
echo "BK_PR_NUMBERS=$(jq -rc '[(.check_run.pull_requests // [])[].number] | if length == 0 then "" else . end' "$GITHUB_EVENT_PATH")" >> "$GITHUB_ENV"
fi
mkdir -p /tmp/gh-aw
{
echo "event_name: $GITHUB_EVENT_NAME"
if [ "$GITHUB_EVENT_NAME" = "status" ]; then
echo "event_id: $(jq -r '.id' "$GITHUB_EVENT_PATH")"
echo "failure_state: $(jq -r '.state' "$GITHUB_EVENT_PATH")"
echo "commit_sha: $(jq -r '.commit.sha' "$GITHUB_EVENT_PATH")"
echo "target_url: $(jq -r '.target_url // empty' "$GITHUB_EVENT_PATH")"
echo "branches: $(jq -r '[(.branches // [])[].name] | join(", ")' "$GITHUB_EVENT_PATH")"
echo "pr_numbers:"
else
echo "event_id: $(jq -r '.check_run.id' "$GITHUB_EVENT_PATH")"
echo "failure_state: $(jq -r '.check_run.conclusion' "$GITHUB_EVENT_PATH")"
echo "commit_sha: $(jq -r '.check_run.head_sha' "$GITHUB_EVENT_PATH")"
echo "target_url: $(jq -r '.check_run.details_url // empty' "$GITHUB_EVENT_PATH")"
echo "branches:"
echo "pr_numbers: $(jq -r '[(.check_run.pull_requests // [])[].number | tostring] | join(", ")' "$GITHUB_EVENT_PATH")"
fi
} > /tmp/gh-aw/buildkite-event.txt
echo "Buildkite event context:"
cat /tmp/gh-aw/buildkite-event.txt
- name: Repo-specific setup
if: ${{ inputs.setup-commands != '' }}
env:
Expand All @@ -128,15 +133,10 @@ Analyze failed Buildkite CI builds for pull requests in ${{ github.repository }}
## Context

- **Repository**: ${{ github.repository }}
- **Event Name**: ${{ env.BK_EVENT_NAME }}
- **Event ID**: ${{ env.BK_EVENT_ID }}
- **Failure State**: ${{ env.BK_FAILURE_STATE }}
- **Commit SHA**: ${{ env.BK_COMMIT_SHA }}
- **Target URL**: ${{ env.BK_TARGET_URL }}
- **PR Numbers**: ${{ env.BK_PR_NUMBERS }}
- **Branches**: ${{ env.BK_BRANCHES }}
- **Buildkite Organization**: ${{ inputs.buildkite-org }}

**Read `/tmp/gh-aw/buildkite-event.txt` first.** It contains the event context (commit SHA, target URL, PR numbers, branches, failure state) extracted from the GitHub event payload.

## Constraints

- **CAN**: Read files, search code, run tests and commands, query Buildkite via MCP, comment on PRs
Expand Down Expand Up @@ -165,10 +165,10 @@ Classify each failure to guide your investigation:

### Step 1: Gather Context

1. Use the commit SHA provided in the Context section above. If it is empty, discover it from the PR's commit statuses or check runs.
1. Read `/tmp/gh-aw/buildkite-event.txt` to get the event context. Use the `commit_sha` value. If it is empty, discover it from the PR's commit statuses or check runs.
2. Find the associated pull request(s):
- If **PR Numbers** in the Context section above is non-empty (e.g., from `check_run` events), use those PR numbers directly with `pull_request_read` method `get`.
- Otherwise, use `bash` + `gh api repos/${{ github.repository }}/commits/{commit_sha}/pulls` to find PRs containing the commit SHA. Filter the results to keep only PRs whose `state` is `"open"` and, when **Branches** is available, whose `head.ref` matches one of the listed branches. If no candidates remain, also try searching open PRs whose head branch matches one of the **Branches** listed in the Context section.
- If `pr_numbers` is non-empty (from `check_run` events), use those PR numbers directly with `pull_request_read` method `get`.
- Otherwise, use `bash` + `gh api repos/${{ github.repository }}/commits/{commit_sha}/pulls` to find PRs containing the commit SHA. Filter the results to keep only PRs whose `state` is `"open"` and, when `branches` is non-empty, whose `head.ref` matches one of the listed branches. If no candidates remain, also try searching open PRs whose head branch matches one of the branches.
- If no PR is found after all attempts, call `noop` with message "No pull request associated with failed commit status; nothing to do" and stop.
3. For each matching PR, call `pull_request_read` with method `get` to capture the author, branches, and fork status for downstream analysis.

Expand Down
Loading