Step4 - 🚀 4단계 - 자동차 경주(우승자) #2
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: Gradle PR test On GitHub Action | |
on: | |
pull_request: | |
types: [opened,reopened,synchronize] | |
jobs: | |
onPRTest: | |
runs-on: ubuntu-latest | |
steps: | |
- name: '소스 checkout' | |
uses: actions/checkout@master | |
- name: 'graalvm jdk21 setup' | |
uses: graalvm/setup-graalvm@v1 | |
with: | |
java-version: '21' | |
distribution: 'graalvm' | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
native-image-job-reports: 'true' | |
cache: 'gradle' | |
- name: 'gradle 빌드' | |
run: gradle build --no-daemon --parallel | |
- name: '커버리지 정보 및 요약' | |
run: | | |
echo 'CSV 파일에서 커버리지 정보 추출'; | |
awk -F',' 'NR > 1 {instructions_covered += $5; instructions_missed += $4; branches_covered += $7; branches_missed += $6} END {print instructions_covered, instructions_missed, branches_covered, branches_missed}' build/reports/jacoco/test/jacocoTestReport.csv > coverage.txt | |
read instructions_covered instructions_missed branches_covered branches_missed < coverage.txt | |
echo '커버리지 계산'; | |
total_instructions=$((instructions_covered + instructions_missed)) | |
total_branches=$((branches_covered + branches_missed)) | |
instruction_coverage=$(echo "scale=2; $instructions_covered / $total_instructions * 100" | bc) | |
echo '분모가 0일 경우, 커버리지를 'N/A'로 설정'; | |
if [ "$total_instructions" -eq 0 ]; then | |
instruction_coverage="N/A" | |
else | |
instruction_coverage=$(echo "scale=2; $instructions_covered / $total_instructions * 100" | bc)% | |
fi | |
if [ "$total_branches" -eq 0 ]; then | |
branch_coverage="N/A" | |
else | |
branch_coverage=$(echo "scale=2; $branches_covered / $total_branches * 100" | bc)% | |
fi | |
echo '# GitHub Action Summary' >> PR_summary.md | |
echo 'GITHUB_STEP_SUMMARY에 커버리지 정보 추가'; | |
echo "## JaCoCo 커버리지 요약" >> PR_summary.md | |
echo "- Instruction Coverage: $instruction_coverage" >> PR_summary.md | |
echo "- Branch Coverage: $branch_coverage" >> PR_summary.md | |
- name: 'PMD 리포트 요약' | |
run: | | |
echo 'PMD 파일에서 정보 추출: XML 구조에 의존적이므로 구조가 변경되면 스크립트도 업데이트가 필요'; | |
echo 'xml이 매우 크면 성능에 문제가 생길 수 있으므로 더 효율적인 파싱 방법의 고려가 필요'; | |
echo "## PMD Code Analysis" >> PR_summary.md | |
total_violations=$(grep -c '<violation' build/reports/pmd/main.xml||true) | |
if [ "$total_violations" -eq 0 ]; then | |
echo "### 문제 없음" >> PR_summary.md | |
else | |
echo "### Total Violations: $total_violations" >> PR_summary.md | |
echo '각 file 태그를 찾아 파일 경로를 추출하고, 내부의 violation 정보를 처리' | |
awk '/<file name=/,/<\/file>/' build/reports/pmd/main.xml | awk ' | |
/<file name="/ { | |
filename=gensub(/.*<file name="([^"]+).*/, "\\1", "g"); | |
print "### File: " filename; | |
print "### File: " filename >> "PR_summary.md"; | |
next; | |
} | |
/<violation/,/<\/violation>/ { | |
if ($0 ~ /<violation/) { | |
line=gensub(/.*beginline="([^"]+).*/, "\\1", "g"); | |
url=gensub(/.*externalInfoUrl="([^"]+).*/, "\\1", "g"); | |
capturing = 1; | |
content = ""; | |
} else if ($0 ~ /<\/violation>/) { | |
print "- Line " line ": [" content "](" url ")"; | |
print "- Line " line ": [" content "](" url ")" >> "PR_summary.md"; | |
capturing = 0; | |
} else if (capturing) { | |
content = content $0; | |
} | |
} | |
' | |
fi | |
cat PR_summary.md >> $GITHUB_STEP_SUMMARY | |
- name: 'PR Comment에 SUMMARY Report 작성' | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
issue-number: ${{ github.event.pull_request.number }} | |
body-path: 'PR_summary.md' | |
- name: '실패 시 보고서 업로드' | |
uses: actions/upload-artifact@v4 | |
if: failure() | |
with: | |
name: report-jacoco | |
path: | | |
build/reports/jacoco/test/html | |
build/reports/pmd/*.html | |
- name: 'slack 알림' | |
uses: 8398a7/action-slack@v3 | |
if: always() | |
with: | |
status: ${{ job.status }} | |
author_name: my workflow bot | |
fields: repo,message,commit,author,eventName,ref,workflow,job,took, | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |