From 9c5559a006d2ae8aaed6eca1a2b61b6134f2a863 Mon Sep 17 00:00:00 2001 From: Richard Darst Date: Wed, 13 Mar 2024 18:23:01 +0200 Subject: [PATCH] Add basic recipe checks --- .github/workflows/check-recipes.yml | 27 +++++++++++++++++++++++++++ check_recipes.py | 22 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 .github/workflows/check-recipes.yml create mode 100644 check_recipes.py diff --git a/.github/workflows/check-recipes.yml b/.github/workflows/check-recipes.yml new file mode 100644 index 0000000..aa7fa0f --- /dev/null +++ b/.github/workflows/check-recipes.yml @@ -0,0 +1,27 @@ +# This workflow will check that each recipe has an "Instructions" and +# "Ingredients" Markdown section (line starting with `#`). +name: Basic recipe checks + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + check: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.x" + - name: Test with pytest + run: | + python check_recipes.py diff --git a/check_recipes.py b/check_recipes.py new file mode 100644 index 0000000..0929a95 --- /dev/null +++ b/check_recipes.py @@ -0,0 +1,22 @@ +import glob +from pathlib import Path +import re +import sys + +ingredients_re = re.compile('^#.*ingredients', re.IGNORECASE|re.MULTILINE) +instructions_re = re.compile('^#.*instructions', re.IGNORECASE|re.MULTILINE) + +base = Path('.') +print(f"Checking recipes in {str(base.absolute())}:") + +errors = 0 +for path in base.glob('*/*.md'): + if not ingredients_re.search(path.read_text()): + print(f'::error file={str(path)},title=Ingredients missing::File is missing an ingredients section: "# Ingredients"') + errors += 1 + if not instructions_re.search(path.read_text()): + print(f'::error file={str(path)},title=Instructions missing::File is missing an instructions section: "# Instructions"') + errors += 1 +print(f"{errors} errors") +if errors: + sys.exit(1)