Github Actions CI for the repo - sanity check #51
Workflow file for this run
This file contains 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: Sanity check | |
on: | |
push: | |
branches: [ "master" ] | |
pull_request: | |
branches: [ "master" ] | |
permissions: | |
contents: read | |
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 | |
- name: Categorize subprojects | |
id: categorize-subprojects | |
run: | | |
notebook=() | |
gradio=() | |
webcam=() | |
js=() | |
for dir in $(find demos -type d -mindepth 1 -maxdepth 1 ! -name utils); do | |
if [ -f "$dir/package.json" ]; then | |
js+=("$dir") | |
elif [ -f "$dir/main.ipynb" ]; then | |
notebook+=("$dir") | |
elif grep -q "gradio" "$dir/requirements.txt"; then | |
gradio+=("$dir") | |
elif grep -q -- "--stream" "$dir/main.py"; then | |
webcam+=("$dir") | |
fi | |
done | |
notebook_json=$(printf '%s\n' "${notebook[@]}" | jq -R -s -c 'split("\n")[:-1]') | |
gradio_json=$(printf '%s\n' "${gradio[@]}" | jq -R -s -c 'split("\n")[:-1]') | |
webcam_json=$(printf '%s\n' "${webcam[@]}" | jq -R -s -c 'split("\n")[:-1]') | |
js_json=$(printf '%s\n' "${js[@]}" | jq -R -s -c 'split("\n")[:-1]') | |
echo "notebook=$notebook_json" | tee -a $GITHUB_OUTPUT | |
echo "gradio=$gradio_json" | tee -a $GITHUB_OUTPUT | |
echo "webcam=$webcam_json" | tee -a $GITHUB_OUTPUT | |
echo "js=$js_json" | tee -a $GITHUB_OUTPUT | |
notebook: | |
needs: find-subprojects | |
if: ${{ needs.find-subprojects.outputs.notebook != '[]' }} | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-latest, windows-latest, macos-latest] | |
python: [3.11] | |
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 }} | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r ${{ matrix.subproject }}/requirements.txt | |
pip list | |
- name: Execute Notebook | |
run: | | |
cd ${{ matrix.subproject }} | |
jupyter nbconvert --to notebook --execute main.ipynb | |
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.11] | |
subproject: ${{ fromJson(needs.find-subprojects.outputs.gradio) }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: ./.github/setup-os | |
- name: Set up Python ${{ matrix.python }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python }} | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r ${{ matrix.subproject }}/requirements.txt | |
pip list | |
- name: Run Gradio App | |
run: | | |
cd ${{ matrix.subproject }} | |
# the timeout trick "gracefully" kills the app after 5 minutes (waiting for user input otherwise) | |
timeout 5m python main.py || [[ $? -eq 124 ]] | |
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.11] | |
subproject: ${{ fromJson(needs.find-subprojects.outputs.webcam) }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.python }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python }} | |
- name: Install virtual display | |
if: runner.os == 'Linux' | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y xvfb | |
- name: Install python dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r ${{ matrix.subproject }}/requirements.txt | |
pip list | |
- name: Download sample video file | |
run: | | |
cd ${{ matrix.subproject }} | |
curl -L -o sample_video.mp4 https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4 | |
- name: Run Webcam Demo | |
shell: bash | |
run: | | |
cd ${{ matrix.subproject }} | |
# linux requires a virtual display | |
if [ "${{ runner.os }}" == "Linux" ]; then | |
xvfb-run python main.py --stream sample_video.mp4 | |
else | |
python main.py --stream sample_video.mp4 | |
fi | |
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 | |
- name: Install virtual display | |
if: runner.os == 'Linux' | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y xvfb | |
- name: Install coreutils | |
if: runner.os == 'macOS' | |
run: | | |
brew install coreutils | |
- name: Install Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '22' | |
- name: Install dependencies | |
run: | | |
cd ${{ matrix.subproject }} | |
npm install | |
- name: Run JS Project | |
shell: bash | |
run: | | |
cd ${{ matrix.subproject }} | |
# linux requires a virtual display | |
if [ "${{ runner.os }}" == "Linux" ]; then | |
# the timeout trick "gracefully" kills the app after 1 minute (waiting for user input otherwise) | |
timeout 1m xvfb-run npm start || [[ $? -eq 124 ]] | |
else | |
timeout 1m npm start || [[ $? -eq 124 ]] | |
fi |