Skip to content

Updates AI plugin #8883

Updates AI plugin

Updates AI plugin #8883

Workflow file for this run

name: Python Lint and Test
on: pull_request
jobs:
test:
env:
# Minimum code coverage per file
COVERAGE_SINGLE: 50
# Minimum total code coverage
COVERAGE_TOTAL: 56
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: dispatch
POSTGRES_DB: dispatch
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Check out Git repository
uses: actions/checkout@v2
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
python-version: 3.11.2
- uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install python dependencies
run: |
export DISPATCH_LIGHT_BUILD=1
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: "Lint with ruff"
run: |
ruff check src tests
ruff format src tests
- name: Test with pytest
run: |
pip install pytest-cov
pytest --junitxml=junit/test-results.xml --cov=dispatch --cov-report=json:coverage.json --cov-report=xml --cov-report=html
- name: Coverage per file
# All modified files should meet the minimum code coverage requirement.
run: |
export MODIFIED_FILES=$(git diff master...HEAD --name-only | grep -E '\.py$')
export FAILED_COVERAGE_PER_FILE=$(python -c "import json;files=json.load(open('coverage.json'))['files'];covs=map(lambda k, v: (k, v['summary']['percent_covered_display']),files.keys(),files.values()); f=filter(lambda cov:int(cov[1])<50,covs); print('\n'.join('{:<68}{:>3}%'.format(k,v) for k,v in f))")
export FAILED_COVERAGE_FILES=(); echo "$FAILED_COVERAGE_PER_FILE" | while read -r line; do FAILED_COVERAGE_FILES+=${line%%[[:space:]]*};done
files=($(comm -12 <(for X in "${MODIFIED_FILES}"; do echo "${X}"; done|sort) <(for X in "${FAILED_COVERAGE_FILENAMES}"; do echo "${X}"; done|sort)))
if [[ ${#files[@]} > 0 ]]; then
echo "FAIL Recommended file test coverage of ${{ env.COVERAGE_SINGLE }}% not reached. All modified files must meet the minimum code coverage requirement."
for f in "${files[@]}"; do
echo $FAILED_COVERAGE_PER_FILE | grep $f
done
exit 1
fi
- name: Coverage total
run: |
export COVERAGE_TOTAL=$(python -c "import json;print(json.load(open('coverage.json'))['totals']['percent_covered_display'])")
echo "Total coverage: $COVERAGE_TOTAL%"
if [[ $COVERAGE_TOTAL < ${{ env.COVERAGE_TOTAL }} ]]; then
echo "FAIL Recommended total test coverage of ${{ env.COVERAGE_TOTAL }}% not reached. Total coverage: $COVERAGE_TOTAL%"
exit 1
fi