Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/deployer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,47 @@ on:

jobs:

tutorials: #################################################################
runs-on: ubuntu-latest
env:
TUTORIAL_TIMEOUT: 1200s
steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
python3 -m pip install --upgrade pip .[tutorial] black[jupyter]

- name: Setup FFmpeg
uses: FedericoCarboni/setup-ffmpeg@v2

- name: Run formatter
run: black tutorials/

- name: Export tutorials to .html
run: |
set -x
for file in $(find tutorials -type f -name "*.ipynb"); do
filename=$(basename $file)
htmlfilename="${filename%.ipynb}.html"
htmldir="docs/source"/$(dirname $file)
mkdir -p $htmldir
timeout --signal=SIGKILL $TUTORIAL_TIMEOUT python -Xfrozen_modules=off -m jupyter nbconvert --execute $file --to html --output $htmlfilename --output-dir=$htmldir
break
done
set +x

- name: Remove unwanted files
run: |
rm -rf build/ tutorials/tutorial4/data/

- name: Upload tutorials artifact
uses: actions/upload-artifact@v4
with:
name: tutorials
path: |
docs/source/tutorials/**/*.html

docs: #######################################################################
runs-on: ubuntu-latest
steps:
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/tester.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ jobs:
- name: Install Python dependencies
run: python3 -m pip install .[doc]

- name: Create placeholder tutorial HTMLs
run: |
set -e
for nb in tutorials/*.ipynb; do
nbname=$(basename "$nb" .ipynb)
html_dir="docs/source/tutorials/$nbname"
mkdir -p "$html_dir"
echo "<html><body><h1>Placeholder for $nbname</h1><p>This tutorial will be generated by the export workflow.</p></body></html>" > "$html_dir/tutorial.html"
done

- name: Build Documentation
run: |
make html SPHINXOPTS+='-W'
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/tutorial_dynamical_tester.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: "Testing Tutorials RUn"

on:
workflow_dispatch:
schedule:
- cron: '20 2 1 * *'

jobs:
# run on push
test_tutorials:
runs-on: ubuntu-latest
env:
TUTORIAL_TIMEOUT: 1200s
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9

- name: Install dependencies
run: |
python3 -m pip install --upgrade pip .[tutorial] black[jupyter]

- name: Setup FFmpeg
uses: FedericoCarboni/setup-ffmpeg@v2

- name: Run formatter (check only)
run: black --check tutorials/

- name: Execute all tutorials
run: |
set -euo pipefail
for file in $(find tutorials -type f -name "*.ipynb"); do
echo "Running tutorial: $file"
timeout --signal=SIGKILL $TUTORIAL_TIMEOUT \
python -Xfrozen_modules=off -m jupyter nbconvert \
--execute --to notebook --inplace $file
done
236 changes: 105 additions & 131 deletions .github/workflows/tutorial_exporter.yml
Original file line number Diff line number Diff line change
@@ -1,140 +1,114 @@
name: "Export Tutorials"
name: "Export Tutorial on Comment"

on:
workflow_dispatch:
push:
branches:
- "dev"
- "master"
paths:
- 'tutorials/**/*.ipynb'
issue_comment:
types: [created]

jobs:
# run on push
export_tutorials_on_push:
if: ${{ github.event_name == 'push' }}
permissions: write-all
export_on_comment:
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/tutorial-exporter')
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: read
env:
TUTORIAL_TIMEOUT: 1200s

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9

- name: Install dependencies
run: |
# Dependencies for tutorials
python3 -m pip install --upgrade pip .[tutorial] black[jupyter]
- name: Setup FFmpeg
uses: FedericoCarboni/setup-ffmpeg@v2

- id: files
uses: jitterbit/get-changed-files@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
format: space-delimited

- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email 41898282+github-actions[bot]@users.noreply.github.com

- name: Run formatter
run: black tutorials/

- name: Export tutorials to .py and .html
run: |
set -x
for file in ${{ steps.files.outputs.all }}; do
if [[ $file == *.ipynb ]]; then
filename=$(basename $file)
pyfilename=$(echo ${filename%?????})py
timeout --signal=SIGKILL $TUTORIAL_TIMEOUT python -Xfrozen_modules=off -m jupyter nbconvert $file --to python --output $pyfilename --output-dir=$(dirname $file)
htmlfilename=$(echo ${filename%?????} | sed -e 's/-//g')html
htmldir="docs/source"/$(echo ${file%??????????????} | sed -e 's/-//g')
timeout --signal=SIGKILL $TUTORIAL_TIMEOUT python -Xfrozen_modules=off -m jupyter nbconvert --execute $file --to html --output $htmlfilename --output-dir=$htmldir
# Detect PR branch from comment
- name: Get PR branch from comment
uses: xt0rted/pull-request-comment-branch@v1
id: comment-branch

- name: Set latest commit status as pending
uses: myrotvorets/set-commit-status-action@master
with:
sha: ${{ steps.comment-branch.outputs.head_sha }}
token: ${{ secrets.GITHUB_TOKEN }}
status: pending

