Skip to content
Latchkey

Runnability tests on changed examples workflow (luxonis/oak-examples)

The Runnability tests on changed examples workflow from luxonis/oak-examples, explained and optimized by Latchkey.

A

CI health: A - excellent

Point runs-on at Latchkey and get job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: luxonis/oak-examples.github/workflows/tests_diff.ymlLicense Apache-2.0View source

What it does

This is the Runnability tests on changed examples workflow from the luxonis/oak-examples repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
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=$(cat <<'JSON'
        ${{ toJson(github.event.pull_request.labels) }}
        JSON
        )

        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."

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

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:
    timeout-minutes: 30
    runs-on: latchkey-small
    outputs:
      should_run: ${{ steps.check.outputs.should_run }}
    steps:
    - name: Evaluate trigger condition
      id: check
      run: |
        EVENT_NAME="${{ github.event_name }}"
 
        RAW_LABELS=$(cat <<'JSON'
        ${{ toJson(github.event.pull_request.labels) }}
        JSON
        )
 
        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:
    timeout-minutes: 30
    runs-on: latchkey-small
    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:
    timeout-minutes: 30
    runs-on: latchkey-small
    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:
    timeout-minutes: 30
    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:
    timeout-minutes: 30
    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:
    timeout-minutes: 30
    name: Runnability of changed examples
    runs-on: latchkey-small
    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."
 

What changed

What Latchkey heals here

This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:

This workflow runs 6 jobs per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow