From f80f6f4a62f391b1b543d08e377dfb9c39669f0e Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Wed, 15 Jul 2026 04:36:15 -0400 Subject: [PATCH] [Fix] (CI): retain fixtures for failed retraces --- .github/workflows/apk.yml | 41 +++++++++++++++++++++++++++++++------- .github/workflows/test.yml | 41 +++++++++++++++++++++++++++++++------- 2 files changed, 68 insertions(+), 14 deletions(-) diff --git a/.github/workflows/apk.yml b/.github/workflows/apk.yml index a224237f..e6909d99 100644 --- a/.github/workflows/apk.yml +++ b/.github/workflows/apk.yml @@ -489,14 +489,41 @@ jobs: env: GH_TOKEN: ${{ github.token }} run: | - mapfile -t artifacts < <( + declare -A failed_cases=() + while IFS= read -r job_name; do + case_name="${job_name#retrace (*, }" + case_name="${case_name%)}" + failed_cases["${case_name}"]=1 + done < <( + gh api --paginate "repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/jobs?per_page=100" \ + --jq '.jobs[] | select(.name | startswith("retrace (")) | select(.conclusion == "failure" or .conclusion == "cancelled" or .conclusion == "timed_out" or .conclusion == "action_required") | .name' + ) + + if ((${#failed_cases[@]})); then + echo "Retaining fixtures for failed retrace case(s):" + printf ' %s\n' "${!failed_cases[@]}" + else + echo "All retrace jobs succeeded; no fixtures need to be retained." + fi + + deleted=0 + retained=0 + while IFS=$'\t' read -r artifact_id artifact_name; do + if [[ "${artifact_name}" == MobileGL-trace-fixture-* ]]; then + case_name="${artifact_name#MobileGL-trace-fixture-}" + if [[ -v "failed_cases[${case_name}]" ]]; then + echo "Retaining ${artifact_name} (${artifact_id}) for failed retrace." + ((retained += 1)) + continue + fi + fi + + echo "Deleting ${artifact_name} (${artifact_id})" + gh api --method DELETE "repos/${GITHUB_REPOSITORY}/actions/artifacts/${artifact_id}" + ((deleted += 1)) + done < <( gh api --paginate "repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/artifacts?per_page=100" \ --jq '.artifacts[] | select(.name | startswith("MobileGL-trace-fixture-") or startswith("MobileGL-android-retrace-result-") or startswith("trace-fixture-") or startswith("retrace-result-")) | [.id, .name] | @tsv' ) - echo "Found ${#artifacts[@]} intermediate Android artifact(s)." - for artifact in "${artifacts[@]}"; do - IFS=$'\t' read -r artifact_id artifact_name <<<"${artifact}" - echo "Deleting ${artifact_name} (${artifact_id})" - gh api --method DELETE "repos/${GITHUB_REPOSITORY}/actions/artifacts/${artifact_id}" - done + echo "Deleted ${deleted} intermediate Android artifact(s); retained ${retained} failed-retrace fixture(s)." diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5273a851..33032a5e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -519,14 +519,41 @@ jobs: env: GH_TOKEN: ${{ github.token }} run: | - mapfile -t artifacts < <( + declare -A failed_cases=() + while IFS= read -r job_name; do + case_name="${job_name#retrace (*, }" + case_name="${case_name%)}" + failed_cases["${case_name}"]=1 + done < <( + gh api --paginate "repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/jobs?per_page=100" \ + --jq '.jobs[] | select(.name | startswith("retrace (")) | select(.conclusion == "failure" or .conclusion == "cancelled" or .conclusion == "timed_out" or .conclusion == "action_required") | .name' + ) + + if ((${#failed_cases[@]})); then + echo "Retaining fixtures for failed retrace case(s):" + printf ' %s\n' "${!failed_cases[@]}" + else + echo "All retrace jobs succeeded; no fixtures need to be retained." + fi + + deleted=0 + retained=0 + while IFS=$'\t' read -r artifact_id artifact_name; do + if [[ "${artifact_name}" == trace-fixture-* ]]; then + case_name="${artifact_name#trace-fixture-}" + if [[ -v "failed_cases[${case_name}]" ]]; then + echo "Retaining ${artifact_name} (${artifact_id}) for failed retrace." + ((retained += 1)) + continue + fi + fi + + echo "Deleting ${artifact_name} (${artifact_id})" + gh api --method DELETE "repos/${GITHUB_REPOSITORY}/actions/artifacts/${artifact_id}" + ((deleted += 1)) + done < <( gh api --paginate "repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/artifacts?per_page=100" \ --jq '.artifacts[] | select(.name | startswith("trace-fixture-") or startswith("retrace-result-")) | [.id, .name] | @tsv' ) - echo "Found ${#artifacts[@]} intermediate Linux artifact(s)." - for artifact in "${artifacts[@]}"; do - IFS=$'\t' read -r artifact_id artifact_name <<<"${artifact}" - echo "Deleting ${artifact_name} (${artifact_id})" - gh api --method DELETE "repos/${GITHUB_REPOSITORY}/actions/artifacts/${artifact_id}" - done + echo "Deleted ${deleted} intermediate Linux artifact(s); retained ${retained} failed-retrace fixture(s)."