Skip to content

Commit 14141e4

Browse files
committed
Added action to remove the output of Notebooks if they've been pushed to the repo
1 parent de3648d commit 14141e4

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# .github/workflows/propagate-config.yml
2+
# This workflow keeps repos in sync
3+
name: Remove Notebook Outputs
4+
permissions:
5+
contents: write
6+
7+
on:
8+
push:
9+
push:
10+
branches:
11+
- '**'
12+
pull_request:
13+
branches:
14+
- '**'
15+
16+
17+
jobs:
18+
remove-notebook-outputs:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout source repo
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Git
25+
run: |
26+
git config --global user.name "Clear Notebook Outputs Action"
27+
git config --global user.email "[email protected]"
28+
29+
- name: Install prerequisites
30+
run: |
31+
sudo apt-get update -y
32+
33+
sudo apt-get install python3.8 -y
34+
35+
echo ✅ Install Jupyter notebook
36+
echo ✅ ------------------------
37+
# Install Jupyter notebook
38+
sudo apt-get install jupyter -y
39+
40+
- name: Clear Jupyter notebook run outputs
41+
run: |
42+
# Get all notebook files
43+
files=$(git ls-files '*.ipynb')
44+
[ -z "$files" ] && exit 0
45+
46+
for f in $files; do
47+
echo $f
48+
# Clear outputs + execution_count in place
49+
jupyter nbconvert \
50+
--ClearOutputPreprocessor.enabled=True \
51+
--inplace "$f"
52+
53+
# Re-stage cleaned file
54+
git add "$f"
55+
done
56+
57+
git commit -m "Clear notebook outputs" --no-verify
58+
git push origin HEAD:${{ github.ref_name }}

0 commit comments

Comments
 (0)