Skip to content

Step4 carracing (#5541) #1

Step4 carracing (#5541)

Step4 carracing (#5541) #1

Workflow file for this run

name: Gradle test On GitHub Action
on:
push:
branches-ignore: ['main','master']
jobs:
onPushTest:
runs-on: ubuntu-latest
steps:
- name: '소스 checkout'
uses: actions/checkout@master
- name: 'jdk21 setup'
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '21'
cache: 'gradle'
- name: 'gradle test'
run: |
echo "Available processors: $(nproc)"
gradle test --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' >> PUSH_summary.md
echo 'GITHUB_STEP_SUMMARY에 커버리지 정보 추가';
echo "## JaCoCo 커버리지 요약" >> PUSH_summary.md
echo "- Instruction Coverage: $instruction_coverage" >> PUSH_summary.md
echo "- Branch Coverage: $branch_coverage" >> PUSH_summary.md
- name: 'PMD 리포트 요약'
run: |
echo 'PMD 파일에서 정보 추출: XML 구조에 의존적이므로 구조가 변경되면 스크립트도 업데이트가 필요';
echo 'xml이 매우 크면 성능에 문제가 생길 수 있으므로 더 효율적인 파싱 방법의 고려가 필요';
echo "## PMD Code Analysis" >> PUSH_summary.md
total_violations=$(grep -c '<violation' build/reports/pmd/main.xml||true)
if [ "$total_violations" -eq 0 ]; then
echo "### 문제 없음" >> PUSH_summary.md
else
echo "### Total Violations: $total_violations" >> PUSH_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 >> "PUSH_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 ")" >> "PUSH_summary.md";
capturing = 0;
} else if (capturing) {
content = content $0;
}
}
'
fi
cat PUSH_summary.md >> $GITHUB_STEP_SUMMARY
- 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 }}