Skip to content

[feat]: 코드 커버리지 측정 자동화 #172

[feat]: 코드 커버리지 측정 자동화

[feat]: 코드 커버리지 측정 자동화 #172

Workflow file for this run

name: CI (빌드 및 테스트)
on:
pull_request:
branches:
- master
- develop
- 'weekly/**'
permissions:
contents: write
issues: write
pull-requests: write
jobs:
build-and-test:
runs-on: ubuntu-22.04
services:
mysql:
image: mysql:8.0
env:
MYSQL_DATABASE: ${{ secrets.MYSQL_DATABASE }}
MYSQL_USER: ${{ secrets.MYSQL_USER }}
MYSQL_PASSWORD: ${{ secrets.MYSQL_PASSWORD }}
MYSQL_ROOT_PASSWORD: ${{ secrets.MYSQL_ROOT_PASSWORD }}
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping -h localhost"
--health-interval=10s
--health-timeout=5s
--health-retries=5
redis:
image: redis
ports:
- 6379:6379
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Decode env.properties from GitHub Secrets
run: |
echo "${{ secrets.ENV_FILE }}" | base64 --decode > ./src/main/resources/env.properties
- name: Decode Firebase config from GitHub Secrets
run: |
echo "${{ secrets.FIREBASE_CONFIG }}" | base64 --decode > ./src/main/resources/splanet-firebase.json
- name: Set environment variables from env.properties
run: |
set -o allexport
source ./src/main/resources/env.properties
set +o allexport
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
java-version: '21'
distribution: 'temurin'
- name: Wait for MySQL to be ready
run: |
for i in {30..0}; do
if docker exec $(docker ps -q --filter name=mysql) mysqladmin ping -h localhost; then
echo "MySQL is ready"
break
fi
echo "Waiting for MySQL..."
sleep 1
done
if [ $i -eq 0 ]; then
echo "MySQL did not become ready in time"
docker logs $(docker ps -q --filter name=mysql)
exit 1
fi
- name: Build with Gradle
run: ./gradlew clean build -Dspring.profiles.active=test
- name: Run Tests and Generate Code Coverage Report
run: ./gradlew test jacocoTestReport -Dspring.profiles.active=test
- name: Upload Jacoco Report
uses: actions/upload-artifact@v3
with:
name: jacoco-report
path: build/reports/jacoco/test/jacocoTestReport.xml
- name: Post Coverage Comment to PR
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const coverageReport = fs.readFileSync('build/reports/jacoco/test/jacocoTestReport.xml', 'utf8');
const match = coverageReport.match(/<counter type="INSTRUCTION" missed="(\d+)" covered="(\d+)"\/>/);
if (match) {
const missed = parseInt(match[1]);
const covered = parseInt(match[2]);
const coverage = ((covered / (missed + covered)) * 100).toFixed(2);
const comment = `### Code Coverage Report\n\n- **Coverage**: ${coverage}%\n\n`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
} else {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "### Code Coverage Report\n\nUnable to parse coverage report."
});
}