fix: feat: supervisor auto-retriggers CI after infra-only exhaustion (#185)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
a4877b58db
commit
051ff39144
2 changed files with 174 additions and 0 deletions
|
|
@ -15,3 +15,45 @@ ci_passed() {
|
|||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
# classify_pipeline_failure <repo_id> <pipeline_num>
|
||||
# Classifies a pipeline's failure type by inspecting all failed steps.
|
||||
# Outputs "infra" if every failed step is a git step with exit code 128 or 137.
|
||||
# Outputs "code" otherwise (including when steps cannot be determined).
|
||||
# Returns 0 for infra, 1 for code or unclassifiable.
|
||||
classify_pipeline_failure() {
|
||||
local repo_id="$1" pip_num="$2"
|
||||
local pip_json failed_steps all_infra _sname _ecode
|
||||
|
||||
pip_json=$(woodpecker_api "/repos/${repo_id}/pipelines/${pip_num}" 2>/dev/null) || {
|
||||
echo "code"; return 1
|
||||
}
|
||||
|
||||
failed_steps=$(printf '%s' "$pip_json" | jq -r '
|
||||
.workflows[]?.children[]? |
|
||||
select(.state == "failure" or .state == "error" or .state == "killed") |
|
||||
"\(.name)\t\(.exit_code)"' 2>/dev/null)
|
||||
|
||||
if [ -z "$failed_steps" ]; then
|
||||
echo "code"; return 1
|
||||
fi
|
||||
|
||||
all_infra=true
|
||||
while IFS=$'\t' read -r _sname _ecode; do
|
||||
[ -z "$_sname" ] && continue
|
||||
# git step with exit 128 (connection/rate-limit) or 137 (OOM) → infra
|
||||
if [[ "$_sname" == git* ]] && { [ "$_ecode" = "128" ] || [ "$_ecode" = "137" ]; }; then
|
||||
: # infra step — continue checking remaining steps
|
||||
else
|
||||
all_infra=false
|
||||
break
|
||||
fi
|
||||
done <<< "$failed_steps"
|
||||
|
||||
if [ "$all_infra" = true ]; then
|
||||
echo "infra"
|
||||
return 0
|
||||
fi
|
||||
echo "code"
|
||||
return 1
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue