Minor fix #211
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: Notebook Test | |
| on: [push, pull_request] | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| env: | |
| DEBIAN_FRONTEND: noninteractive | |
| PYTHON_VERSION: '3.10' | |
| outputs: | |
| is_self_hosted: ${{ steps.detect_env.outputs.is_self_hosted }} | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v4 | |
| - name: Detect Runner Environment | |
| id: detect_env | |
| run: | | |
| IS_SELF_HOSTED=false | |
| IS_ACT=false | |
| IS_GITEA=false | |
| if [ -n "$ACT" ]; then | |
| echo "Runner environment: local act" | |
| IS_ACT=true | |
| IS_SELF_HOSTED=true | |
| elif [ "${{ github.server_url }}" != "https://github.com" ]; then | |
| echo "Runner environment: Gitea" | |
| IS_GITEA=true | |
| IS_SELF_HOSTED=true | |
| else | |
| echo "Runner environment: GitHub.com" | |
| fi | |
| echo "is_act=$IS_ACT" >> $GITHUB_OUTPUT | |
| echo "is_gitea=$IS_GITEA" >> $GITHUB_OUTPUT | |
| echo "is_self_hosted=$IS_SELF_HOSTED" >> $GITHUB_OUTPUT | |
| - name: Perform Local Runner Setup | |
| id: local_setup | |
| # This action performs general setup for self-hosted runners, including Gitea and local act | |
| if: steps.detect_env.outputs.is_self_hosted == 'true' | |
| uses: ./.github/actions/local-setup | |
| with: | |
| gitea-token: ${{ secrets.GITEA_TOKEN }} | |
| - name: Set up Docker (act runner only) | |
| # Docker is needed for Elasticsearch container in tests | |
| if: steps.detect_env.outputs.is_self_hosted == 'true' | |
| run: | | |
| if ! command -v docker &> /dev/null; then | |
| echo "Docker not found, installing..." | |
| curl -fs | |
| if command -v sudo &> /dev/null; then | |
| sudo usermod -aG docker $USER || true | |
| sudo chmod 666 /var/run/docker.sock || true | |
| else | |
| # Fallback for environments running as root without sudo | |
| usermod -aG docker $USER || true | |
| chmod 666 /var/run/docker.sock || true | |
| fi | |
| else | |
| echo "Docker already available: $(docker --version)" | |
| if command -v sudo &> /dev/null; then | |
| sudo chmod 666 /var/run/docker.sock || true | |
| else | |
| chmod 666 /var/run/docker.sock || true | |
| fi | |
| fi | |
| - name: Verify Docker is available | |
| run: | | |
| docker --version | |
| docker ps | |
| - name: Set up Python ${{ env.PYTHON_VERSION }} | |
| uses: actions/setup-python@v5 | |
| env: | |
| http_proxy: ${{ env.http_proxy }} | |
| https_proxy: ${{ env.https_proxy }} | |
| AGENT_TOOLSDIRECTORY: /opt/hostedtoolcache | |
| with: | |
| python-version: '3.10.18' | |
| check-latest: false | |
| - name: Fix pip installation # <-- NEW STEP: force-reinstall pip to fix vendored resolvelib mismatch | |
| run: | | |
| curl -sS https://bootstrap.pypa.io/get-pip.py | python3 - --ignore-installed | |
| python3 -m pip install --upgrade --ignore-installed pip setuptools wheel | |
| - name: Get pip cache directory | |
| id: pip-cache | |
| run: | | |
| echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT | |
| - name: Cache pip dependencies | |
| if: steps.detect_env.outputs.is_act_runner != 'true' | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ steps.pip-cache.outputs.dir }} | |
| key: ${{ runner.os }}-pip-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/pyproject.toml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip-${{ env.PYTHON_VERSION }}- | |
| - name: Install dependencies | |
| env: | |
| GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} | |
| run: | | |
| pip_install_args=() | |
| if [[ "${{ steps.detect_env.outputs.is_act_runner }}" == "true" ]] && [[ -n "${GITEA_TOKEN}" ]]; then | |
| echo "🔧 Running in act - using local mirror and removing hash requirements" | |
| find . -name "requirements*.txt" -type f -exec sed -i 's/ --hash=sha256:[a-f0-9]*//g' {} \; | |
| pip_install_args+=("--trusted-host" "dh-cap02" "-i" "http://dh-cap02:8008/mirrors/pat2vec") | |
| fi | |
| echo "Installing project dependencies..." | |
| python3 -m pip install "${pip_install_args[@]}" -e ".[all,dev]" | |
| python3 -m ipykernel install --user --name=pat2vec_env --display-name "Python (pat2vec_env)" | |
| jupyter kernelspec list | |
| - name: List installed packages | |
| run: | | |
| which python3 | |
| python3 --version | |
| python3 -m pip list | |
| - name: Run notebook test | |
| run: | | |
| if ! command -v docker &> /dev/null; then | |
| echo "⚠️ Docker not available — skipping notebook test" | |
| exit 0 | |
| fi | |
| pytest --nbmake --nbmake-timeout=1200 --exitfirst notebooks/test_notebook.py | |
| - name: Clean up Jupyter kernels | |
| if: always() | |
| run: | | |
| echo "Forcefully cleaning up Jupyter kernels to prevent hanging..." | |
| pkill -9 -f ipykernel || true | |
| pkill -9 -f jupyter || true | |
| - name: Clean Up Generated Files for Local Act Runner | |
| if: steps.detect_env.outputs.is_act_runner == 'true' && always() | |
| run: | | |
| echo "INFO: Cleaning up directories created during the test run..." | |
| rm -rf notebooks/new_project | |
| rm -rf notebooks/new_project_ipw | |
| rm -rf notebooks/treatment_doc_extract |