feat: adding workflow file to run notebooks #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test Notebooks as Scripts | |
| on: | |
| pull_request: | |
| schedule: | |
| - cron: '0 0 */14 * *' # Every 14 days at midnight UTC | |
| workflow_dispatch: | |
| env: | |
| OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
| HF_API_TOKEN: ${{ secrets.HUGGINGFACE_API_KEY }} | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| jobs: | |
| test-notebooks: | |
| runs-on: ubuntu-latest | |
| env: | |
| OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v3 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.10' | |
| - name: Install dependencies | |
| run: | | |
| pip install nbconvert ipython | |
| - name: Run notebooks as scripts | |
| run: | | |
| SKIP_FILE=".github/workflows/skip_notebooks" | |
| mapfile -t SKIP_LIST < "$SKIP_FILE" | |
| mkdir -p converted_scripts | |
| for notebook in $(find ./notebooks -name "*.ipynb"); do | |
| skip=false | |
| for skip_item in "${SKIP_LIST[@]}"; do | |
| if [[ "$notebook" == "$skip_item" ]]; then | |
| echo "Skipping $notebook" | |
| skip=true | |
| break | |
| fi | |
| done | |
| if ! $skip; then | |
| echo "Converting $notebook to .py" | |
| base_name=$(basename "$notebook" .ipynb) | |
| notebook_dir=$(dirname "$notebook") | |
| output_path="converted_scripts/$base_name.py" | |
| jupyter nbconvert --to script "$notebook" --output "$base_name" | |
| mv "$notebook_dir/$base_name.py" "$output_path" | |
| # strip IPython Magics Before Running | |
| sed -i '/get_ipython()/d;/^%/d;/^!/d' "$output_path" | |
| python "$output_path" | |
| fi | |
| done |