Created
July 14, 2025 06:48
-
-
Save iwata/6737ce61fb868f814cc23057fd9b9138 to your computer and use it in GitHub Desktop.
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
# Function to get job runtimes for a specific workflow and job | |
get_job_runtimes() { | |
local workflow_file=$1 | |
local job_name=$2 | |
echo "Analyzing $workflow_file - $job_name" | |
# Get recent successful runs | |
run_ids=$(gh run list --workflow "$workflow_file" --limit 30 --json status,databaseId,conclusion | \ | |
jq -r '.[] | select(.conclusion=="success") | .databaseId' | head -20) | |
if [ -z "$run_ids" ]; then | |
echo " No successful runs found" | |
return | |
fi | |
# Collect runtimes | |
runtimes=() | |
for run_id in $run_ids; do | |
runtime=$(gh run view $run_id --json jobs 2>/dev/null | \ | |
jq -r ".jobs[] | select(.name==\"$job_name\") | ((.completedAt | fromdateiso8601) - (.startedAt | fromdateiso8601)) / 60" 2>/dev/null) | |
if [ ! -z "$runtime" ] && [ "$runtime" != "null" ]; then | |
runtimes+=($runtime) | |
fi | |
done | |
if [ ${#runtimes[@]} -eq 0 ]; then | |
echo " No runtime data available" | |
return | |
fi | |
# Sort runtimes | |
sorted_runtimes=($(printf '%s\n' "${runtimes[@]}" | sort -n)) | |
# Calculate 95th percentile | |
count=${#sorted_runtimes[@]} | |
index=$(( (count * 95 + 99) / 100 - 1 )) | |
if [ $index -ge $count ]; then | |
index=$((count - 1)) | |
fi | |
p95=${sorted_runtimes[$index]} | |
# Round up to nearest minute | |
p95_minutes=$(echo "$p95" | awk '{print int($1 + 0.999)}') | |
echo " Samples: $count" | |
echo " 95th percentile: $p95 minutes" | |
echo " Recommended timeout: $p95_minutes minutes" | |
echo "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment