Skip to content

multi-cam stitching and nn detections example #186

multi-cam stitching and nn detections example

multi-cam stitching and nn detections example #186

Workflow file for this run

name: Runnability tests on changed examples
concurrency:
group: pr-tests-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
on:
workflow_dispatch:
inputs:
log_level:
description: 'Log level to use for pytest.'
type: choice
options:
- ERROR
- INFO
- DEBUG
default: INFO
required: false
platform:
description: 'Platform to use for testing. By default both RVC2 and RVC4 are used but you can use only one by passing only `rvc2` or `rvc4`(use lowercase).'
default: "all"
required: false
strict_mode:
description: "If set to 'yes', tests will fail on DepthAI warnings."
type: choice
options:
- "yes"
- "no"
default: "no"
required: false
subtests:
description: "Specify if should run only peripheral, only standalone or both"
type: choice
options:
- "all"
- "peripheral"
- "standalone"
default: "all"
required: false
pull_request:
types: [opened, synchronize, reopened, labeled]
branches:
- main
jobs:
precheck:
runs-on: ubuntu-latest
outputs:
should_run: ${{ steps.check.outputs.should_run }}
steps:
- name: Evaluate trigger condition
id: check
run: |
EVENT_NAME="${{ github.event_name }}"
RAW_LABELS='${{ toJson(github.event.pull_request.labels) }}'
if [[ "$RAW_LABELS" == "null" || -z "$RAW_LABELS" ]]; then
LABELS="[]"
else
LABELS="$RAW_LABELS"
fi
SHOULD_RUN="false"
if [[ "$EVENT_NAME" == "workflow_dispatch" ]]; then
SHOULD_RUN="true"
elif [[ "$EVENT_NAME" == "pull_request" ]]; then
if echo "$LABELS" | jq -r '.[].name' | grep -q "testable"; then
SHOULD_RUN="true"
fi
fi
echo "should_run=$SHOULD_RUN" >> "$GITHUB_OUTPUT"
setup:
runs-on: ubuntu-latest
needs: [precheck]
if: needs.precheck.outputs.should_run == 'true'
outputs:
matrix_platform: ${{ steps.set-matrix.outputs.platform }}
matrix_python: ${{ steps.set-matrix.outputs.python }}
steps:
- id: set-matrix
env:
INPUT_PLATFORM: ${{ github.event.inputs.platform || 'all' }}
INPUT_PYTHON: "3.10" # Test only on python 3.10
run: |
if [ "$INPUT_PLATFORM" = "all" ]; then
echo 'platform=["rvc2","rvc4"]' >> $GITHUB_OUTPUT
else
echo "platform=[\"$INPUT_PLATFORM\"]" >> $GITHUB_OUTPUT
fi
if [ "$INPUT_PYTHON" = "all" ]; then
echo 'python=["3.8", "3.10", "3.12"]' >> $GITHUB_OUTPUT
else
echo "python=[\"$INPUT_PYTHON\"]" >> $GITHUB_OUTPUT
fi
detect-changes:
runs-on: ubuntu-latest
needs: [precheck]
if: needs.precheck.outputs.should_run == 'true'
outputs:
example_dirs: ${{ steps.detect.outputs.example_dirs }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- id: detect
run: |
git fetch origin main
changed_files=$(git diff --name-only origin/main...HEAD)
example_dirs=""
while read -r file; do
dir=$(dirname "$file")
while [ "$dir" != "." ] && [ "$dir" != "/" ]; do
if [[ -f "$dir/main.py" && -f "$dir/requirements.txt" ]]; then
example_dirs="$example_dirs $dir"
break
fi
dir=$(dirname "$dir")
done
done <<< "$changed_files"
example_dirs=$(echo "$example_dirs" | tr ' ' '\n' | sort -u | xargs)
echo "Changed example dirs: $example_dirs"
echo "example_dirs=$example_dirs" >> "$GITHUB_OUTPUT"
- name: Log if no examples detected
if: steps.detect.outputs.example_dirs == ''
run: echo "✅ No runnable examples detected in this PR."
test_peripheral:
runs-on: ["self-hosted", "testbed-runner"]
needs: [setup, detect-changes]
if: needs.detect-changes.outputs.example_dirs != '' &&
((inputs.subtests || 'all') == 'all' || (inputs.subtests || 'all') == 'peripheral')
strategy:
matrix:
python-version: ${{ fromJSON(needs.setup.outputs.matrix_python) }}
platform: ${{ fromJSON(needs.setup.outputs.matrix_platform) }}
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12
cache: pip
- name: Install HIL
run: |
pip install hil_framework --upgrade --index-url https://__token__:${{ secrets.GITLAB_TOKEN }}@gitlab.luxonis.com/api/v4/projects/213/packages/pypi/simple
- name: Set model variable
run: |
if [ "${{ matrix.platform }}" = "rvc2" ]; then
echo "MODEL=oak_d_s2" >> $GITHUB_ENV
elif [ "${{ matrix.platform }}" = "rvc4" ]; then
echo "MODEL=oak4_pro or oak4_d" >> $GITHUB_ENV
fi
- name: Run Test
run: |
export RESERVATION_NAME="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}#${{ matrix.python-version}}-${{ matrix.platform }}"
export INFLUXDB_TOKEN=${{ secrets.INFLUXDB_TOKEN }}
ENV_VARS="\
--env PLATFORM=${{ matrix.platform }} \
--env PYTHON_VERSION_ENV=${{ matrix.python-version }} \
--env LOG_LEVEL=${{ github.event.inputs.log_level || 'INFO' }} \
--env ROOT_DIR='${{ needs.detect-changes.outputs.example_dirs }}' \
--env STRICT_MODE=${{ github.event.inputs.strict_mode || 'no' }} "
RESERVATION_OPTION="--reservation-name $RESERVATION_NAME"
exec hil_runner --models "$MODEL" $RESERVATION_OPTION $HOLD_RESERVATION --wait --sync-workspace \
--dockerfile ./tests/Dockerfile_peripheral \
--docker-build-args "--build-arg PYTHON_VERSION=${{ matrix.python-version }}" \
--docker-run-args "$ENV_VARS"
test_standalone:
runs-on: ["self-hosted", "testbed-runner"]
needs: [setup, detect-changes]
if: needs.detect-changes.outputs.example_dirs != '' &&
((inputs.subtests || 'all') == 'all' || (inputs.subtests || 'all') == 'standalone')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12
cache: pip
- name: Install HIL
run: |
pip install hil_framework --upgrade --index-url https://__token__:${{ secrets.GITLAB_TOKEN }}@gitlab.luxonis.com/api/v4/projects/213/packages/pypi/simple
- name: Run Test
run: |
export RESERVATION_NAME="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}#standalone"
export INFLUXDB_TOKEN=${{ secrets.INFLUXDB_TOKEN }}
ENV_VARS="\
--env PLATFORM="rvc4" \
--env PYTHON_VERSION_ENV="3.10" \
--env LOG_LEVEL=${{ github.event.inputs.log_level || 'INFO' }} \
--env ROOT_DIR='${{ needs.detect-changes.outputs.example_dirs }}' \
--env STRICT_MODE=${{ github.event.inputs.strict_mode || 'no' }} \
--env DEVICE_PASSWORD=${{ secrets.DEVICE_PASSWORD }} \
--env LOCAL_STATIC_REGISTRY=${{ secrets.LOCAL_STATIC_REGISTRY }}"
RESERVATION_OPTION="--reservation-name $RESERVATION_NAME"
exec hil_runner --models "oak4_pro or oak4_d" $RESERVATION_OPTION $HOLD_RESERVATION --wait --oakctl --sync-workspace \
--dockerfile ./tests/Dockerfile_standalone \
--docker-build-args "--build-arg PYTHON_VERSION=3.12" \
--docker-run-args "$ENV_VARS"
final:
name: Runnability of changed examples
runs-on: ubuntu-latest
needs:
- precheck
- test_peripheral
- test_standalone
if: always()
steps:
- name: Fail if tests have been skipped
if: needs.precheck.outputs.should_run == 'false'
run: |
echo "❌ PR is not marked as testable (no 'testable' label). Skipping tests is not allowed."
exit 1
- name: Fail if any previous job failed
if: ${{ needs.test_peripheral.result == 'failure' || needs.test_standalone.result == 'failure' || needs.test_peripheral.result == 'cancelled' || needs.test_standalone.result == 'cancelled' }}
run: |
echo "❌ One or more required tests failed or were cancelled."
exit 1
- name: All required jobs passed
run: echo "✅ All tests passed successfully."