[FEATURE] 리팩터링 챕터 7 작성 완료 #6
Workflow file for this run
This file contains hidden or 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: 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 and Write Summary | |
| run: | | |
| 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']) | |
| percentage = line_rate * 100 | |
| with open('${{ github.step_summary }}', 'a') as f: | |
| f.write('| Metric | Value |\n') | |
| f.write('|--------|-----|\n') | |
| f.write(f'| 📊 Line Coverage | {percentage:.2f}% |\n') | |
| " | |
| - name: Publish Test Results Summary | |
| 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: 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: Add Coverage Comment to PR | |
| uses: peter-evans/create-or-update-comment@v4 | |
| with: | |
| issue-number: ${{ github.event.pull_request.number }} | |
| body: | | |
| ## 📝 Coverage Report | |
| | Metric | Value | | |
| |--------|-----| | |
| | 📊 Line Coverage | ${{ steps.coverage-comment.outputs.COVERAGE_PERCENT }}% | | |
| token: ${{ secrets.PAT_TOKEN }} |