Skip to content

Guides as notebooks #39

Guides as notebooks

Guides as notebooks #39

---
name: Update Tutorials
on:
pull_request:
branches: [develop]
paths: [tutorials/**]
jobs:
update-tutorials:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/[email protected]
with:
fetch-depth: 0 # Fetch all history for all branches and tags
- name: Set up Python 3.9
uses: actions/[email protected]
with:
python-version: "3.9"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install nbconvert pyyaml jupyter
- name: Clear notebook outputs
run: |
find tutorials -name "*.ipynb" -exec jupyter nbconvert --ClearOutputPreprocessor.enabled=True --inplace {} \;
- name: Update Tutorials
id: update_tutorials
run: python scripts/update_tutorials.py
- name: Debug Outputs
run: |
echo "Available outputs:"
cat $GITHUB_OUTPUT
- name: Check for changes
id: git-check
run: |
git add tutorials docs/book
git status
changed_files=$(git diff --staged --name-only)
if [ -n "$changed_files" ]; then
echo "changes=true" >> $GITHUB_OUTPUT
echo "changed_files<<EOF" >> $GITHUB_OUTPUT
echo "$changed_files" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
fi
- name: Use Outputs
if: steps.git-check.outputs.changes == 'true'
run: |
echo "Suggested TOC for Starter Guide:"
echo "${{ steps.update_tutorials.outputs.suggested_toc_starter_guide }}"
echo "Retained files for Starter Guide:"
echo "${{ steps.update_tutorials.outputs.retained_files_starter_guide }}"
- name: Commit changes
if: steps.git-check.outputs.changes == 'true'
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
changed_files="${{ steps.git-check.outputs.changed_files }}"
num_changed=$(echo "$changed_files" | wc -l)
if [ $num_changed -eq 1 ]; then
file=$(echo "$changed_files" | tr -d '\n')
commit_message="Update tutorial: ${file##*/}"
else
commit_message="Update ${num_changed} tutorial files"
fi
git commit -m "$commit_message"
- name: Push changes
if: steps.git-check.outputs.changes == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.head_ref }}
- name: Create PR comment
if: steps.git-check.outputs.changes == 'true'
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |-
const prNumber = context.payload.pull_request.number;
const changedFiles = `${{ steps.git-check.outputs.changed_files }}`.split('\n');
let commentBody = '### Tutorial Update Summary\n\n';
commentBody += 'The following files have been updated:\n\n';
changedFiles.forEach(file => {
commentBody += `- \`${file}\`\n`;
});
commentBody += '\nPlease review these changes.\n\n';
try {
await github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
} catch (error) {
console.error('Error creating comment:', error);
core.setFailed(`Failed to create comment: ${error.message}`);
}