name: Verify examples on: workflow_call: inputs: python_version: description: 'Python version.' required: false default: '3.10' type: string jobs: VerifyDocs: name: 👍 Verify example snippets using Python ${{ inputs.python_version }} runs-on: ubuntu-latest steps: - name: ⏬ Checkout repository uses: actions/checkout@v2 - name: 🐍 Setup Python uses: actions/setup-python@v2 with: python-version: ${{ inputs.python_version }} - name: 🐍 Install dependencies run: | pip3 install . - name: ✂ Extract code snippet from README shell: python run: | from pathlib import Path import re ROOT = Path('.') with (ROOT / 'README.md').open('r') as rptr: content = rptr.read() m = re.search(r"```py(thon)?(?P.*?)```", content, re.MULTILINE|re.DOTALL) if m is None: raise Exception("Regular expression did not find the example in the README!") with (ROOT / 'tests/docs/example.py').open('w') as wptr: wptr.write(m["code"]) - name: Print example.py run: cat tests/docs/example.py - name: ☑ Run example snippet working-directory: tests/docs run: | python3 example.py