Skip to content

Commit

Permalink
Relax title, section and task names
Browse files Browse the repository at this point in the history
As of Mermaid 10.8, these characters are no longer unsafe.

See:
* mermaid-js/mermaid#1981
* mermaid-js/mermaid#5095
* https://github.com/mermaid-js/mermaid/releases/tag/v10.8.0
  • Loading branch information
pcolby committed Feb 5, 2024
1 parent 0ba6ae6 commit 6930ad6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
10 changes: 10 additions & 0 deletions test/data/pcolby-ww-7763520889.pre
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
displayMode: compact
---
gantt
title Test (run 7763520889, attempt 1)
dateFormat YYYY-MM-DDTHH:MM:SS.SSSZ
%% https://github.com/pcolby/ww/actions/runs/7763520889

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

section check
Set up job :2024-02-03T12:20:33.000+11:00, 1s
section #;#;check#;#;
#;#;Set up job#;#; :2024-02-03T12:20:33.000+11:00, 1s
5 changes: 5 additions & 0 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@ while IFS= read -d '' -r fileName; do
export TEST_RUN_FILE="${fileName}" TEST_JOBS_FILE="${fileName%.json}-jobs.json"
"${PROJECT_SOURCE_DIR}/ww.sh" "${owner}" "${repo}" "${runId}" "${attemptNumber}" >| "${fileName%.json}.out"
diff --color=auto --unified "${fileName%.json}".{txt,out}
[[ ! -e "${fileName%.json}.pre" ]] || {
echo "Test: ${testName}-pre"
PRE_MERMAID_10_8=true "${PROJECT_SOURCE_DIR}/ww.sh" "${owner}" "${repo}" "${runId}" "${attemptNumber}" >| "${fileName%.json}.out"
diff --color=auto --unified "${fileName%.json}".{pre,out}
}
done < <(find "${TEST_DATA_DIR}" -name '*.json' -not -name '*-jobs.json' -print0 || :)
echo 'All tests passed.'
10 changes: 5 additions & 5 deletions ww.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ readonly API_PATH="/repos/${owner}/${repo}/actions/runs/${runId}${attemptNumber:
# Generate Mermaid Gantt chart header.
[[ -v TEST_RUN_FILE ]] && workflowRun=$(cat "${TEST_RUN_FILE}") || workflowRun=$(gh api "${API_PATH}")
#jq . <<< "$workflowRun" >| "./test/data/$owner-$repo-$runId${attemptNumber:+-${attemptNumber}}.json"
jq -er --arg displayMode "${DISPLAY_MODE}" "$(cat <<-"-" || :
def safe(s): s|gsub("[;#]";""); # Note, `:` is ok in titles.
jq -er --arg displayMode "${DISPLAY_MODE}" --arg unsafeChars "${PRE_MERMAID_10_8:+;#}" "$(cat <<-"-" || :
def safe(s): if ($unsafeChars|length) > 0 then s|gsub("[;#]";"") else s end;
"---\ndisplayMode: " + $displayMode + "\n---\ngantt\n" +
" title " + safe(.name) + " (run " + (.id|tostring) + ", attempt " + (.run_attempt|tostring) + ")\n" +
" dateFormat YYYY-MM-DDTHH:MM:SS.SSSZ\n %% "+ .html_url
Expand All @@ -44,10 +44,10 @@ jq -er --arg displayMode "${DISPLAY_MODE}" "$(cat <<-"-" || :
# Generate Mermaid Gantt chart sections.
[[ -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"
jq -er --argjson minStepDuration "${MIN_STEP_DURATION}" "$(cat <<-"-" || :
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);
def safe(s): s|gsub("[:;#]";"");
def isodiff(d1;d2): isodate(d2)-isodate(d1);
def safe(s): s|gsub("["+$unsafeChars+"]";"");
.jobs[]|"\n section " + safe(.name) + "\n" + ([
.steps[]|select(.completed_at)|
(.+{duration:isodiff(.started_at;.completed_at)})|
Expand Down

0 comments on commit 6930ad6

Please sign in to comment.