mirror of
https://github.com/pyTooling/Actions.git
synced 2026-02-12 02:56:56 +08:00
add reusable workflows
This commit is contained in:
56
.github/workflows/VerifyDocs.yml
vendored
Normal file
56
.github/workflows/VerifyDocs.yml
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
name: Verify examples
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
pyver:
|
||||
description: 'Python version.'
|
||||
required: false
|
||||
default: '3.10'
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
|
||||
VerifyDocs:
|
||||
name: 👍 Verify example snippets using Python ${{ inputs.pyver }}
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: ⏬ Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: 🐍 Setup Python
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: ${{ inputs.pyver }}
|
||||
|
||||
- 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<code>.*?)```", 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
|
||||
Reference in New Issue
Block a user