@@ -13,62 +13,46 @@ jobs:
1313 runs-on : ${{ matrix.os }}
1414 strategy :
1515 matrix :
16- python-version : ["3.9", "3.10", "3.11", "3.12"]
17- os : [ubuntu-latest, windows-latest]
18- exclude :
19- - os : windows-latest
20- python-version : " 3.9"
21- - os : windows-latest
22- python-version : " 3.12"
23-
24- # カバレッジレポートを1回だけアップロードするための設定
25- outputs :
26- coverage : ${{ steps.coverage.outputs.coverage }}
16+ os : [ubuntu-latest, windows-latest, macos-latest]
17+ python-version : [3.9, "3.10", 3.11]
2718
2819 steps :
29- - uses : actions/checkout@v4
20+ - uses : actions/checkout@v3
21+ with :
22+ fetch-depth : 0
3023
3124 - name : Set up Python ${{ matrix.python-version }}
32- uses : actions/setup-python@v5
25+ uses : actions/setup-python@v4
3326 with :
3427 python-version : ${{ matrix.python-version }}
3528
3629 - name : Install dependencies
3730 run : |
3831 python -m pip install --upgrade pip
39- pip install pytest pytest-cov pytest-asyncio httpx aiosqlite
40- pip install pydantic-settings
41- pip install -r requirements.txt
42- pip install -r requirements-test.txt
32+ if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
33+ pip install pytest pytest-cov pytest-asyncio
4334
44- - name : Run tests with coverage
45- id : coverage
35+ - name : Run tests and generate coverage report
4636 run : |
47- # デバッグ情報を表示
48- python --version
49- pip list
50-
51- # テスト環境変数を設定
52- if [ "$RUNNER_OS" == "Linux" ] || [ "$RUNNER_OS" == "macOS" ]; then
53- export TESTING=True
54- export DATABASE_URL=sqlite+aiosqlite:///:memory:
55- elif [ "$RUNNER_OS" == "Windows" ]; then
56- echo "TESTING=True" >> $GITHUB_ENV
57- echo "DATABASE_URL=sqlite+aiosqlite:///:memory:" >> $GITHUB_ENV
58- fi
59-
60- # まずテストのみを実行して詳細なエラー情報を取得
61- python -m pytest tests/ -v
62-
63- # カバレッジレポートを生成
64- python -m pytest tests/ -v --cov=src --cov-report=xml:coverage.xml --cov-report=term-missing --cov-report=html
65-
66- # カバレッジの閾値チェック(70%未満で失敗)
67- python -m coverage report --fail-under=70
68-
69- # カバレッジのパーセンテージを取得
70- COVERAGE=$(python -c "import xml.etree.ElementTree as ET; print(ET.parse('coverage.xml').getroot().attrib['line-rate'])")
71- echo "coverage=${COVERAGE}" >> $GITHUB_OUTPUT
37+ if [ "$RUNNER_OS" == "Linux" ] || [ "$RUNNER_OS" == "macOS" ]; then
38+ export TESTING=True
39+ export DATABASE_URL=sqlite+aiosqlite:///:memory:
40+ export PYTHONPATH=src
41+ elif [ "$RUNNER_OS" == "Windows" ]; then
42+ echo "TESTING=True" >> $GITHUB_ENV
43+ echo "DATABASE_URL=sqlite+aiosqlite:///:memory:" >> $GITHUB_ENV
44+ echo "PYTHONPATH=src" >> $GITHUB_ENV
45+ fi
46+
47+ python -m pytest tests/ -v --import-mode=importlib
48+
49+ python -m pytest tests/ -v --cov=src --cov-report=xml:coverage.xml --cov-report=term-missing --cov-report=html
50+
51+ - name : Upload coverage to Codecov
52+ uses : codecov/codecov-action@v3
53+ with :
54+ file : ./coverage.xml
55+ fail_ci_if_error : true
7256
7357 - name : Upload coverage report artifact
7458 if : matrix.python-version == '3.10' && matrix.os == 'ubuntu-latest'
0 commit comments