Skip to content

Commit

Permalink
added script and workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mr8lu committed Jul 11, 2024
1 parent edcc766 commit b62ad8b
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/lint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import nbformat
from nbformat.v4 import new_notebook

def clean_notebook(file_path):
with open(file_path, 'r', encoding='utf-8') as f:
notebook = nbformat.read(f, as_version=4)

# Clean cells
for cell in notebook.cells:
if 'outputs' in cell:
cell['outputs'] = []
if 'execution_count' in cell:
cell['execution_count'] = None
if 'metadata' in cell:
cell['metadata'] = {}

# Clean notebook metadata
if 'metadata' in notebook:
notebook['metadata'] = {}

with open(file_path, 'w', encoding='utf-8') as f:
nbformat.write(notebook, f)


if __name__ == "__main__":
import os

# Change this to the directory containing your notebooks
notebook_dir = '../../'

for root, dirs, files in os.walk(notebook_dir):
for file in files:
if file.endswith('.ipynb'):
file_path = os.path.join(root, file)
clean_notebook(file_path)
print(f'Cleaned {file_path}')
41 changes: 41 additions & 0 deletions .github/workflows/notebook-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: 'Lint Notebook'
on:
push:
branches:
- dev/lint
permissions:
contents: write
id-token: write

jobs:
gather_stats:
name: 'Gather Stats'
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
working-directory: .github/workflows
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'

- name: Install requirements.txt
run: |
python3 -m pip install --upgrade pip
pip3 install nbformat
- name: Generate reports
working-directory: .github/workflows
run: |
python3 lint.py
- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
author_name: github-action
author_email: [email protected]
message: 'Github Action: Refresh stats'

0 comments on commit b62ad8b

Please sign in to comment.