diff --git a/.github/workflows/generate-readme.yaml b/.github/workflows/generate-readme.yaml new file mode 100644 index 0000000..75351b9 --- /dev/null +++ b/.github/workflows/generate-readme.yaml @@ -0,0 +1,33 @@ +name: Autogenerate README + +on: + pull_request: {} + +jobs: + generate-readme: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r .utils/requirements.txt + + - name: Generate README + run: python .utils/generate_readme.py + + - name: Check for uncommitted README changes + run: | + git add README.md + git diff --cached --exit-code || { + echo "::error::README.md is out of date or modified manually. Please re-run the generate_readme script and commit the result."; + exit 1; + } diff --git a/.utils/generate_readme.py b/.utils/generate_readme.py index a311641..84d46c3 100644 --- a/.utils/generate_readme.py +++ b/.utils/generate_readme.py @@ -36,7 +36,7 @@ def extract_metadata(readme_path): metadata = yaml.safe_load(match.group(1)) except yaml.YAMLError as e: print("Error parsing YAML metadata in", readme_path, ":", e) - return None + raise e return metadata diff --git a/CONTRIBUTING b/CONTRIBUTING index ce78843..c1b03f6 100644 --- a/CONTRIBUTING +++ b/CONTRIBUTING @@ -18,5 +18,5 @@ To contribute a tutorial, please follow these steps: - `blog_post_url` - the url to blog post (optional) - `video_url` - the url to the video (optional) - `visualize_url` - the url to Foxglove visualization (optional) - -When creating a merge request, a GitHub action should automatically regenerate the README based on your metadata. To test it yourself, you can run the python script `.utils/generate_readme.py` in the root of this repo. +4. Install generate_readme.py dependencies: `pip install -r .utils/requirements.txt` +5. Regenerate the main README.md by running `python .utils/generate_readme.py` from the root of the repo