From bae18df4bba5a4443295a834e3215bffe9360b7f Mon Sep 17 00:00:00 2001 From: Dario Coscia <93731561+dario-coscia@users.noreply.github.com> Date: Fri, 4 Apr 2025 12:06:59 +0200 Subject: [PATCH] update workflow + pyproject tut dependencies (#531) --- .github/workflows/tutorial_exporter.yml | 64 +++++++++++++++++++++++++ pyproject.toml | 2 +- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tutorial_exporter.yml b/.github/workflows/tutorial_exporter.yml index ee6384f..f495c3e 100644 --- a/.github/workflows/tutorial_exporter.yml +++ b/.github/workflows/tutorial_exporter.yml @@ -10,6 +10,9 @@ on: - 'tutorials/**/*.ipynb' jobs: + # run on push + export_tutorials_on_push: + if: ${{ github.event_name == 'push' }} export_tutorials: permissions: write-all runs-on: ubuntu-latest @@ -41,6 +44,9 @@ jobs: 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 @@ -56,9 +62,67 @@ jobs: done set +x + - uses: benjlevesque/short-sha@v2.1 + id: short-sha + + - name: Remove unwanted files + run: | + rm -rf build/ tutorials/tutorial4/data/ + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v5.0.2 + 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.8 + + - 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/short-sha@v2.1 id: short-sha diff --git a/pyproject.toml b/pyproject.toml index 43f56d0..ebd2623 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,7 @@ dev = [ ] tutorial = [ "jupyter", - "smithers", + "smithers @ git+https://github.com/mathLab/smithers.git", "torchvision", "tensorboard", "scipy",