Skip to content

Commit

Permalink
Add basic recipe checks
Browse files Browse the repository at this point in the history
  • Loading branch information
rkdarst committed Mar 13, 2024
1 parent 990cea4 commit 9c5559a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/check-recipes.yml
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions check_recipes.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 9c5559a

Please sign in to comment.