From b5828a5ec03d5fc67860c0f656f4abca3947cced Mon Sep 17 00:00:00 2001 From: Kendall Gassner Date: Wed, 5 Jul 2023 10:23:10 -0700 Subject: [PATCH] Flag images without alt text (#26) * Flag images without alt text * add exit on failure * add todo; * uncomment * flag images without alt --- action.yml | 4 +-- flag-alt-text.sh | 23 ++++++++----- test-flag-alt-text.sh | 78 ++++++++++++++++++++++++------------------- 3 files changed, 60 insertions(+), 45 deletions(-) diff --git a/action.yml b/action.yml index e2c6757..5a54ece 100644 --- a/action.yml +++ b/action.yml @@ -59,8 +59,8 @@ runs: Learn more about alt text at [Basic writing and formatting syntax: images on GitHub Docs](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#images)." flag="$(flagAltText "$content")" - echo $flag - echo $type + echo "Detected bad alt text: ${flag}" + echo "Event type: $type" if [[ $flag = true ]]; then if [[ $type = pr_comment ]] || [[ $type = pr_description ]]; then diff --git a/flag-alt-text.sh b/flag-alt-text.sh index d9003fb..2eb16f4 100644 --- a/flag-alt-text.sh +++ b/flag-alt-text.sh @@ -1,13 +1,18 @@ #!/bin/bash flagAltText() { - markdownMacOsScreenshotRegex="^.*!\[(Clean|Screen) ?[S|s]hot [0-9][0-9][0-9][0-9]-[0-1][0-9]-[0-9][0-9].*\].*$" - semanticMacOsScreenshotRegex="^.*' - # html - 'image' - 'Screen shot 2020-01-01 at 12.00.00.png' - 'Screen Shot 2020-01-01 at 12.00.00.png' - 'Screenshot 2020-01-01 at 12.00.00.png' - 'CleanShot 2020-01-01 @12x' + # markdown + '![Cleanshot 2020-01-01 at 12.00.00.png]' + '![Clean shot 2020-12-01 @12x]' + "![Clean shot 2020-12-01 @12x]" + "![Screen Shot 2020-01-01 at 12.00.00.png]" + "![Screenshot 2020-01-01 at 12.00.00.png]" + "![image]" + "![Image]" + "![]" + "Check this: ![Image]" + "My awesome ![image]" + 'Check this out: image' + # html + 'image' + '' + "" + "" + '' + '' + 'Screen shot 2020-01-01 at 12.00.00.png' + 'Screen Shot 2020-01-01 at 12.00.00.png' + 'Screenshot 2020-01-01 at 12.00.00.png' + 'CleanShot 2020-01-01 @12x' ) declare -a should_be_false=( - # markdown - "![Screenshot of the new GitHub home page]" - "![Screen shot of Submit button with updated color contrast.]" - "![Image of a cat]" - # html - 'Mona Lisa, the Octocat' - 'Screenshot of the new danger button with a dark red shade' - 'Clean shot of the scenery' + # markdown + "![Screenshot of the new GitHub home page]" + "![Screen shot of Submit button with updated color contrast.]" + "![Image of a cat]" + # html + 'Mona Lisa, the Octocat' + 'Mona Lisa, the Octocat' + 'Screenshot of the new danger button with a dark red shade' + 'Clean shot of the scenery' ) echo "******Expecting true:*******" -for i in "${should_be_true[@]}" -do - echo "Testing: $i" - assert_true "$(flagAltText "$i")" "$i must be true" +for i in "${should_be_true[@]}"; do + echo "Testing: $i" + assert_true "$(flagAltText "$i")" "$i must be true" + if [ $? == 1 ]; then + exit 1 + fi done echo "******Expecting false:*******" -for i in "${should_be_false[@]}" -do - echo "Testing: $i" - assert_false "$(flagAltText "$i")" "$i must be false" +for i in "${should_be_false[@]}"; do + echo "Testing: $i" + assert_false "$(flagAltText "$i")" "$i must be false" + if [ $? == 1 ]; then + exit 1 + fi done -