Skip to content

[FEATURE] 리팩터링 챕터 7 작성 완료 #7

[FEATURE] 리팩터링 챕터 7 작성 완료

[FEATURE] 리팩터링 챕터 7 작성 완료 #7

Workflow file for this run

name: PR Test & Coverage Report
on:
pull_request:
branches:
- main
jobs:
test:
name: Run Tests & Coverage
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12.6'
- name: Install Poetry
run: |
pipx install poetry
- name: Install Dependencies
run: |
poetry install --no-root
- name: Run Tests (by Makefile)
run: |
poetry run make test
- name: Combine Coverage Report (XML)
run: |
poetry run coverage xml -o coverage.xml
- name: Parse Coverage for Comment
id: coverage-comment
run: |
percentage=$(poetry run python -c "
import xml.etree.ElementTree as ET
tree = ET.parse('coverage.xml')
root = tree.getroot()
line_rate = float(root.attrib['line-rate'])
print(f'{line_rate * 100:.2f}')
")
echo "COVERAGE_PERCENT=$percentage" >> "$GITHUB_OUTPUT"
- name: Parse JUnit Results for Summary
id: junit-summary
run: |
summary=$(poetry run python -c "
import xml.etree.ElementTree as ET
import glob
total_tests = 0
total_failures = 0
total_skipped = 0
total_errors = 0
total_time = 0.0
for file in glob.glob('test-results/*.xml'):
tree = ET.parse(file)
root = tree.getroot()
total_tests += int(root.attrib['tests'])
total_failures += int(root.attrib['failures'])
total_skipped += int(root.attrib['skipped'])
total_errors += int(root.attrib.get('errors', 0))
total_time += float(root.attrib.get('time', 0))
passed = total_tests - total_failures - total_skipped
print(f'PASSED={passed}')
print(f'FAILED={total_failures}')
print(f'SKIPPED={total_skipped}')
print(f'TIME={total_time:.2f}')
")
echo "$summary" >> "$GITHUB_OUTPUT"
- name: Publish Test Results Summary (optional)
uses: test-summary/action@v2
with:
paths: "test-results/*.xml"
if: always()
- name: Upload Coverage HTML Report
uses: actions/upload-artifact@v4
with:
name: coverage-html
path: htmlcov/
- name: Upload JUnit XML (for archive)
uses: actions/upload-artifact@v4
with:
name: junit-xml-reports
path: test-results/
- name: Add Test & Coverage Summary Comment to PR
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
## 📝 Test & Coverage Report
| Metric | Value |
|--------|-----|
| ✅ Passed | ${{ steps.junit-summary.outputs.PASSED }} |
| ❌ Failed | ${{ steps.junit-summary.outputs.FAILED }} |
| ⏩ Skipped | ${{ steps.junit-summary.outputs.SKIPPED }} |
| ⏱️ Time | ${{ steps.junit-summary.outputs.TIME }}s |
| 📊 Line Coverage | ${{ steps.coverage-comment.outputs.COVERAGE_PERCENT }}% |
token: ${{ secrets.PAT_TOKEN }}