# Checkout the PR branch
- name: Checkout PR branch ${{ steps.comment-branch.outputs.head_ref }}
uses: actions/checkout@v3
with:
ref: ${{ steps.comment-branch.outputs.head_ref }}

# Setup Python
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.10

# Install dependencies
- name: Install dependencies
run: python3 -m pip install --upgrade pip .[tutorial] black[jupyter]

# Setup FFmpeg (if needed)
- name: Setup FFmpeg
uses: FedericoCarboni/setup-ffmpeg@v2

# Format notebooks
- name: Run formatter
run: black tutorials/

# Export the tutorial to .py
- name: Export tutorial to .py
run: |
set -euo pipefail
COMMENT_BODY="${{ github.event.comment.body }}"
TUTORIAL_NUM=$(echo "$COMMENT_BODY" | awk '{print $2}')
FILE="tutorials/tutorial${TUTORIAL_NUM}.ipynb"

if [[ -f "$FILE" ]]; then
echo "Exporting $FILE"
PYFILENAME="${FILE%.ipynb}.py"
timeout --signal=SIGKILL $TUTORIAL_TIMEOUT \
python -Xfrozen_modules=off -m jupyter nbconvert \
"$FILE" --to python --output "$PYFILENAME" --output-dir=$(dirname "$FILE")
else
echo "Tutorial $TUTORIAL_NUM not found: $FILE"
exit 1
fi
done
set +x

- uses: benjlevesque/[email protected]
id: short-sha

- name: Remove unwanted files
run: |
rm -rf build/ tutorials/tutorial4/data/

- name: Create Pull Request
uses: peter-evans/[email protected]
with:
labels: maintenance
title: Export tutorial changed in ${{ steps.short-sha.outputs.sha }}
branch: export-tutorial-${{ steps.short-sha.outputs.sha }}
base: ${{ github.head_ref }}
commit-message: export tutorials changed in ${{ steps.short-sha.outputs.sha }}
delete-branch: true

# run on workflow_dispatch
export_tutorials_workflow_dispatch:
if: ${{ github.event_name == 'workflow_dispatch' }}
permissions: write-all
runs-on: ubuntu-latest
env:
TUTORIAL_TIMEOUT: 1200s
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9

- name: Install dependencies
run: |
python3 -m pip install --upgrade pip .[tutorial] black[jupyter]

- name: Setup FFmpeg
uses: FedericoCarboni/setup-ffmpeg@v2

- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email 41898282+github-actions[bot]@users.noreply.github.com

- name: Run formatter
run: black tutorials/

- name: Export all tutorials to .py and .html
run: |
set -x
# Find all .ipynb files in the tutorials directory
for file in $(find tutorials -type f -name "*.ipynb"); do
filename=$(basename $file)
pyfilename="${filename%.ipynb}.py"
timeout --signal=SIGKILL $TUTORIAL_TIMEOUT python -Xfrozen_modules=off -m jupyter nbconvert $file --to python --output $pyfilename --output-dir=$(dirname $file)
htmlfilename="${filename%.ipynb}.html"
htmldir="docs/source"/$(dirname $file)
timeout --signal=SIGKILL $TUTORIAL_TIMEOUT python -Xfrozen_modules=off -m jupyter nbconvert --execute $file --to html --output $htmlfilename --output-dir=$htmldir
done
set +x

- uses: benjlevesque/[email protected]
id: short-sha

- name: Remove unwanted files
run: |
rm -rf build/ tutorials/tutorial4/data/

- name: Create Pull Request
uses: peter-evans/[email protected]
with:
labels: maintenance
title: Export tutorial changed in ${{ steps.short-sha.outputs.sha }}
branch: export-tutorial-${{ steps.short-sha.outputs.sha }}
base: ${{ github.head_ref }}
commit-message: export tutorials changed in ${{ steps.short-sha.outputs.sha }}
delete-branch: true

# Create a PR
- uses: benjlevesque/[email protected]
id: short-sha

- name: Remove unwanted files
run: |
rm -rf build/
rm -rf tutorials/tutorial12/SegTrackv2/

- name: Create Pull Request
uses: peter-evans/[email protected]
with:
labels: maintenance
title: Export tutorial to .py in ${{ steps.short-sha.outputs.sha }}
branch: export-tutorial-${{ steps.short-sha.outputs.sha }}
commit-message: export tutorial to .py in ${{ steps.short-sha.outputs.sha }}
delete-branch: true

- name: Add workflow result as comment on PR
uses: actions/github-script@v6
if: always()
with:
script: |
const name = '${{ github.workflow }}';
const url = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}';
const success = '${{ job.status }}' === 'success';
const body = `${name}: ${success ? 'succeeded ✅' : 'failed ❌'}\n${url}`;

await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
})

- name: Set latest commit status as ${{ job.status }}
uses: myrotvorets/set-commit-status-action@master
if: always()
with:
sha: ${{ steps.comment-branch.outputs.head_sha }}
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
Loading
Loading