chore(ci): generate pytest summary #138
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test | |
on: | |
push: | |
branches: | |
- "main" | |
pull_request: | |
types: [opened, synchronize, reopened] | |
paths: | |
- "src/**" | |
- "tests/**" | |
jobs: | |
check: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-latest, macos-latest, windows-latest] | |
python-version: ["3.10", "3.11", "3.12"] | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
cache: "pip" | |
cache-dependency-path: "requirements-dev.txt" | |
- name: Install Dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements-dev.txt | |
- name: Run pytest and capture output (Linux/macOS) | |
if: runner.os != 'Windows' | |
run: | | |
pytest --cov --cov-report=xml | tee pytest_output.txt | |
test ${PIPESTATUS[0]} -eq 0 # 检查 pytest 的退出状态码 | |
echo "# Pytest Results Summary" >> $GITHUB_STEP_SUMMARY | |
cat pytest_output.txt >> $GITHUB_STEP_SUMMARY | |
- name: Run pytest and capture output (Windows) | |
if: runner.os == 'Windows' | |
run: | | |
pytest --cov --cov-report=xml | Out-File -FilePath pytest_output.txt -Encoding utf8 | |
if ($?) { exit 0 } else { exit 1 } # 检查 pytest 的退出状态码 | |
echo "# Pytest Results Summary" >> $env:GITHUB_STEP_SUMMARY | |
Get-Content pytest_output.txt | Out-File -Append -FilePath $env:GITHUB_STEP_SUMMARY | |
- name: Upload results to Codecov | |
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12' | |
uses: codecov/codecov-action@v4 | |
with: | |
verbose: true | |
token: ${{ secrets.CODECOV_TOKEN }} |