|
| 1 | +name: Build ipynb [using QuantEcon/mystmd] |
| 2 | +on: [pull_request] |
| 3 | +jobs: |
| 4 | + build-ipynb: |
| 5 | + runs-on: ubuntu-latest |
| 6 | + steps: |
| 7 | + - uses: actions/checkout@v4 |
| 8 | + |
| 9 | + - uses: actions/setup-node@v4 |
| 10 | + with: |
| 11 | + node-version: 22.x |
| 12 | + |
| 13 | + - name: Install Python |
| 14 | + uses: actions/setup-python@v5 |
| 15 | + with: |
| 16 | + python-version: '3.12' |
| 17 | + cache: 'pip' |
| 18 | + cache-dependency-path: 'myst_requirements.txt' |
| 19 | + |
| 20 | + - name: Install execution requirements |
| 21 | + run: python -m pip install -r myst_requirements.txt |
| 22 | + |
| 23 | + - name: Clone QuantEcon/mystmd (myst-to-ipynb branch) |
| 24 | + run: | |
| 25 | + git clone --depth 1 --branch myst-to-ipynb https://github.com/QuantEcon/mystmd.git /tmp/mystmd |
| 26 | +
|
| 27 | + - name: Build mystmd from source |
| 28 | + working-directory: /tmp/mystmd |
| 29 | + run: | |
| 30 | + npm ci |
| 31 | + npx turbo run build |
| 32 | +
|
| 33 | + - name: Build HTML with custom mystmd |
| 34 | + working-directory: ./lectures |
| 35 | + run: /tmp/mystmd/packages/mystmd/dist/myst.cjs build --html |
| 36 | + |
| 37 | + - name: Build ipynb exports with custom mystmd |
| 38 | + working-directory: ./lectures |
| 39 | + run: /tmp/mystmd/packages/mystmd/dist/myst.cjs build --ipynb |
| 40 | + |
| 41 | + - name: Audit notebooks for MyST syntax leaks |
| 42 | + working-directory: ./lectures |
| 43 | + run: | |
| 44 | + python3 -c " |
| 45 | + import json, glob, re, sys |
| 46 | + PATTERNS = [ |
| 47 | + (r'^\s*:::', 'directive fence'), |
| 48 | + (r'\{math\}\`', 'math role'), |
| 49 | + (r'^\+\+\+', 'block marker'), |
| 50 | + (r'\{doc\}\`', 'doc role'), |
| 51 | + (r'\{index\}', 'index directive'), |
| 52 | + (r'\`\`\`\{', 'fenced directive'), |
| 53 | + (r'^\([a-z_][a-z0-9_-]*\)=\$', 'target label'), |
| 54 | + ] |
| 55 | + issues = 0 |
| 56 | + for nb_path in sorted(glob.glob('exports/*.ipynb')): |
| 57 | + with open(nb_path) as f: |
| 58 | + nb = json.load(f) |
| 59 | + for i, cell in enumerate(nb.get('cells', []), 1): |
| 60 | + if cell.get('cell_type') != 'markdown': |
| 61 | + continue |
| 62 | + source = ''.join(cell.get('source', [])) |
| 63 | + for line in source.split('\n'): |
| 64 | + for pat, desc in PATTERNS: |
| 65 | + if re.search(pat, line.strip()): |
| 66 | + print(f'{nb_path} cell {i}: [{desc}] {line.strip()[:80]}') |
| 67 | + issues += 1 |
| 68 | + if issues: |
| 69 | + print(f'\n{issues} MyST syntax leaks found!') |
| 70 | + sys.exit(1) |
| 71 | + else: |
| 72 | + print(f'All {len(glob.glob(\"exports/*.ipynb\"))} notebooks clean.') |
| 73 | + " |
| 74 | +
|
| 75 | + - name: Upload ipynb exports |
| 76 | + uses: actions/upload-artifact@v4 |
| 77 | + with: |
| 78 | + name: ipynb-exports |
| 79 | + path: './lectures/exports/' |
0 commit comments