summaryrefslogtreecommitdiff
path: root/.github
diff options
context:
space:
mode:
authorSteven Hall <Hallzy.18@gmail.com>2021-03-23 05:39:30 -0700
committerGitHub <noreply@github.com>2021-03-23 08:39:30 -0400
commitbcef14fb3f2e1e0732b78323d6158e2b0321d9e0 (patch)
treec8170c321160de3c83682e139982f0b37761c952 /.github
parentf9a6b43d56eb24c79d69b4601ea58494a9faf14d (diff)
Improved the PR check script (#426)
* Improved the PR check script * Added check to make sure that only lowercase alpha characters and hyphens are in the tag list * Brought back the set -eu
Diffstat (limited to '.github')
-rwxr-xr-x.github/workflows/scripts/check-files.sh93
1 files changed, 59 insertions, 34 deletions
diff --git a/.github/workflows/scripts/check-files.sh b/.github/workflows/scripts/check-files.sh
index 48cb4af..428649b 100755
--- a/.github/workflows/scripts/check-files.sh
+++ b/.github/workflows/scripts/check-files.sh
@@ -36,13 +36,17 @@ check_recipe_name() {
}
check_recipe_content() {
- awk '
+ errMsgs="$(awk '
BEGIN {
- HAS_TITLE = 0;
- HAS_TAGS = 0;
- NUM_TAGS = 0;
- HAS_INGREDIENTS = 0;
- HAS_DIRECTIONS = 0;
+ HAS_TITLE = 0;
+ HAS_TAGS = 0;
+ HAS_INVALID_TAGS = 0;
+ NUM_TAGS = 0;
+ HAS_INGREDIENTS = 0;
+ HAS_DIRECTIONS = 0;
+ HAS_CONSECUTIVE_EMPTY_LINES = 0;
+
+ CONSECUTIVE_EMPTY_LINES = 0;
}
# First line should be the title
@@ -51,14 +55,23 @@ check_recipe_content() {
next;
}
- /^## Ingredients/ {
+ $0 == "## Ingredients" {
HAS_INGREDIENTS = 1;
- next;
}
- /^## Directions/ {
+ $0 == "## Directions" {
HAS_DIRECTIONS = 1;
- next;
+ }
+
+ $0 == "" {
+ CONSECUTIVE_EMPTY_LINES++
+ if (CONSECUTIVE_EMPTY_LINES >= 2) {
+ HAS_CONSECUTIVE_EMPTY_LINES = 1;
+ }
+ }
+
+ $0 != "" {
+ CONSECUTIVE_EMPTY_LINES = 0;
}
END {
@@ -66,63 +79,75 @@ check_recipe_content() {
if ($1 == ";tags:") {
HAS_TAGS = 1;
NUM_TAGS = NF - 1;
- }
- FAIL = 0;
+ # Loop through all the tags
+ for (i = 2; i <= NF; i++) {
+ # Make sure that each tag only contains lowercase letters and hyphens
+ if ($i !~ "^[a-z-]+$") {
+ HAS_INVALID_TAGS = 1;
+ break;
+ }
+ }
+ }
if (!HAS_TITLE) {
print "Recipe does not have a properly formatted title on the first line."
- FAIL = 1;
}
if (!HAS_TAGS) {
print "Recipe does not have a properly formatted tags on the last line."
- FAIL = 1;
- } else if (NUM_TAGS < 2) {
- print "Recipe only has " NUM_TAGS " tags. Add some more."
- FAIL = 1;
- } else if (NUM_TAGS > 5) {
- print "Recipe has " NUM_TAGS " tags which is too many. Remove some tags."
- FAIL = 1;
+ } else {
+ if (HAS_INVALID_TAGS) {
+ print "Recipe has invalid tags. Tags must be separated by spaces and contain only lowercase letters or hyphens (-)";
+ }
+
+ if (NUM_TAGS < 2) {
+ print "Recipe only has " NUM_TAGS " tags. Add some more."
+ } else if (NUM_TAGS > 5) {
+ print "Recipe has " NUM_TAGS " tags which is too many. Remove some tags."
+ }
}
if (!HAS_INGREDIENTS) {
print "Recipe does not have an ingredients list."
- FAIL = 1;
}
if (!HAS_DIRECTIONS) {
print "Recipe does not have a directions section."
- FAIL = 1;
}
- if (FAIL) {
- exit 1;
+ if (HAS_CONSECUTIVE_EMPTY_LINES) {
+ print "Recipe has at least 2 consecutive empty lines.";
}
}
- ' "$1"
+ ' "$1")"
- if [ $? -ne 0 ]; then
+ if [ -n "$errMsgs" ]; then
+ echo "$errMsgs"
FAIL=1
fi
}
-git diff --name-only "$(git merge-base origin/master HEAD)" | while IFS= read -r file; do
+while IFS= read -r file; do
+ echo "Checking '$file'"
case "$file" in
+ # Ignore these files
+ index.md) ;;
+ .github/*.md) ;;
+
*.webp)
- echo "Checking size of $file"
check_size "$file"
check_webp_name "$file"
;;
- .github/*.md)
- # Ignore markdown files in .github
- continue;
- ;;
*.md)
check_recipe_name "$file"
check_recipe_content "$file"
;;
- esac
-done
+ esac
+ # Separate each file for easier reading.
+ echo ""
+done <<EOF
+$(git diff --name-only "$(git merge-base origin/master HEAD)")
+EOF
exit $FAIL