From e38946d916a6f1663bf842ff4efdc958e0bfab3b Mon Sep 17 00:00:00 2001 From: Kendall Gassner Date: Wed, 28 Jun 2023 00:45:31 +0000 Subject: [PATCH 1/5] Flag images without alt text --- action.yml | 4 +-- flag-alt-text.sh | 22 +++++++++------ test-flag-alt-text.sh | 65 ++++++++++++++++++++++++------------------- 3 files changed, 51 insertions(+), 40 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..a0ab1ab 100644 --- a/flag-alt-text.sh +++ b/flag-alt-text.sh @@ -1,13 +1,17 @@ #!/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" + echo "Testing: $i" + assert_true "$(flagAltText "$i")" "$i must be true" done echo "******Expecting false:*******" for i in "${should_be_false[@]}" do - echo "Testing: $i" - assert_false "$(flagAltText "$i")" "$i must be false" + echo "Testing: $i" + assert_false "$(flagAltText "$i")" "$i must be false" done From 9d09e655541ad8fe7573b6e8fc67a461835d52fd Mon Sep 17 00:00:00 2001 From: Kendall Gassner Date: Wed, 28 Jun 2023 01:11:34 +0000 Subject: [PATCH 2/5] add exit on failure --- test-flag-alt-text.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test-flag-alt-text.sh b/test-flag-alt-text.sh index 4716006..45dd080 100755 --- a/test-flag-alt-text.sh +++ b/test-flag-alt-text.sh @@ -48,6 +48,10 @@ 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:*******" @@ -55,5 +59,8 @@ 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 From c99d18f37b35b219ea176175bc4a68234c4ace39 Mon Sep 17 00:00:00 2001 From: Kendall Gassner Date: Wed, 28 Jun 2023 02:00:42 +0000 Subject: [PATCH 3/5] add todo; --- flag-alt-text.sh | 3 +-- test-flag-alt-text.sh | 30 ++++++++++++++---------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/flag-alt-text.sh b/flag-alt-text.sh index a0ab1ab..6dde1e0 100644 --- a/flag-alt-text.sh +++ b/flag-alt-text.sh @@ -6,10 +6,9 @@ flagAltText() { markdownImageRegex="^.*!\[(i|I)mage\].*$" semanticImageRegex="^.*' '' - "" - '' - '' - '' + "" + # TODO: add flag for these cases + # "" + # '' + # '' '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' @@ -44,23 +45,20 @@ declare -a should_be_false=( ) echo "******Expecting true:*******" -for i in "${should_be_true[@]}" -do +for i in "${should_be_true[@]}"; do echo "Testing: $i" assert_true "$(flagAltText "$i")" "$i must be true" - if [ $? == 1 ]; then - exit 1 - fi - + # if [ $? == 1 ]; then + # exit 1 + # fi + done echo "******Expecting false:*******" -for i in "${should_be_false[@]}" -do +for i in "${should_be_false[@]}"; do echo "Testing: $i" assert_false "$(flagAltText "$i")" "$i must be false" - if [ $? == 1 ]; then - exit 1 - fi + # if [ $? == 1 ]; then + # exit 1 + # fi done - From 7a1f4100348356cb004c1cc3e3187ae305469c61 Mon Sep 17 00:00:00 2001 From: Kendall Gassner Date: Wed, 28 Jun 2023 02:01:00 +0000 Subject: [PATCH 4/5] uncomment --- test-flag-alt-text.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/test-flag-alt-text.sh b/test-flag-alt-text.sh index eb01e0e..1214908 100755 --- a/test-flag-alt-text.sh +++ b/test-flag-alt-text.sh @@ -48,17 +48,16 @@ echo "******Expecting 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 - + 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" - # if [ $? == 1 ]; then - # exit 1 - # fi + if [ $? == 1 ]; then + exit 1 + fi done From 475fc118447fdfcf10e3c74aec825c684abd4a7a Mon Sep 17 00:00:00 2001 From: Kendall Gassner Date: Wed, 5 Jul 2023 15:51:58 +0000 Subject: [PATCH 5/5] flag images without alt --- flag-alt-text.sh | 6 ++++-- test-flag-alt-text.sh | 7 +++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/flag-alt-text.sh b/flag-alt-text.sh index 6dde1e0..2eb16f4 100644 --- a/flag-alt-text.sh +++ b/flag-alt-text.sh @@ -4,11 +4,13 @@ flagAltText() { markdownMacOsScreenshotRegex="^.*!\[(Clean|Screen) ?[S|s]hot [0-9][0-9][0-9][0-9]-[0-1][0-9]-[0-9][0-9].*\].*$" semanticMacOsScreenshotRegex="^.*' '' "" - # TODO: add flag for these cases - # "" - # '' - # '' + "" + '' + '' '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'