-
Notifications
You must be signed in to change notification settings - Fork 45
195 lines (184 loc) · 7.1 KB
/
sanity-check.yml
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
name: Sanity check
on:
schedule:
- cron: "0 2 * * *"
pull_request:
branches: [master]
push:
branches: [master]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
find-subprojects:
runs-on: ubuntu-latest
outputs:
notebook: ${{ steps.categorize-subprojects.outputs.notebook }}
gradio: ${{ steps.categorize-subprojects.outputs.gradio }}
webcam: ${{ steps.categorize-subprojects.outputs.webcam }}
js: ${{ steps.categorize-subprojects.outputs.js }}
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine subprojects to test
run: |
# Include the workflow file as a trigger for running all subprojects
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
changed_files=$(git diff --name-only origin/master..HEAD)
if echo "$changed_files" | grep -q '.github/'; then
# Workflow file changed; run all subprojects
subproject_dirs=$(find demos notebooks -mindepth 1 -maxdepth 1 -type d ! -name utils | tr '\n' ' ')
else
# Only run subprojects affected by changes
subproject_dirs=$(echo "$changed_files" | grep -e '^demos' -e '^notebooks' | grep -v 'README.md$' | xargs -I{} dirname "{}" | sort -u | tr '\n' ' ')
fi
else
subproject_dirs=$(find demos notebooks -mindepth 1 -maxdepth 1 -type d ! -name utils | tr '\n' ' ')
fi
echo "subproject_dirs=$subproject_dirs" >> $GITHUB_ENV
- name: Categorize subprojects
id: categorize-subprojects
run: |
notebook=()
gradio=()
webcam=()
js=()
for dir in $subproject_dirs; do
if [ -f "$dir/package.json" ]; then
js+=("$dir")
elif find "$dir" -maxdepth 1 -name "*.ipynb" | grep -q "."; then
notebook+=("$dir")
elif [ -f "$dir/requirements.txt" ] && grep -q "gradio" "$dir/requirements.txt"; then
gradio+=("$dir")
elif [ -f "$dir/main.py" ] && grep -q -- "--stream" "$dir/main.py"; then
webcam+=("$dir")
fi
done
notebook_json=$(printf '%s\n' "${notebook[@]}" | jq -R -s -c 'split("\n") | map(select(length > 0))')
gradio_json=$(printf '%s\n' "${gradio[@]}" | jq -R -s -c 'split("\n") | map(select(length > 0))')
webcam_json=$(printf '%s\n' "${webcam[@]}" | jq -R -s -c 'split("\n") | map(select(length > 0))')
js_json=$(printf '%s\n' "${js[@]}" | jq -R -s -c 'split("\n") | map(select(length > 0))')
echo "notebook=$notebook_json" >> $GITHUB_OUTPUT
echo "gradio=$gradio_json" >> $GITHUB_OUTPUT
echo "webcam=$webcam_json" >> $GITHUB_OUTPUT
echo "js=$js_json" >> $GITHUB_OUTPUT
- name: Print subprojects to test
run: |
echo "Notebook subprojects: ${{ steps.categorize-subprojects.outputs.notebook }}"
echo "Gradio subprojects: ${{ steps.categorize-subprojects.outputs.gradio }}"
echo "Webcam subprojects: ${{ steps.categorize-subprojects.outputs.webcam }}"
echo "JS subprojects: ${{ steps.categorize-subprojects.outputs.js }}"
notebook:
needs: find-subprojects
if: ${{ needs.find-subprojects.outputs.notebook != '[]' }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# onnxruntime-openvino is not available on mac and python<3.10
os: [ubuntu-latest, windows-latest]
python: [3.11, 3.12]
subproject: ${{ fromJson(needs.find-subprojects.outputs.notebook) }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- uses: ./.github/reusable-steps/setup-python
with:
python: ${{ matrix.python }}
project: ${{ matrix.subproject }}
- name: Use downloaded video as a stream
shell: bash
run: |
cd ${{ matrix.subproject }}
# replace video_path with sample_video.mp4
find . -name "*.ipynb" -exec sed -E -i "s/video_path\s*=\s*(['\"]?.*?['\"]?)/video_path=\\\\\"sample_video.mp4\\\\\"\\\n\",/g" {} +
- uses: ./.github/reusable-steps/timeouted-action
name: Run Notebook
with:
command: jupyter nbconvert --to notebook --execute *.ipynb
project: ${{ matrix.subproject }}
gradio:
needs: find-subprojects
if: ${{ needs.find-subprojects.outputs.gradio != '[]' }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python: ["3.10", 3.12]
subproject: ${{ fromJson(needs.find-subprojects.outputs.gradio) }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/reusable-steps/setup-os
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- uses: ./.github/reusable-steps/setup-python
with:
python: ${{ matrix.python }}
project: ${{ matrix.subproject }}
- name: Login to HF
shell: bash
run: |
huggingface-cli login --token ${{ secrets.HF_TOKEN }}
- uses: ./.github/reusable-steps/gradio-action
with:
script: main.py
project: ${{ matrix.subproject }}
webcam:
needs: find-subprojects
if: ${{ needs.find-subprojects.outputs.webcam != '[]' }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python: [3.9, 3.12]
subproject: ${{ fromJson(needs.find-subprojects.outputs.webcam) }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/reusable-steps/setup-os
- uses: ./.github/reusable-steps/setup-python
with:
python: ${{ matrix.python }}
project: ${{ matrix.subproject }}
- uses: ./.github/reusable-steps/timeouted-action
name: Run Webcam Demo
with:
command: python main.py --stream sample_video.mp4
project: ${{ matrix.subproject }}
js:
needs: find-subprojects
if: ${{ needs.find-subprojects.outputs.js != '[]' }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
subproject: ${{ fromJson(needs.find-subprojects.outputs.js) }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/reusable-steps/setup-os
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Install dependencies
run: |
cd ${{ matrix.subproject }}
npm install
- uses: ./.github/reusable-steps/timeouted-action
name: Run JS Project
with:
command: npm start
project: ${{ matrix.subproject }}
timeout: 1m