Skip to content

Commit 330f99b

Browse files
authored
Refactor notebook rendering workflow
Updated workflow to render notebooks for GitHub, added checks for changes, and improved Python version specification.
1 parent b54873b commit 330f99b

1 file changed

Lines changed: 30 additions & 23 deletions

File tree

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
name: Render for GitHub
1+
name: Render Notebooks for GitHub
22

33
on:
4-
pull_request:
5-
branches:
6-
- main
74
push:
85
paths:
96
- '**.ipynb'
7+
pull_request:
8+
branches:
9+
- main
1010
workflow_dispatch: # Allows manual triggering
1111

1212
permissions:
@@ -22,39 +22,46 @@ jobs:
2222
uses: actions/checkout@v4
2323
with:
2424
fetch-depth: 0
25+
ref: ${{ github.head_ref || github.ref_name }} # Explicitly checkout the branch that triggered the workflow
2526

2627
- name: Set up Python
2728
uses: actions/setup-python@v4
2829
with:
29-
python-version: '3.x'
30+
python-version: '3.10'
3031

3132
- name: Install dependencies
3233
run: |
3334
python -m pip install --upgrade pip
3435
pip install nbformat nbconvert jupyter
3536
36-
- name: Configure Git
37+
- name: Run conversion script
38+
run: python .github/workflows/convert_notebooks.py
39+
40+
- name: Configure Git
3741
run: |
3842
git config --global user.email "github-actions[bot]@users.noreply.github.com"
3943
git config --global user.name "github-actions[bot]"
4044
41-
- name: Render notebooks for GitHub
42-
run: python .github/workflows/render_notebooks.py
43-
44-
- name: Commit changes
45-
env:
46-
TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
- name: Check for changes
46+
id: git-check
4747
run: |
48-
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
49-
git fetch origin ${{ github.event.pull_request.head.ref }}
50-
git pull --rebase origin ${{ github.event.pull_request.head.ref }} || echo "No rebase needed"
51-
git add "**/*.ipynb"
52-
git commit -m "Render notebooks for GitHub compatibility" || echo "No changes to commit"
53-
git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
54-
git push origin HEAD:${{ github.event.pull_request.head.ref }}
48+
if [[ -n "$(git status --porcelain **/*.ipynb)" ]]; then
49+
echo "has_changes=true" >> $GITHUB_OUTPUT
5550
else
56-
git add "**/*.ipynb"
57-
git commit -m "Render notebooks for GitHub compatibility" || echo "No changes to commit"
58-
git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
59-
git push origin ${{ github.ref_name }}
51+
echo "has_changes=false" >> $GITHUB_OUTPUT
6052
fi
53+
54+
- name: Show modified files
55+
if: steps.git-check.outputs.has_changes == 'true'
56+
run: git status
57+
58+
- name: Commit and push changes to current branch
59+
if: steps.git-check.outputs.has_changes == 'true'
60+
run: |
61+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
62+
echo "Current branch: $CURRENT_BRANCH"
63+
64+
# Add, commit, and push changes
65+
git add "**/*.ipynb"
66+
git commit -m "Render notebooks for GitHub compatibility"
67+
git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git HEAD:${CURRENT_BRANCH}

0 commit comments

Comments
 (0)