jeuko's picture
Sync from GitHub (main)
8018595 verified
name: 'Pytest'
description: 'Pytest'
runs:
using: 'composite'
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
- name: Install dependencies
shell: bash
run: |
uv sync --frozen
- name: Run all tests with coverage
id: pytest
shell: bash
run: |
echo "## Pytest Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if uv run pytest tests/ -v --tb=short --junitxml=pytest-results.xml --cov=src --cov-report=term-missing --cov-report=xml --cov-report=html 2>&1 | tee pytest-output.txt; then
echo "βœ… **All tests passed!**" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Extract test summary from pytest output
if grep -q "passed" pytest-output.txt; then
passed_count=$(grep -o '[0-9]\+ passed' pytest-output.txt | grep -o '[0-9]\+' | head -1)
echo "| Status | Count |" >> $GITHUB_STEP_SUMMARY
echo "|--------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| βœ… Passed | $passed_count |" >> $GITHUB_STEP_SUMMARY
fi
if grep -q "skipped" pytest-output.txt; then
skipped_count=$(grep -o '[0-9]\+ skipped' pytest-output.txt | grep -o '[0-9]\+' | head -1)
echo "| ⏭️ Skipped | $skipped_count |" >> $GITHUB_STEP_SUMMARY
fi
if grep -q "warnings" pytest-output.txt; then
warnings_count=$(grep -o '[0-9]\+ warnings' pytest-output.txt | grep -o '[0-9]\+' | head -1)
echo "| ⚠️ Warnings | $warnings_count |" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "### πŸ“Š Test Summary" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
tail -10 pytest-output.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
else
echo "❌ **Some tests failed**" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Extract test summary from pytest output
if grep -q "passed" pytest-output.txt; then
passed_count=$(grep -o '[0-9]\+ passed' pytest-output.txt | grep -o '[0-9]\+' | head -1)
echo "| Status | Count |" >> $GITHUB_STEP_SUMMARY
echo "|--------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| βœ… Passed | $passed_count |" >> $GITHUB_STEP_SUMMARY
fi
if grep -q "failed" pytest-output.txt; then
failed_count=$(grep -o '[0-9]\+ failed' pytest-output.txt | grep -o '[0-9]\+' | head -1)
echo "| ❌ Failed | $failed_count |" >> $GITHUB_STEP_SUMMARY
fi
if grep -q "skipped" pytest-output.txt; then
skipped_count=$(grep -o '[0-9]\+ skipped' pytest-output.txt | grep -o '[0-9]\+' | head -1)
echo "| ⏭️ Skipped | $skipped_count |" >> $GITHUB_STEP_SUMMARY
fi
if grep -q "warnings" pytest-output.txt; then
warnings_count=$(grep -o '[0-9]\+ warnings' pytest-output.txt | grep -o '[0-9]\+' | head -1)
echo "| ⚠️ Warnings | $warnings_count |" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "<details>" >> $GITHUB_STEP_SUMMARY
echo "<summary>πŸ“‹ Click to see detailed test output</summary>" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
cat pytest-output.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "</details>" >> $GITHUB_STEP_SUMMARY
exit 1
fi
# Coverage report (shown for both success and failure)
echo "" >> $GITHUB_STEP_SUMMARY
echo "### πŸ“ˆ Coverage Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Convert coverage output to markdown table
python3 ${GITHUB_ACTION_PATH}/markdown.py pytest-output.txt >> $GITHUB_STEP_SUMMARY