Skip to content

ci: Add python unit test workflows #1

ci: Add python unit test workflows

ci: Add python unit test workflows #1

Workflow file for this run

name: Test Python
on:
pull_request:
branches:
- main
paths:
- dbgpt/**
- pilot/meta_data/**
- .github/workflows/test-python.yml
push:
branches:
- main
paths:
- dbgpt/**
- pilot/meta_data/**
- .github/workflows/test-python.yml
concurrency:
group: ${{ github.event.number || github.run_id }}
cancel-in-progress: true
jobs:
test-python:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.10", "3.11"]
# os: [ubuntu-latest]
# python-version: ["3.10"]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[openai]"
pip install -r requirements/dev-requirements.txt
- name: Run tests
run: |
pytest dbgpt --cov=dbgpt --cov-report=xml:coverage-${{ matrix.python-version }}-${{ matrix.os }}.xml --cov-report=html:htmlcov-${{ matrix.python-version }}-${{ matrix.os }} --junitxml=pytest_report-${{ matrix.python-version }}-${{ matrix.os }}.xml
- name: Generate coverage report summary
if: matrix.os == 'ubuntu-latest'
id: cov-report
run: |
coverage_file="coverage-${{ matrix.python-version }}-${{ matrix.os }}.xml"
# Pase the coverage file and get the line rate for each package(two level)
coverage_summary=$(grep -oP '<package name="\K[^"]+' $coverage_file | awk -F"." '{ if (NF == 2) print $0 }' | while read -r package_name; do
line_rate=$(grep -oP "<package name=\"$package_name\" line-rate=\"\K[^\"]+" $coverage_file)
echo "$package_name line-rate: $line_rate"
done)
echo "Coverage Summary: $coverage_summary"
echo "::set-output name=summary::$coverage_summary"
- name: Generate test report summary
if: matrix.os == 'ubuntu-latest'
id: test-report
run: |
test_file="pytest_report-${{ matrix.python-version }}-${{ matrix.os }}.xml"
total_tests=$(grep -oP 'tests="\K\d+' $test_file)
failures=$(grep -oP 'failures="\K\d+' $test_file)
skipped=$(grep -oP 'skipped="\K\d+' $test_file)
test_summary="Total tests: $total_tests, Failures: $failures, Skipped: $skipped"
echo "Test Summary: $test_summary"
echo "::set-output name=summary::$test_summary"
- name: Comment PR with coverage and test report
if: github.event_name == 'pull_request' && matrix.os == 'ubuntu-latest'
uses: peter-evans/create-or-update-comment@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body: |
## Test Coverage and Report Summary
${{ steps.cov-report.outputs.summary }}
${{ steps.test-report.outputs.summary }}
- name: Upload test and coverage results
uses: actions/upload-artifact@v3
if: always()
with:
name: test-and-coverage-results-${{ matrix.python-version }}-${{ matrix.os }}
path: |
pytest_report-${{ matrix.python-version }}-${{ matrix.os }}.xml
coverage-${{ matrix.python-version }}-${{ matrix.os }}.xml
htmlcov-${{ matrix.python-version }}-${{ matrix.os }}/*
if-no-files-found: ignore