-
Notifications
You must be signed in to change notification settings - Fork 1
94 lines (81 loc) · 3.04 KB
/
Copy pathvalidate-notebooks.yml
File metadata and controls
94 lines (81 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
name: Validate Notebooks
on:
push:
branches: [main]
paths: ['notebooks/**']
pull_request:
branches: [main]
paths: ['notebooks/**']
jobs:
validate:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.11', '3.12']
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip packages
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install nbformat nbconvert jupyter-client ipykernel
pip install qiskit qiskit-aer numpy scipy matplotlib
- name: Validate notebook format
run: |
python -c "
import nbformat
import glob
import sys
errors = []
notebooks = sorted(glob.glob('notebooks/*.ipynb'))
print(f'Found {len(notebooks)} notebooks')
for nb_path in notebooks:
try:
with open(nb_path, 'r', encoding='utf-8') as f:
nb = nbformat.read(f, as_version=4)
# Check notebook has cells
if len(nb.cells) == 0:
errors.append(f'{nb_path}: Empty notebook (no cells)')
# Check for at least one markdown cell (documentation)
md_cells = [c for c in nb.cells if c.cell_type == 'markdown']
if len(md_cells) == 0:
errors.append(f'{nb_path}: No markdown cells found')
# Check for at least one code cell
code_cells = [c for c in nb.cells if c.cell_type == 'code']
if len(code_cells) == 0:
errors.append(f'{nb_path}: No code cells found')
print(f' OK: {nb_path} ({len(md_cells)} md, {len(code_cells)} code)')
except Exception as e:
errors.append(f'{nb_path}: {str(e)}')
if errors:
print('\nErrors found:')
for e in errors:
print(f' ERROR: {e}')
sys.exit(1)
else:
print(f'\nAll {len(notebooks)} notebooks validated successfully!')
"
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check for large files
run: |
find . -type f -size +10M -not -path './.git/*' | while read f; do
echo "WARNING: Large file detected: $f ($(du -h "$f" | cut -f1))"
done
- name: Check for secrets
run: |
if grep -r "ibm_quantum\|YOUR_TOKEN\|api_key\s*=" notebooks/ --include="*.ipynb" -l; then
echo "WARNING: Possible API tokens found in notebooks. Please verify these are placeholder values."
fi