|
| 1 | +name: Run Notebook |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: [ main ] |
| 7 | + pull_request: |
| 8 | + branches: [ main ] |
| 9 | + |
| 10 | +jobs: |
| 11 | + run-notebook: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v4 |
| 15 | + |
| 16 | + - name: Set up Python 3.11 |
| 17 | + uses: actions/setup-python@v4 |
| 18 | + with: |
| 19 | + python-version: '3.11' |
| 20 | + |
| 21 | + - name: Extract dependencies from colabtools |
| 22 | + run: | |
| 23 | + # Download setup.py |
| 24 | + curl -s https://raw.githubusercontent.com/googlecolab/colabtools/refs/heads/main/setup.py > setup.py |
| 25 | + # Extract DEPENDENCIES using Python |
| 26 | + python3 - <<EOF |
| 27 | + with open('setup.py', 'r') as f: |
| 28 | + content = f.read() |
| 29 | + |
| 30 | + # Find DEPENDENCIES tuple |
| 31 | + start = content.find('DEPENDENCIES = (') |
| 32 | + end = content.find(')', start) |
| 33 | + deps = content[start:end+1] |
| 34 | + |
| 35 | + # Execute the tuple to get the values |
| 36 | + exec(deps) |
| 37 | + |
| 38 | + # Write dependencies to requirements file |
| 39 | + with open('colab_requirements.txt', 'w') as f: |
| 40 | + for dep in DEPENDENCIES: |
| 41 | + f.write(f"{dep}\n") |
| 42 | + EOF |
| 43 | + |
| 44 | + - name: Install dependencies |
| 45 | + run: | |
| 46 | + python -m pip install --upgrade pip |
| 47 | + # Install colabtools dependencies |
| 48 | + pip install -r colab_requirements.txt |
| 49 | + # Install additional required packages |
| 50 | + pip install -r requirements.txt |
| 51 | +
|
| 52 | + - name: Modify notebook |
| 53 | + run: | |
| 54 | + # Convert notebook to Python script for easier text processing |
| 55 | + jupyter nbconvert --to script run_and_explore.ipynb |
| 56 | + |
| 57 | + # Replace META_ID |
| 58 | + sed -i 's/META_ID = ""/META_ID = "36Dm86NVjoTJ"/' run_and_explore.py |
| 59 | + |
| 60 | + # Add no_upload parameter to run function |
| 61 | + sed -i 's/url, meta_result = run(META_ID)/url, meta_result = run(META_ID, no_upload=True)/' run_and_explore.py |
| 62 | + |
| 63 | + # Remove View the Report section (everything after the line containing "## View the Report") |
| 64 | + sed -i '/^## View the Report/,$d' run_and_explore.py |
| 65 | + |
| 66 | + # Convert back to notebook |
| 67 | + jupyter nbconvert --to notebook run_and_explore.py |
| 68 | + |
| 69 | + # Move converted notebook back to original name |
| 70 | + mv run_and_explore.nbconvert.ipynb run_and_explore.ipynb |
| 71 | + |
| 72 | + - name: Execute notebook |
| 73 | + run: | |
| 74 | + jupyter nbconvert --to notebook --execute run_and_explore.ipynb --output executed_notebook.ipynb |
| 75 | + |
| 76 | + - name: Upload notebook |
| 77 | + uses: actions/upload-artifact@v3 |
| 78 | + with: |
| 79 | + name: executed-notebook |
| 80 | + path: executed_notebook.ipynb |
0 commit comments