Skip to content

Commit

Permalink
Add a Mermaid comment with timing summary info
Browse files Browse the repository at this point in the history
  • Loading branch information
pcolby committed Feb 19, 2024
1 parent 70366f9 commit 4c15f2e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
2 changes: 2 additions & 0 deletions test/data/pcolby-dokit-7750792226.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ gantt
title Build and Test (run 7750792226, attempt 1)
dateFormat YYYY-MM-DDTHH:MM:SS.SSSZ
%% https://github.com/pcolby/dokit/actions/runs/7750792226
%% duration: 34 mins (2022 secs) elapsed, 8.6 hrs (30860 secs) total.
%% duration: 34 mins (2056 secs) elapsed, 16 mins (969 secs) total.

section linux0 (clang, clang++, false)
Set up job :2024-02-02T14:00:22.000+11:00, 1s
Expand Down
1 change: 1 addition & 0 deletions test/data/pcolby-nfc-quick-settings-7694544723.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ gantt
title Build (run 7694544723, attempt 1)
dateFormat YYYY-MM-DDTHH:MM:SS.SSSZ
%% https://github.com/pcolby/nfc-quick-settings/actions/runs/7694544723
%% duration: 19 secs elapsed, 9.3 mins (558 secs) total.

section build (ubuntu-latest)
Set up job :2024-01-29T21:22:45.000+11:00, 2s
Expand Down
1 change: 1 addition & 0 deletions test/data/pcolby-ww-7763520889.pre
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ gantt
title Test (run 7763520889, attempt 1)
dateFormat YYYY-MM-DDTHH:MM:SS.SSSZ
%% https://github.com/pcolby/ww/actions/runs/7763520889
%% duration: 0 secs elapsed, 2 secs total.

section check
Set up job :2024-02-03T12:20:33.000+11:00, 1s
1 change: 1 addition & 0 deletions test/data/pcolby-ww-7763520889.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ gantt
title #;#;Test#;#; (run 7763520889, attempt 1)
dateFormat YYYY-MM-DDTHH:MM:SS.SSSZ
%% https://github.com/pcolby/ww/actions/runs/7763520889
%% duration: 0 secs elapsed, 2 secs total.

section #;#;:check#;#;:
#;#;Set up job#;#; :2024-02-03T12:20:33.000+11:00, 1s
31 changes: 28 additions & 3 deletions ww.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function showUsage {
-
}

# Parse the CLI's postional arguments.
# Parse the CLI's positional arguments.
if [[ $# -eq 1 ]]; then
read -r owner repo runId attemptNumber < <(
sed -Ene 's|.*/([^/]*)/([^/]*)/actions/runs/([0-9]+)(/attempts/([0-9]+))?$|\1 \2 \3 \5|p' <<< "$1" || :
Expand All @@ -30,9 +30,11 @@ fi

readonly API_PATH="/repos/${owner}/${repo}/actions/runs/${runId}${attemptNumber:+/attempts/${attemptNumber}}"

# Generate Mermaid Gantt chart header.
# Fetch the workflow run data.
[[ -v TEST_RUN_FILE ]] && workflowRun=$(cat "${TEST_RUN_FILE}") || workflowRun=$(gh api "${API_PATH}")
#jq . <<< "$workflowRun" >| "./test/data/$owner-$repo-$runId${attemptNumber:+-${attemptNumber}}.json"

# Generate Mermaid Gantt chart header.
jq -er --arg displayMode "${DISPLAY_MODE}" --arg unsafeChars "${PRE_MERMAID_10_8:+;#}" "$(cat <<-"-" || :
def safeTitle(s): if ($unsafeChars|length) > 0 then s|gsub("["+$unsafeChars+"]";"") else s end;
"---\ndisplayMode: " + $displayMode + "\n---\ngantt\n" +
Expand All @@ -41,9 +43,32 @@ jq -er --arg displayMode "${DISPLAY_MODE}" --arg unsafeChars "${PRE_MERMAID_10_8
-
)" <<< "${workflowRun}"

# Generate Mermaid Gantt chart sections.
# Fetch the worflow run jobs data.
[[ -v TEST_JOBS_FILE ]] && workflowRunJobs=$(cat "${TEST_JOBS_FILE}") || workflowRunJobs=$(gh api "${API_PATH}/jobs" --paginate)
#jq . <<< "$workflowRunJobs" >| "./test/data/$owner-$repo-$runId${attemptNumber:+-${attemptNumber}}-jobs.json"

# Add some summary metadata.
jq -er "$(cat <<-"-" || :
def roundto(n): (n|exp10)*.|round/(n|exp10);
def duration:
if .>86400 then ./86400|roundto(1)|tostring+" days"
elif .>36000 then ./3600|round|tostring+" hrs"
elif .>7200 then ./3600|roundto(1)|tostring+" hrs"
elif .>600 then ./60|round|tostring+" mins"
elif .>120 then ./60|roundto(1)|tostring+" mins"
else .|roundto(1)|tostring+" secs"
end;
def format: .|duration + if .>120 then " ("+(.|tostring)+" secs)" else "" end;
def isodiff(d1;d2): (d2|fromdate)-(d1|fromdate);
{
elapsed: isodiff([.jobs[].started_at]|min;[.jobs[].started_at]|max),
total: [.jobs[]|isodiff(.started_at;.completed_at)]|add
}
|" %% duration: "+(.elapsed|format)+" elapsed, "+(.total|format)+" total."
-
)" <<< "${workflowRunJobs}"

# Generate Mermaid Gantt chart sections.
jq -er --argjson minStepDuration "${MIN_STEP_DURATION}" --arg unsafeChars "${PRE_MERMAID_10_8:+;#}" "$(cat <<-"-" || :
def isodate(d): d|strptime("%FT%T.000%z")|mktime;
def isodiff(d1;d2): isodate(d2)-isodate(d1);
Expand Down

0 comments on commit 4c15f2e

Please sign in to comment.