test: 아이디/비번 찾기 테스트 코드 재작성 #79
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: Java CI/CD with Gradle and SonarCloud | |
| on: | |
| push: | |
| branches: [ "main", "develop" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| jobs: | |
| CI: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # SonarCloud에서 전체 히스토리 필요 | |
| # .gitignore에 있는 properties파일 추가 | |
| - name: Add prod_properties | |
| run: | | |
| mkdir -p ./src/main/resources | |
| mkdir -p ./src/main/resources/firebase | |
| touch ./src/main/resources/application.properties | |
| touch ./src/main/resources/firebase/firebase_service_key.json | |
| echo "${{ secrets.PROPERTIES }}" > ./src/main/resources/application.properties | |
| echo '${{ secrets.FIREBASE_JSON }}' > ./src/main/resources/firebase/firebase_service_key.json | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '21' # 프로젝트에 맞춰 21로 변경 | |
| distribution: 'temurin' | |
| # SonarCloud 패키지 캐시 | |
| - name: Cache SonarCloud packages | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.sonar/cache | |
| key: ${{ runner.os }}-sonar | |
| restore-keys: ${{ runner.os }}-sonar | |
| # Gradle 캐시 | |
| - name: Cache Gradle packages | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.gradle/caches | |
| key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} | |
| restore-keys: ${{ runner.os }}-gradle | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x gradlew | |
| # 1단계: 테스트 및 커버리지 생성 (실패해도 계속 진행) | |
| - name: Run tests and generate coverage | |
| run: ./gradlew clean test jacocoTestReport --continue | |
| continue-on-error: true # 테스트 실패해도 SonarCloud 분석은 진행 | |
| # 2단계: SonarCloud 분석 실행 | |
| - name: Analyze with SonarCloud | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
| run: | | |
| # 디버깅을 위한 정보 출력 | |
| echo "SONAR_PROJECT_KEY: ${{ secrets.SONAR_PROJECT_KEY }}" | |
| echo "SONAR_ORGANIZATION: ${{ secrets.SONAR_ORGANIZATION }}" | |
| ./gradlew sonar \ | |
| -Dsonar.projectKey=${{ secrets.SONAR_PROJECT_KEY }} \ | |
| -Dsonar.organization=${{ secrets.SONAR_ORGANIZATION }} \ | |
| -Dsonar.host.url=https://sonarcloud.io \ | |
| -Dsonar.token=${{ secrets.SONAR_TOKEN }} \ | |
| -Dsonar.gradle.skipCompile=true \ | |
| -Dsonar.qualitygate.wait=false \ | |
| --info --stacktrace | |
| continue-on-error: true | |
| # 3단계: 빌드 (테스트 제외) | |
| - name: Build with Gradle Wrapper | |
| run: ./gradlew build --exclude-task test | |
| # 4단계: 품질 리포트 아티팩트 업로드 | |
| - name: Upload quality reports | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: quality-reports-${{ github.run_number }} | |
| path: | | |
| build/reports/tests/test/ | |
| build/jacocoReport/test/html/ | |
| retention-days: 30 | |
| # 5단계: PR에 품질 리포트 코멘트 추가 | |
| - name: Comment PR with quality results | |
| if: github.event_name == 'pull_request' | |
| uses: actions/github-script@v6 | |
| with: | |
| script: | | |
| const projectKey = '${{ secrets.SONAR_PROJECT_KEY }}'; | |
| const organization = '${{ secrets.SONAR_ORGANIZATION }}'; | |
| const sonarUrl = `https://sonarcloud.io/project/overview?id=${projectKey}`; | |
| const runNumber = '${{ github.run_number }}'; | |
| const comment = ` | |
| ## 🔍 코드 품질 검사 결과 (Build #${runNumber}) | |
| ### 📊 SonarCloud 분석 | |
| 🔗 **[SonarCloud 대시보드에서 상세 결과 확인](${sonarUrl})** | |
| ### 📈 주요 체크 항목 | |
| - ✅ 정적 코드 분석 완료 | |
| - ✅ 코드 커버리지 측정 완료 | |
| - ✅ 보안 취약점 스캔 완료 | |
| - ✅ 코드 복잡도 분석 완료 | |
| ### 📋 리포트 다운로드 | |
| - [테스트 & 커버리지 리포트 다운로드](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) | |
| > 💡 **참고**: "Previous version" 설정으로 새로 변경된 코드만 엄격하게 검사됩니다. | |
| --- | |
| 🤖 자동 생성된 품질 리포트 | SonarCloud Integration | |
| `; | |
| if (context.issue.number) { | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: comment | |
| }); | |
| } | |
| # 6단계: Docker Image Build and Push (기존 로직 유지) | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Set up Docker Build | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| tags: | | |
| ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}:latest | |
| ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}:build-${{ github.run_number }} | |
| ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}:${{ github.sha }} | |
| # 7단계: CD 배포 (기존 로직 유지) | |
| - name: Deploy to production server | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.DEPLOYMENT_HOST }} | |
| username: ${{ secrets.DEPLOYMENT_USERNAME }} | |
| key: ${{ secrets.SSH_KEY }} | |
| script_stop: true | |
| script: | | |
| cd neeis | |
| chmod +x ./deploy.sh | |
| ./deploy.sh | |
| echo "🚀 배포 완료: $(date '+%Y-%m-%d %H:%M:%S')" | |
| # 8단계: 배포 성공 알림 (선택사항) | |
| - name: Notify deployment success | |
| if: success() | |
| run: | | |
| echo "✅ 전체 CI/CD 파이프라인 성공!" | |
| echo "📊 SonarCloud: https://sonarcloud.io/project/overview?id=${{ secrets.SONAR_PROJECT_KEY }}" | |
| echo "🐳 Docker Hub: https://hub.docker.com/r/${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}" |