Skip to content

Commit 4965128

Browse files
authored
+ validate_and_fix_notebook.yml
1 parent 8ecf50b commit 4965128

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Validate and Fix Notebook
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
validate-and-fix-notebook:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Set up Python
25+
uses: actions/setup-python@v4
26+
with:
27+
python-version: '3.x'
28+
29+
- name: Install Jupyter and nbformat
30+
run: |
31+
pip install jupyter nbformat
32+
33+
- name: Validate and Fix Notebook
34+
run: |
35+
python -c "
36+
import nbformat
37+
import glob
38+
for file in glob.glob('**/*.ypyb', recursive=True):
39+
with open(file, 'r') as f:
40+
nb = nbformat.read(f, as_version=4)
41+
nbformat.validate(nb)
42+
if 'application/vnd.beylor-adapt+notebook' not in nb.metadata:
43+
nb.metadata['application/vnd.beylor-adapt+notebook'] = {'version': '1.0'}
44+
with open(file, 'w') as f:
45+
nbformat.write(nb, f)
46+
"
47+
48+
- name: Configure Git
49+
run: |
50+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
51+
git config --global user.name "github-actions[bot]"
52+
53+
- name: Commit changes
54+
run: |
55+
git add -A
56+
git commit -m "Fix notebook format issues" || echo "No changes to commit"
57+
git push origin HEAD:${{ github.event.pull_request.head.ref }}

0 commit comments

Comments
 (0)