From c1c1ed2318c10258598b13da54afe2079012161a Mon Sep 17 00:00:00 2001 From: ydshieh Date: Mon, 6 Apr 2026 09:51:58 +0200 Subject: [PATCH 1/7] empty commit From d5db76494c890940ef34cf039a33ee1c5b1478f0 Mon Sep 17 00:00:00 2001 From: ydshieh Date: Mon, 6 Apr 2026 10:12:18 +0200 Subject: [PATCH 2/7] Fix GitHub workflow failing when CircleCI only runs empty job When the test fetcher determines no tests need to run, CircleCI only creates the 'empty' job (no 'collection_job'). The GitHub workflow was failing at 'Get CircleCI run artifacts' because collection_job_number was empty, causing a broken curl URL. Add an early exit with artifact_found=false when collection_job_number is empty, matching the existing graceful skip for missing artifacts. --- .github/workflows/circleci-failure-summary-comment.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/circleci-failure-summary-comment.yml b/.github/workflows/circleci-failure-summary-comment.yml index e8012430d669..8a8f6fa62f95 100644 --- a/.github/workflows/circleci-failure-summary-comment.yml +++ b/.github/workflows/circleci-failure-summary-comment.yml @@ -99,6 +99,12 @@ jobs: collection_job_id=$(echo "$jobs" | jq -r '.items[] | select(.name == "collection_job") | .id') echo "CircleCI Collection job number: ${collection_job_number}" echo "CircleCI Collection job ID: ${collection_job_id}" + + if [ -z "$collection_job_number" ]; then + echo "No collection_job found (only empty job ran - no tests were selected). Skipping." + echo "artifact_found=false" >> $GITHUB_OUTPUT + exit 0 + fi # Step 6: Get artifacts list echo "Getting artifacts for job ${collection_job_number}..." @@ -242,4 +248,4 @@ jobs: -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" \ - -f body="$(printf "View the CircleCI Test Summary for this PR:\n\n%s" "$SPACE_URL")" \ No newline at end of file + -f body="$(printf "View the CircleCI Test Summary for this PR:\n\n%s" "$SPACE_URL")" From b3554e75376d852014376c9a511481c5652cf7c1 Mon Sep 17 00:00:00 2001 From: ydshieh Date: Mon, 6 Apr 2026 10:22:27 +0200 Subject: [PATCH 3/7] More robustly handle missing collection_job and null artifacts response --- .github/workflows/circleci-failure-summary-comment.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/circleci-failure-summary-comment.yml b/.github/workflows/circleci-failure-summary-comment.yml index 8a8f6fa62f95..dc75897b6f43 100644 --- a/.github/workflows/circleci-failure-summary-comment.yml +++ b/.github/workflows/circleci-failure-summary-comment.yml @@ -95,8 +95,8 @@ jobs: "https://circleci.com/api/v2/workflow/${workflow_id}/job") # Step 5: Extract collection_job details - collection_job_number=$(echo "$jobs" | jq -r '.items[] | select(.name == "collection_job") | .job_number') - collection_job_id=$(echo "$jobs" | jq -r '.items[] | select(.name == "collection_job") | .id') + collection_job_number=$(echo "$jobs" | jq -r '[.items[] | select(.name == "collection_job") | .job_number] | first // empty') + collection_job_id=$(echo "$jobs" | jq -r '[.items[] | select(.name == "collection_job") | .id] | first // empty') echo "CircleCI Collection job number: ${collection_job_number}" echo "CircleCI Collection job ID: ${collection_job_id}" @@ -111,10 +111,10 @@ jobs: artifacts=$(curl -s \ "https://circleci.com/api/v2/project/gh/${REPO}/${collection_job_number}/artifacts") - echo "$artifacts" | jq '.' + echo "$artifacts" | jq '.' || true # Step 7: Download failure_summary.json specifically - failure_summary_url=$(echo "$artifacts" | jq -r '.items[] | select(.path == "outputs/failure_summary.json") | .url') + failure_summary_url=$(echo "$artifacts" | jq -r '.items // [] | .[] | select(.path == "outputs/failure_summary.json") | .url') if [ -z "$failure_summary_url" ]; then echo "failure_summary.json not found in artifacts - PR may not have latest main merged. Skipping." From 591825868a5a2505fa3d39e24e42a9b62cf9f75f Mon Sep 17 00:00:00 2001 From: ydshieh Date: Mon, 6 Apr 2026 10:25:59 +0200 Subject: [PATCH 4/7] Add comments explaining the defensive changes --- .github/workflows/circleci-failure-summary-comment.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/circleci-failure-summary-comment.yml b/.github/workflows/circleci-failure-summary-comment.yml index dc75897b6f43..7b7d3d368963 100644 --- a/.github/workflows/circleci-failure-summary-comment.yml +++ b/.github/workflows/circleci-failure-summary-comment.yml @@ -95,11 +95,14 @@ jobs: "https://circleci.com/api/v2/workflow/${workflow_id}/job") # Step 5: Extract collection_job details + # Use "first // empty" so the variable is truly empty (not "null") when no collection_job exists. collection_job_number=$(echo "$jobs" | jq -r '[.items[] | select(.name == "collection_job") | .job_number] | first // empty') collection_job_id=$(echo "$jobs" | jq -r '[.items[] | select(.name == "collection_job") | .id] | first // empty') echo "CircleCI Collection job number: ${collection_job_number}" echo "CircleCI Collection job ID: ${collection_job_id}" + # When only the "empty" job ran (no tests selected), there is no collection_job. + # Exit gracefully to avoid curl hitting a broken URL. if [ -z "$collection_job_number" ]; then echo "No collection_job found (only empty job ran - no tests were selected). Skipping." echo "artifact_found=false" >> $GITHUB_OUTPUT @@ -111,9 +114,11 @@ jobs: artifacts=$(curl -s \ "https://circleci.com/api/v2/project/gh/${REPO}/${collection_job_number}/artifacts") + # Print for debugging; "|| true" prevents failure if the response is not valid JSON. echo "$artifacts" | jq '.' || true # Step 7: Download failure_summary.json specifically + # Use ".items // []" to avoid "Cannot iterate over null" if the response has no .items. failure_summary_url=$(echo "$artifacts" | jq -r '.items // [] | .[] | select(.path == "outputs/failure_summary.json") | .url') if [ -z "$failure_summary_url" ]; then From c5e56b0b4f2f0cd3822ceb205bc3f2eebb3bb225 Mon Sep 17 00:00:00 2001 From: ydshieh Date: Mon, 6 Apr 2026 10:51:40 +0200 Subject: [PATCH 5/7] Improve comments and use first // empty for failure_summary_url --- .../workflows/circleci-failure-summary-comment.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/circleci-failure-summary-comment.yml b/.github/workflows/circleci-failure-summary-comment.yml index 7b7d3d368963..e8d2866a7c14 100644 --- a/.github/workflows/circleci-failure-summary-comment.yml +++ b/.github/workflows/circleci-failure-summary-comment.yml @@ -95,7 +95,9 @@ jobs: "https://circleci.com/api/v2/workflow/${workflow_id}/job") # Step 5: Extract collection_job details - # Use "first // empty" so the variable is truly empty (not "null") when no collection_job exists. + # "first // empty": if collection_job is absent or has job_number=null, jq outputs nothing + # (empty string). Without this, jq -r would output the literal string "null", making + # [ -z "$collection_job_number" ] false and bypassing the early-exit check below. collection_job_number=$(echo "$jobs" | jq -r '[.items[] | select(.name == "collection_job") | .job_number] | first // empty') collection_job_id=$(echo "$jobs" | jq -r '[.items[] | select(.name == "collection_job") | .id] | first // empty') echo "CircleCI Collection job number: ${collection_job_number}" @@ -118,8 +120,12 @@ jobs: echo "$artifacts" | jq '.' || true # Step 7: Download failure_summary.json specifically - # Use ".items // []" to avoid "Cannot iterate over null" if the response has no .items. - failure_summary_url=$(echo "$artifacts" | jq -r '.items // [] | .[] | select(.path == "outputs/failure_summary.json") | .url') + # .items // [] : use empty array if .items is null (avoids "Cannot iterate over null") + # .[] : iterate over each artifact object in the array + # select(...) : keep only the artifact whose .path matches + # | .url : extract the download URL from the matched artifact + # first // empty: take the first match; outputs nothing (not "null") if no match found + failure_summary_url=$(echo "$artifacts" | jq -r '[.items // [] | .[] | select(.path == "outputs/failure_summary.json") | .url] | first // empty') if [ -z "$failure_summary_url" ]; then echo "failure_summary.json not found in artifacts - PR may not have latest main merged. Skipping." From c6a9cc9ba5cb361b91be84e9e9b02361dea77855 Mon Sep 17 00:00:00 2001 From: ydshieh Date: Mon, 6 Apr 2026 11:05:17 +0200 Subject: [PATCH 6/7] fix --- .github/workflows/circleci-failure-summary-comment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/circleci-failure-summary-comment.yml b/.github/workflows/circleci-failure-summary-comment.yml index e8d2866a7c14..c7010c3de6d5 100644 --- a/.github/workflows/circleci-failure-summary-comment.yml +++ b/.github/workflows/circleci-failure-summary-comment.yml @@ -1,7 +1,7 @@ name: CircleCI Failure Summary Comment on: - pull_request_target: + pull_request: types: [opened, synchronize, reopened] jobs: From 6e90acf87ba960a492bdf210d6f54d8a3f9d8154 Mon Sep 17 00:00:00 2001 From: ydshieh Date: Mon, 6 Apr 2026 11:13:50 +0200 Subject: [PATCH 7/7] clean --- .github/workflows/circleci-failure-summary-comment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/circleci-failure-summary-comment.yml b/.github/workflows/circleci-failure-summary-comment.yml index c7010c3de6d5..e8d2866a7c14 100644 --- a/.github/workflows/circleci-failure-summary-comment.yml +++ b/.github/workflows/circleci-failure-summary-comment.yml @@ -1,7 +1,7 @@ name: CircleCI Failure Summary Comment on: - pull_request: + pull_request_target: types: [opened, synchronize, reopened] jobs: