Tests #2425
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: Tests | |
| permissions: | |
| contents: read | |
| on: | |
| push: | |
| branches: | |
| - '!test_branch' | |
| - '!documentation' | |
| schedule: # once a day at midnight UTC | |
| - cron: '0 0 * * *' | |
| pull_request: # requires approval for first-time contributors | |
| types: [synchronize, opened, reopened, labeled, closed] | |
| workflow_dispatch: # Manually trigger with 'Run workflow' button | |
| inputs: | |
| test_mode: | |
| description: 'Test mode (fast or full)' | |
| required: false | |
| default: 'full' | |
| type: choice | |
| options: | |
| - fast | |
| - full | |
| concurrency: # Replace Cancel Workflow Action | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| run-tests: | |
| # Skip if PR is closed but not merged | |
| if: |- | |
| github.event_name != 'pull_request' || | |
| github.event.action != 'closed' || | |
| github.event.pull_request.merged == true | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| shell: bash -l {0} | |
| env: | |
| OS: ubuntu-latest | |
| PYTHON: '3.9' | |
| services: | |
| mysql: | |
| image: datajoint/mysql:8.0 | |
| # args: mysql -h 127.0.0.1 -P 3308 -uroot -ptutorial -e "CMD;" | |
| env: | |
| MYSQL_DATABASE: localhost | |
| MYSQL_ROOT_PASSWORD: tutorial | |
| ports: | |
| - 3308:3306 | |
| options: >- | |
| --health-cmd="mysqladmin ping" | |
| --health-interval=10s | |
| --health-timeout=5s | |
| --health-retries=3 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ env.PYTHON }} | |
| - name: Set up conda | |
| uses: conda-incubator/setup-miniconda@v3 | |
| with: | |
| activate-environment: spyglass | |
| environment-file: environment.yml | |
| miniforge-version: latest | |
| use-mamba: true | |
| - name: Install apt dependencies | |
| run: | | |
| sudo apt-get update # First mysql options | |
| # non-dlc position deps | |
| sudo apt-get install \ | |
| mysql-client libmysqlclient-dev libgirepository1.0-dev -y | |
| sudo apt-get install ffmpeg libsm6 libxext6 -y | |
| - name: Run pip install for test deps | |
| run: | | |
| pip install --quiet .[test] | |
| - name: Cache test data | |
| id: cache-test-data | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| tests/_data/raw/ | |
| tests/_data/video/ | |
| key: |- | |
| test-data-${{ hashFiles('.github/workflows/test-conda.yml') }}-v1 | |
| restore-keys: | | |
| test-data- | |
| - name: Download data | |
| if: steps.cache-test-data.outputs.cache-hit != 'true' | |
| env: | |
| BASEURL: https://ucsf.box.com/shared/static/ | |
| NWB_URL: k3sgql6z475oia848q1rgms4zdh4rkjn.nwb | |
| VID1URL: ykep8ek4ogad20wz4p0vuyuqfo60cv3w.h264 | |
| VID2URL: d2jjk0y565ru75xqojio3hymmehzr5he.h264 | |
| NWBFILE: minirec20230622.nwb | |
| VID_ONE: 20230622_minirec_01_s1.1.h264 | |
| VID_TWO: 20230622_minirec_02_s2.1.h264 | |
| RAW_DIR: /home/runner/work/spyglass/spyglass/tests/_data/raw/ | |
| VID_DIR: /home/runner/work/spyglass/spyglass/tests/_data/video/ | |
| run: | | |
| mkdir -p $RAW_DIR $VID_DIR | |
| curl_opts() { # Declare func with download options | |
| curl -L --output "$1""$2" "$BASEURL""$3" | |
| } | |
| curl_opts $RAW_DIR $NWBFILE $NWB_URL | |
| curl_opts $VID_DIR $VID_ONE $VID1URL | |
| curl_opts $VID_DIR $VID_TWO $VID2URL | |
| - name: Move actions coveragerc | |
| run: mv tests/.coveragerc .coveragerc | |
| - name: Determine test mode | |
| id: test_mode | |
| run: | | |
| # Determine which tests to run based on trigger | |
| if [[ "${{ github.event_name }}" == "push" ]]; then | |
| # Fast tests on push | |
| echo "mode=fast" >> $GITHUB_OUTPUT | |
| echo "marker_args=-m 'not slow and not very_slow'" \ | |
| >> $GITHUB_OUTPUT | |
| echo "description=Fast tests" >> $GITHUB_OUTPUT | |
| elif [[ "${{ github.event_name }}" == "pull_request" ]] \ | |
| && [[ "${{ github.event.action }}" == "closed" ]] \ | |
| && [[ "${{ github.event.pull_request.merged }}" == "true" ]]; then | |
| # Full suite on PR merge | |
| echo "mode=full" >> $GITHUB_OUTPUT | |
| echo "marker_args=" >> $GITHUB_OUTPUT | |
| echo "description=Full test suite" >> $GITHUB_OUTPUT | |
| elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| # Manual trigger - use input | |
| if [[ "${{ github.event.inputs.test_mode }}" == "fast" ]]; then | |
| echo "mode=fast" >> $GITHUB_OUTPUT | |
| echo "marker_args=-m 'not slow and not very_slow'" \ | |
| >> $GITHUB_OUTPUT | |
| echo "description=Fast tests (manual)" >> $GITHUB_OUTPUT | |
| else | |
| echo "mode=full" >> $GITHUB_OUTPUT | |
| echo "marker_args=" >> $GITHUB_OUTPUT | |
| echo "description=Full suite (manual)" >> $GITHUB_OUTPUT | |
| fi | |
| else | |
| # Full suite for schedule and other PR events | |
| # (synchronize, opened, etc.) | |
| echo "mode=full" >> $GITHUB_OUTPUT | |
| echo "marker_args=" >> $GITHUB_OUTPUT | |
| echo "description=Full test suite" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Run tests (${{ steps.test_mode.outputs.description }}) | |
| run: | | |
| pytest --no-docker --no-dlc \ | |
| --cov-config=.coveragerc --cov=spyglass-neuro --cov-report=xml \ | |
| ${{ steps.test_mode.outputs.marker_args }} \ | |
| tests/ | |
| - name: Upload coverage reports to Codecov | |
| uses: codecov/codecov-action@v5 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| flags: ${{ steps.test_mode.outputs.mode }}-tests | |
| name: ${{ steps.test_mode.outputs.description }} |