Skip to content

chore: align badges and workflows with org template #1

chore: align badges and workflows with org template

chore: align badges and workflows with org template #1

name: Validate and Fix Notebook
on:
pull_request:
branches:
- main
permissions:
contents: write
jobs:
validate-and-fix-notebook:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install Jupyter and nbformat
run: pip install jupyter nbformat
- name: Validate and fix notebooks
run: |
python - <<'PY'
import glob
import sys
import nbformat
files = glob.glob('**/*.ipynb', recursive=True)
if not files:
print('No notebooks found.')
sys.exit(0)
for file_path in files:
with open(file_path, 'r', encoding='utf-8') as handle:
notebook = nbformat.read(handle, as_version=4)
nbformat.validate(notebook)
widgets = notebook.metadata.setdefault('widgets', {})
widget_state = widgets.setdefault(
'application/vnd.jupyter.widget-state+json',
{'version': '1.0', 'state': {}},
)
widget_state.setdefault('state', {})
with open(file_path, 'w', encoding='utf-8') as handle:
nbformat.write(notebook, handle)
PY
- name: Configure Git
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Commit changes
run: |
git fetch origin
git checkout -B "${{ github.event.pull_request.head.ref }}" "origin/${{ github.event.pull_request.head.ref }}"
git add -A
git commit -m "Fix notebook format issues" || echo "No changes to commit"
git pull --rebase origin "${{ github.event.pull_request.head.ref }}" || echo "No rebase needed"
git push origin HEAD:"${{ github.event.pull_request.head.ref }}"