trying something out #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CircleCI Failure Summary Comment | |
| # Requires repository secrets: | |
| # - CIRCLE_TOKEN: API token with permission to query CircleCI pipelines | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| jobs: | |
| comment: | |
| runs-on: ubuntu-22.04 | |
| permissions: | |
| pull-requests: write | |
| env: | |
| TARGET_BRANCH: ${{ github.event.pull_request.head.ref }} | |
| TARGET_SHA: ${{ github.event.pull_request.head.sha }} | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.13" | |
| - name: Install dependencies | |
| run: python -m pip install requests | |
| - name: Wait for CircleCI check suite completion | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| COMMIT_SHA: ${{ github.event.pull_request.head.sha }} | |
| github_repository: ${{ github.repository }} | |
| run: | | |
| echo "Waiting for CircleCI check suite to complete..." | |
| end=$((SECONDS+1800)) | |
| while [ $SECONDS -lt $end ]; do | |
| suite_json=$(gh api "repos/${github_repository}/commits/${COMMIT_SHA}/check-suites" --jq '.check_suites[] | select(.app.slug=="circleci-checks")') | |
| if [ -z "$suite_json" ]; then | |
| echo "CircleCI check suite not found yet, retrying..." | |
| else | |
| status=$(echo "$suite_json" | jq -r '.status') | |
| conclusion=$(echo "$suite_json" | jq -r '.conclusion // empty') | |
| echo "Current CircleCI check suite status: $status (conclusion: $conclusion)" | |
| if [ "$status" = "completed" ] && [ -n "$conclusion" ]; then | |
| break | |
| fi | |
| fi | |
| sleep 20 | |
| done | |
| if [ $SECONDS -ge $end ]; then | |
| echo "Timed out waiting for CircleCI check suite." | |
| exit 1 | |
| fi | |
| - name: Find CircleCI workflow | |
| id: circleci | |
| env: | |
| CIRCLE_TOKEN: ${{ secrets.CIRCLE_TOKEN }} | |
| run: | | |
| WORKFLOW_ID=$(python scripts/find_circleci_workflow.py --branch "$TARGET_BRANCH" --sha "$TARGET_SHA") | |
| echo "workflow_id=$WORKFLOW_ID" >> $GITHUB_OUTPUT | |
| - name: Generate failure summary | |
| env: | |
| CIRCLE_TOKEN: ${{ secrets.CIRCLE_TOKEN }} | |
| run: | | |
| python utils/process_circleci_workflow_test_reports.py --workflow_id "${{ steps.circleci.outputs.workflow_id }}" | |
| - name: Post comment with failure summary | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GITHUB_RUN_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| github_repository: ${{ github.repository }} | |
| pr_number: ${{ github.event.pull_request.number }} | |
| run: | | |
| if [ ! -f outputs/failure_summary.json ]; then | |
| echo "failure_summary.json missing, skipping comment." | |
| exit 0 | |
| fi | |
| failures=$(python -c "import json; print(len(json.load(open('outputs/failure_summary.json'))['failures']))") | |
| if [ "$failures" -eq 0 ]; then | |
| echo "No failures detected, skipping PR comment." | |
| exit 0 | |
| fi | |
| body="$(cat outputs/failure_summary.md)" | |
| gh api \ | |
| --method POST \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "X-GitHub-Api-Version: 2022-11-28" \ | |
| "repos/${github_repository}/issues/${pr_number}/comments" \ | |
| -f body="$body" |