|
| 1 | +name: "Export tutorials" |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - "**" # Run on push on all branches |
| 7 | + paths: |
| 8 | + - 'tutorials/**/*.ipynb' |
| 9 | + |
| 10 | +jobs: |
| 11 | + export_tutorials: |
| 12 | + permissions: write-all |
| 13 | + runs-on: ubuntu-latest |
| 14 | + env: |
| 15 | + TUTORIAL_TIMEOUT: 1200s |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Set up Python |
| 20 | + uses: actions/setup-python@v5 |
| 21 | + with: |
| 22 | + python-version: 3.8 |
| 23 | + |
| 24 | + - name: Install dependencies |
| 25 | + run: | |
| 26 | + # Dependencies for tutorials |
| 27 | + python3 -m pip install --upgrade pip .[tutorial] black[jupyter] |
| 28 | + - name: Setup FFmpeg |
| 29 | + uses: FedericoCarboni/setup-ffmpeg@v2 |
| 30 | + |
| 31 | + - id: files |
| 32 | + uses: jitterbit/get-changed-files@v1 |
| 33 | + with: |
| 34 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + format: space-delimited |
| 36 | + |
| 37 | + - name: Configure git |
| 38 | + run: | |
| 39 | + git config user.name "github-actions[bot]" |
| 40 | + git config user.email 41898282+github-actions[bot]@users.noreply.github.com |
| 41 | + - name: Export tutorials to .py and .html |
| 42 | + run: | |
| 43 | + set -x |
| 44 | + for file in ${{ steps.files.outputs.all }}; do |
| 45 | + if [[ $file == *.ipynb ]]; then |
| 46 | + filename=$(basename $file) |
| 47 | + pyfilename=$(echo ${filename%?????})py |
| 48 | + timeout --signal=SIGKILL $TUTORIAL_TIMEOUT python -Xfrozen_modules=off -m jupyter nbconvert --execute $file --to python --output $pyfilename --output-dir=$(dirname $file) |
| 49 | + htmlfilename=$(echo ${filename%?????} | sed -e 's/-//g')html |
| 50 | + htmldir="docs/source"/$(echo ${file%?????} | sed -e 's/-//g')html |
| 51 | + timeout --signal=SIGKILL $TUTORIAL_TIMEOUT python -Xfrozen_modules=off -m jupyter nbconvert --execute $file --to html --output $htmlfilename --output-dir=$htmldir |
| 52 | + fi |
| 53 | + done |
| 54 | + set +x |
| 55 | + |
| 56 | + - name: Run formatter |
| 57 | + run: black tutorials/ |
| 58 | + |
| 59 | + - uses: benjlevesque/[email protected] |
| 60 | + id: short-sha |
| 61 | + |
| 62 | + - name: Remove unwanted files |
| 63 | + run: | |
| 64 | + rm -rf build/ |
| 65 | + - name: Create Pull Request |
| 66 | + uses: peter-evans/[email protected] |
| 67 | + with: |
| 68 | + labels: maintenance |
| 69 | + title: Export tutorial changed in ${{ steps.short-sha.outputs.sha }} |
| 70 | + branch: export-tutorial-${{ steps.short-sha.outputs.sha }} |
| 71 | + commit-message: export tutorials changed in ${{ steps.short-sha.outputs.sha }} |
| 72 | + delete-branch: true |
0 commit comments