name: gradio-backend on: push: branches: - "main" pull_request: concurrency: group: backend-${{ github.ref }}-${{ github.event_name == 'push' || github.event.inputs.fire != null }} cancel-in-progress: true env: NODE_OPTIONS: "--max-old-space-size=4096" jobs: changes: runs-on: ubuntu-latest outputs: python-client: ${{ steps.changes.outputs.python-client }} gradio: ${{ steps.changes.outputs.gradio }} test: ${{ steps.changes.outputs.test }} workflows: ${{ steps.changes.outputs.workflows }} scripts: ${{ steps.changes.outputs.scripts }} client-scripts: ${{ steps.changes.outputs.client-scripts }} steps: - uses: actions/checkout@v3 - uses: dorny/paths-filter@v2 id: changes with: filters: | python-client: - 'client/python/**' gradio: - 'gradio/**' - 'requirements.txt' test: - 'test/**' workflows: - '.github/**' scripts: - 'scripts/**' client-test: needs: [changes] if: needs.changes.outputs.python-client == 'true' || needs.changes.outputs.workflows == 'true' strategy: matrix: os: ["ubuntu-latest", "windows-latest"] test-type: ["not flaky", "flaky"] python-version: ["3.8"] runs-on: ${{ matrix.os }} continue-on-error: ${{ matrix.test-type == 'flaky' }} steps: - uses: actions/checkout@v3 - name: Install Python uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} cache: pip cache-dependency-path: | client/python/requirements.txt requirements.txt test/requirements.txt - name: Create env run: | python -m pip install --upgrade virtualenv python -m virtualenv venv - uses: actions/cache@master id: cache with: path: | client/python/venv/* key: python-client-${{ runner.os }}-pip-${{ hashFiles('client/python/requirements.txt') }}-${{ hashFiles('client/python/test/requirements.txt') }} - uses: actions/cache@v3 id: frontend-cache with: path: | gradio/templates/* key: gradio-lib-front-end-${{ hashFiles('js/**')}} - name: Install pnpm if: steps.frontend-cache.outputs.cache-hit != 'true' uses: pnpm/action-setup@v2 with: version: 8 - uses: actions/setup-node@v3 if: steps.frontend-cache.outputs.cache-hit != 'true' with: node-version: 18 cache: pnpm cache-dependency-path: pnpm-lock.yaml - name: Build frontend if: steps.frontend-cache.outputs.cache-hit != 'true' run: | pnpm i --frozen-lockfile --ignore-scripts pnpm build - name: Install Test Requirements (Linux) if: runner.os == 'Linux' run: | . venv/bin/activate python -m pip install -r client/python/test/requirements.txt - name: Install ffmpeg uses: FedericoCarboni/setup-ffmpeg@v2 - name: Install Gradio and Client Libraries Locally (Linux) if: runner.os == 'Linux' run: | . venv/bin/activate python -m pip install -e client/python python -m pip install -e . - name: Lint (Linux) if: runner.os == 'Linux' run: | . venv/bin/activate bash client/python/scripts/lint.sh - name: Tests (Linux) if: runner.os == 'Linux' run: | . venv/bin/activate python -m pytest -m "${{ matrix.test-type }}" client/python/ - name: Install Test Requirements (Windows) if: runner.os == 'Windows' run: | venv\Scripts\activate pip install -r client/python/test/requirements.txt - name: Install Gradio and Client Libraries Locally (Windows) if: runner.os == 'Windows' run: | venv\Scripts\activate python -m pip install -e client/python python -m pip install -e . - name: Tests (Windows) if: runner.os == 'Windows' run: | venv\Scripts\activate python -m pytest -m "${{ matrix.test-type }}" client/python/ test: needs: [changes] if: needs.changes.outputs.gradio == 'true' || needs.changes.outputs.workflows == 'true' || needs.changes.outputs.scripts == 'true' || needs.changes.outputs.test == 'true' strategy: matrix: os: ["ubuntu-latest", "windows-latest"] test-type: ["not flaky", "flaky"] python-version: ["3.8"] runs-on: ${{ matrix.os }} continue-on-error: ${{ matrix.test-type == 'flaky' }} steps: - uses: actions/checkout@v3 - name: Install Python uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} cache: pip cache-dependency-path: | client/python/requirements.txt requirements.txt test/requirements.txt - name: Create env run: | python -m pip install --upgrade virtualenv python -m virtualenv venv - uses: actions/cache@v3 id: cache with: path: | venv/* key: gradio-lib-${{ runner.os }}-pip-${{ hashFiles('client/python/requirements.txt') }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('test/requirements.txt') }} - uses: actions/cache@v3 id: frontend-cache with: path: | gradio/templates/* key: gradio-lib-front-end-${{ hashFiles('js/**')}} - name: Install pnpm if: steps.frontend-cache.outputs.cache-hit != 'true' uses: pnpm/action-setup@v2 with: version: 8 - uses: actions/setup-node@v3 if: steps.frontend-cache.outputs.cache-hit != 'true' with: node-version: 18 cache: pnpm cache-dependency-path: pnpm-lock.yaml - name: Build frontend if: steps.frontend-cache.outputs.cache-hit != 'true' run: | pnpm i --frozen-lockfile --ignore-scripts pnpm build - name: Install Gradio and Client Libraries Locally (Linux) if: runner.os == 'Linux' run: | . venv/bin/activate python -m pip install -e client/python python -m pip install . - name: Install Test Dependencies (Linux) if: steps.cache.outputs.cache-hit != 'true' && runner.os == 'Linux' run: | . venv/bin/activate bash scripts/install_test_requirements.sh - name: Install ffmpeg uses: FedericoCarboni/setup-ffmpeg@v2 - name: Lint (Linux) if: runner.os == 'Linux' run: | . venv/bin/activate bash scripts/lint_backend.sh - name: Typecheck (Linux) if: runner.os == 'Linux' run: | . venv/bin/activate bash scripts/type_check_backend.sh - name: Run tests (Linux) if: runner.os == 'Linux' run: | . venv/bin/activate python -m coverage run -m pytest -m "${{ matrix.test-type }}" --ignore=client python -m coverage xml - name: Install Gradio and Client Libraries Locally (Windows) if: runner.os == 'Windows' run: | venv\Scripts\activate python -m pip install -e client/python python -m pip install . - name: Install Test Dependencies (Windows) if: steps.cache.outputs.cache-hit != 'true' && runner.os == 'Windows' run: | venv\Scripts\activate python -m pip install -e . -r test/requirements.txt - name: Run tests (Windows) if: runner.os == 'Windows' run: | venv\Scripts\activate python -m coverage run -m pytest -m "${{ matrix.test-type }}" --ignore=client python -m coverage xml