File size: 8,531 Bytes
a03b3ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
name: gradio-backend

on:
  push:
    branches:
      - "main"
  pull_request: 
    types: [opened, synchronize, reopened, labeled, unlabeled]

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"
  HF_TOKEN: ${{ secrets.HF_TOKEN }}

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/**'
            - 'requirements.txt'
          gradio:
            - 'client/python/**'
            - '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"]
        exclude:
          - os: ${{ github.event_name == 'pull_request' && contains( github.event.pull_request.labels.*.name, 'windows-tests') && 'dummy' || 'windows-latest' }}
          - test-type: ${{ github.event_name == 'pull_request' && contains( github.event.pull_request.labels.*.name, 'flaky-tests') && 'dummy' || 'flaky' }}
    runs-on: ${{ matrix.os }}
    continue-on-error: true
    steps:
    - uses: actions/checkout@v3
    - name: Install Python
      uses: actions/setup-python@v5
      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@v4
      id: frontend-cache
      with:
        path: |
          gradio/templates/*
        key: gradio-lib-front-end-${{ hashFiles('js/**', 'client/js/**')}}
    - name: Install pnpm
      if: steps.frontend-cache.outputs.cache-hit != 'true'
      uses: pnpm/action-setup@v2
      with:
        version: 8
    - uses: actions/setup-node@v4
      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 client/python
        python -m pip install ".[oauth]"
    - 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 client/python
        python -m pip install ".[oauth]"
    - 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"]
        exclude:
          - os: ${{ github.event_name == 'pull_request' && contains( github.event.pull_request.labels.*.name, 'windows-tests') && 'dummy' || 'windows-latest' }}
          - test-type: ${{ github.event_name == 'pull_request' && contains( github.event.pull_request.labels.*.name, 'flaky-tests') && 'dummy' || 'flaky' }}
    runs-on: ${{ matrix.os }}
    continue-on-error: true
    steps:
    - uses: actions/checkout@v3
    - name: Install Python
      uses: actions/setup-python@v5
      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@v4
      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@v4
      id: frontend-cache
      with:
        path: |
          gradio/templates/*
          gradio/node/*
        key: gradio-lib-front-end-${{ hashFiles('js/**', 'client/js/**')}}
    - name: Install pnpm
      if: steps.frontend-cache.outputs.cache-hit != 'true'
      uses: pnpm/action-setup@v2
      with:
        version: 8
    - uses: actions/setup-node@v4
      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 client/python
        python -m pip install ".[oauth]"
    - 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 pytest -m "${{ matrix.test-type }}" --ignore=client
    - name: Install Gradio and Client Libraries Locally (Windows)
      if: runner.os == 'Windows'
      run: |
        venv\Scripts\activate
        python -m pip install client/python  
        python -m pip install ".[oauth]"
    - name: Install Test Dependencies (Windows)
      if: steps.cache.outputs.cache-hit != 'true' && runner.os == 'Windows'
      run: |
        venv\Scripts\activate
        python -m pip install . -r test/requirements.txt
    - name: Run tests (Windows)
      if: runner.os == 'Windows'
      run: |
        venv\Scripts\activate
        python -m pytest -m "${{ matrix.test-type }}" --ignore=client
        echo "The exit code for pytest was $LASTEXITCODE"