Skip to content

refactor: GitHub Actions 워크플로우 최적화 완료 #1

refactor: GitHub Actions 워크플로우 최적화 완료

refactor: GitHub Actions 워크플로우 최적화 완료 #1

name: Test and Quality Analysis
on:
pull_request:
permissions:
pull-requests: write
contents: read
actions: read
checks: write
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Java and Gradlew
uses: ./.github/actions/setup-java-and-gradlew
with:
java-distribution: 'liberica'
java-version: '21'
java-package: 'jdk'
- name: Run tests with Gradle
run: ./gradlew test jacocoTestReport --info --parallel
env:
SPRING_PROFILES_ACTIVE: test
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: '**/build/reports/tests/test/*'
- name: Upload coverage results
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: '**/build/reports/jacoco/test/jacocoTestReport.xml'
- name: Test Reporter
id: reporter
uses: dorny/test-reporter@v1
if: always()
with:
name: Spring Boot Tests
path: '**/build/test-results/test/*.xml'
reporter: java-junit
only-summary: false
list-suites: all
list-tests: all
max-annotations: 50
fail-on-error: true
fail-on-empty: true
- name: Compute Metrics
if: always()
run: |
total=$(( ${PASSED:-0} + ${FAILED:-0} + ${SKIPPED:-0} ))
time_in_seconds=$(echo "scale=2; ${TIME_MS:-0} / 1000" | bc)
echo "total=$total" >> $GITHUB_ENV
echo "time_in_seconds=$time_in_seconds" >> $GITHUB_ENV
env:
PASSED: ${{ steps.reporter.outputs.passed }}
FAILED: ${{ steps.reporter.outputs.failed }}
SKIPPED: ${{ steps.reporter.outputs.skipped }}
TIME_MS: ${{ steps.reporter.outputs.time }}
- name: Post Test Results to PR
uses: marocchino/sticky-pull-request-comment@v2
if: always()
with:
header: Test Results
recreate: true
message: |
## 🛠️ Test Summary (${{ steps.reporter.outputs.conclusion }})
📄 **[View Detailed Test Logs](${{ steps.reporter.outputs.url_html }})**
| **Metrics** | **Test Result Details** |
|-----------------------|---------------------------------------|
| **Total Tests** | ${{ env.total }} |
| ✅ **Tests Passed** | ${{ steps.reporter.outputs.passed }} |
| ❌ **Tests Failed** | ${{ steps.reporter.outputs.failed }} |
| ⚠️ **Tests Skipped** | ${{ steps.reporter.outputs.skipped }} |
| ⏱️ **Execution Time** | ${{ env.time_in_seconds }}s |
code_quality_analysis:
runs-on: ubuntu-latest
needs: test
if: always()
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download test results
uses: actions/download-artifact@v4
with:
name: test-results
- name: Download coverage report
uses: actions/download-artifact@v4
with:
name: coverage-report
- name: Setup Java and Gradlew
uses: ./.github/actions/setup-java-and-gradlew
with:
java-distribution: 'liberica'
java-version: '21'
java-package: 'jdk'
- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Run Checkstyle
run: ./gradlew checkstyleMain checkstyleTest -x test --info
- name: Run JaCoCo Test Coverage Verification
run: ./gradlew jacocoTestCoverageVerification -x test -x jacocoTestReport --info
continue-on-error: true
- name: Run SonarCloud Analysis
run: ./gradlew sonar --info
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}