Skip to content

feat: RND-116: YOLOv8 ML Backend #1095

feat: RND-116: YOLOv8 ML Backend

feat: RND-116: YOLOv8 ML Backend #1095

Workflow file for this run

name: "Tests"
on:
push:
branches:
- master
- 'release/**'
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
branches:
- master
- 'release/**'
env:
CACHE_NAME_PREFIX: v1
jobs:
run_pytest:
name: Run pytest
needs: calculate_matrix
runs-on: ${{
matrix.ml_backend == 'mmdetection-3' && 'ubuntu-latest-4c-16gb' ||
matrix.ml_backend == 'segment_anything_2_image' && 'ubuntu-latest-4c-16gb' ||
matrix.ml_backend == 'segment_anything_2_video' && 'ubuntu-latest-4c-16gb' ||
matrix.ml_backend == 'grounding_dino' && 'ubuntu-latest-4c-16gb' ||
matrix.ml_backend == 'grounding_sam' && 'ubuntu-latest-4c-16gb' ||
'ubuntu-latest' }} # Use larger runner for some backends, as we need >20GB during build time.
timeout-minutes: 30
strategy:
fail-fast: false
matrix: ${{fromJSON(needs.calculate_matrix.outputs.matrix)}}
env:
LOG_DIR: pytest_logs
collect_analytics: false
TEST_WITH_CPU: ${{ matrix.ml_backend == 'segment_anything_model' }}
steps:
- uses: hmarr/debug-action@v3.0.0
- name: Extract branch name on direct push to a branch
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/')
run: |
echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
- name: Extract branch name on 'pull_request'
if: github.event_name == 'pull_request'
run: |
echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF})" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4
with:
ref: "${{ env.GITHUB_SHA }}"
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- uses: actions/cache@v4
name: Configure pip cache
id: pip-cache
with:
path: ~/.cache/pip
key: ${{ env.CACHE_NAME_PREFIX }}-${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}-${{ hashFiles('**/requirements-test.txt') }}
restore-keys: |
${{ env.CACHE_NAME_PREFIX }}-${{ runner.os }}-pip-
- name: Install dependencies
run: |
sudo apt-get clean
sudo apt-get update
sudo apt-get install virtualenv libsasl2-dev python3-dev libldap2-dev libssl-dev
pip install -r tests/requirements-test.txt
pip install -r requirements.txt
pip install -e .
- name: Check pytest version
run: pytest --version
- name: Build the stack
env:
DOCKER_BUILDKIT: 1
TEST_ENV: "true"
run: docker compose -f label_studio_ml/examples/${{ matrix.ml_backend }}/docker-compose.yml up -d --build
- name: Wait for stack
timeout-minutes: 10
run: |
while [ "$(curl -s -o /dev/null -L -w ''%{http_code}'' "http://localhost:9090/health")" != "200" ]; do
echo "=> Waiting for service to become available" && sleep 2s
done
- name: Run general functional tests
env:
ML_BACKEND: ${{ matrix.ml_backend }}
run: |
pytest tests/ -vvv --ignore-glob='**/logs/*' --ignore-glob='**/data/*' --cov=. --cov-report=xml:tests/${{ matrix.ml_backend }}_coverage.xml
- name: Run per-ml-backend tests
env:
ML_BACKEND: ${{ matrix.ml_backend }}
run: |
docker compose -f label_studio_ml/examples/${{ matrix.ml_backend }}/docker-compose.yml exec -T ${{ matrix.ml_backend }} pytest -vvv --cov --cov-report=xml:/tmp/coverage.xml
- name: Copy per-ml-backend coverage.xml from the container
run: |
docker compose -f label_studio_ml/examples/${{ matrix.ml_backend }}/docker-compose.yml cp ${{ matrix.ml_backend }}:/tmp/coverage.xml label_studio_ml/examples/${{ matrix.ml_backend }}/coverage.xml
- name: Pull the logs
if: always()
env:
DOCKER_BUILDKIT: 1
run: docker compose -f label_studio_ml/examples/${{ matrix.ml_backend }}/docker-compose.yml logs
- name: "Upload general coverage to Codecov"
if: ${{ matrix.ml_backend == 'the_simplest_backend' }}
uses: codecov/codecov-action@v4.5.0
with:
name: codecov-general
files: ./tests/${{ matrix.ml_backend }}_coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false
- name: "Upload ml-backend ${{ matrix.ml_backend }} coverage to Codecov"
uses: codecov/codecov-action@v4.5.0
with:
name: codecov-${{ matrix.ml_backend }}
files: ./label_studio_ml/examples/${{ matrix.ml_backend }}/coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false
calculate_matrix:
name: "Calculate test matrix"
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: hmarr/debug-action@v3.0.0
- name: Extract branch name on direct push to a branch
if: github.event_name == 'push'
run: |
echo "BASE_SHA=${{ github.event.before }}" >> $GITHUB_ENV
- name: Extract branch name on 'pull_request'
if: github.event_name == 'pull_request'
run: |
echo "BASE_SHA=${{ github.event.pull_request.base.sha }}" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4
with:
ref: "${{ env.GITHUB_SHA }}"
fetch-depth: 0
- name: Build matrix
id: set-matrix
shell: bash
env:
BASE_SHA: ${{ env.BASE_SHA }}
run: |
set -xuo pipefail
set +e
CHANGED=$(git diff --name-only $BASE_SHA ${{ github.sha }} -- label_studio_ml/ | xargs -L1 dirname | uniq | cut -d'/' -f2-)
CHANGED_EXAMPLES=$(echo "$CHANGED" | grep examples )
set -e
ALL_EXAMPLES=$(ls -1d label_studio_ml/examples/*/ | cut -d'/' -f3- | cut -d'/' -f1)
if [[ $GITHUB_REF == 'refs/heads/master' || $GITHUB_REF =~ ^refs/heads/release/.* ]]; then
echo "All in matrix because we are on master or a release branch"
echo "matrix={\"ml_backend\":[$(echo "$ALL_EXAMPLES" | xargs | sed -e 's/ /\",\"/g' -e 's/^/\"/' -e 's/$/\"/')]}" >> $GITHUB_OUTPUT
elif [[ $(echo "$CHANGED" | grep -c -v ^$) == $(echo "$CHANGED_EXAMPLES" | grep -c -v ^$) ]]; then
echo "Finding examples to test"
if [[ $(echo "$CHANGED" | grep -c -v ^$) == 0 ]]; then
echo "matrix={\"ml_backend\":[]}" >> $GITHUB_OUTPUT
else
echo "matrix={\"ml_backend\":[$(echo "$CHANGED_EXAMPLES" | cut -d'/' -f2- | xargs | sed -e 's/ /\",\"/g' -e 's/^/\"/' -e 's/$/\"/')]}" >> $GITHUB_OUTPUT
fi
else
echo "All in matrix"
echo "matrix={\"ml_backend\":[$(echo "$ALL_EXAMPLES" | xargs | sed -e 's/ /\",\"/g' -e 's/^/\"/' -e 's/$/\"/')]}" >> $GITHUB_OUTPUT
fi
dependabot-auto-merge:
name: "Auto Merge dependabot PR"
if: |
always() &&
needs.run_pytest.result == 'success' &&
github.event_name == 'pull_request' &&
github.event.pull_request.user.login == 'dependabot[bot]' &&
( startsWith(github.head_ref, 'dependabot/npm_and_yarn/') || startsWith(github.head_ref, 'dependabot/pip/') )
runs-on: ubuntu-latest
needs:
- run_pytest
steps:
- name: Enable auto-merge for Dependabot PRs
run: gh pr merge --admin --squash "${PR_URL}"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.GIT_PAT }}