Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CHORE] CI 스크립트 작성 #21

Merged
merged 14 commits into from
Dec 15, 2024
Merged

[CHORE] CI 스크립트 작성 #21

merged 14 commits into from
Dec 15, 2024

Conversation

coli-geonwoo
Copy link
Contributor

@coli-geonwoo coli-geonwoo commented Dec 13, 2024

🚩 연관 이슈

closed #20
closed #22

⭐ CI Description

  • event trigger: develop 브랜치에 PR이 발생(PR branch의 새로운 push도 포함)
  • 스크립트 timeout : 2분
  1. test를 수행합니다.
  2. Junit Test Report를 발행합니다.
  3. Jacoco 라이브러리를 통해 테스트 커버리지를 검증합니다.
      - name: Report test Coverage to PR
        id: jacoco
        uses: madrapps/[email protected]
        with:
          title: 📝 Test Coverage Report
          paths: ${{ github.workspace }}/build/reports/jacoco/test/jacocoTestReport.xml
          token: ${{ secrets.GITHUB_TOKEN }}
          min-coverage-overall: 80
          min-coverage-changed-files: 80
          update-comment: true
          debug-mode: true
- min-coverage-overall: 전체 코드 커버리지 기준
- min-coverage-changed-files: 변경한 파일에 대한 테스트 커버리지
- update-comment: 스크립트가 돌때마다 새로 생성하지 않고 PR 내에 comment를 업데이트
- debug-mode: 오류 발생시 디버깅 모드로 돌리고 에러 내역을 콘솔에 출력

🗣️ 리뷰 요구사항 (선택)

@coli-geonwoo coli-geonwoo linked an issue Dec 13, 2024 that may be closed by this pull request
1 task
@unifolio0 unifolio0 self-requested a review December 13, 2024 15:23
@unifolio0 unifolio0 added the chore 기타 label Dec 13, 2024
@unifolio0 unifolio0 requested a review from leegwichan December 13, 2024 15:23
Copy link

github-actions bot commented Dec 13, 2024

Test Results

1 tests   1 ✅  0s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit 4f11bf8.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Dec 13, 2024

📝 Test Coverage Report

Overall Project 85.71% 🍏

There is no coverage information present for the Files changed

Copy link
Contributor

@leegwichan leegwichan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/noti
PR을 통해 정상 작동 확인했습니다!
제안 사항 달아 두었으니 가능한 부분만 반영 부탁드릴께요!

.github/workflows/Backend_Dev_CI.yml Outdated Show resolved Hide resolved
build.gradle Outdated
Comment on lines 56 to 59
tasks.named('test') {
useJUnitPlatform()
finalizedBy jacocoTestReport
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[제안] local에서 테스트할 때도 항상 jacocoTestReport가 실행될 것 같은데, 더 좋은 방안 없을까요? (특정 옵션을 주어야만 작동하게 한다거나 등등...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TEST_REPORT 환경변수 옵션에 따라서 실행여부를 결정하도록 하였습니다.

  • local에서는 환경변수가 없어서 실행되지 않음
  • Script 상에서는 env 설정을 통해
jacocoTestReport {
    dependsOn test
    reports {
        xml.required.set(true)
        csv.required.set(false)
        html.required.set(false)
    }

    //dto는 테스트 대상에서 제외
    afterEvaluate {
        classDirectories.setFrom(files(classDirectories.files.collect {
            fileTree(dir: it, exclude: [
                    "com/debatetimer/**/dto/**"
            ])
        }))
    }

    **onlyIf {
        return System.getenv('TEST_REPORT') == 'true'
    }**
}

CI script 에서 환경 변수 설정

name: dev-ci

on:
  pull_request:
    branches:
      - develop

permissions: write-all

jobs:
  build-and-push:
    runs-on: ubuntu-latest
    timeout-minutes: 2
    env:
      TEST_REPORT: true

@coli-geonwoo coli-geonwoo linked an issue Dec 14, 2024 that may be closed by this pull request
@coli-geonwoo
Copy link
Contributor Author

/noti

  • gradle 캐싱 활용하도록 수정
  • lombok & dto 클래스 테스트 되지 않도록 수정
  • local에서는 test report 발행되지 않도록 수정

Copy link
Contributor

@unifolio0 unifolio0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/noti
콜리 ci 스크립트에 관해서 궁금한 부분이 있어 RC 남겼어요~
확인 부탁드려요

Comment on lines 26 to 35
- name: Cache Gradle dependencies
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: |
${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gradle을 캐싱하는 부분 같은데 gitHub 공식문서에서는 actions의 활용을 권장하고 있습니다.
https://docs.github.com/ko/actions/use-cases-and-examples/building-and-testing/building-and-testing-java-with-gradle#caching-dependencies

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 반영 완료!

branches:
- develop

permissions: write-all
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

쓰기 권한이 너무 광범위 한 것 같아요. 필요한 권한만 주는 건 어떤가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 반영 완료

permissions:
  contents: read
  checks: write
  pull-requests: write

jobs:
build-and-push:
runs-on: ubuntu-latest
timeout-minutes: 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2분으로 설정한 기준이 궁금해요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

도메인이 커진 오디 CI 스크립트가 1분 40초정도 소모되어 현재 프로젝트 규모에서 확장된 상황을 감안했을 때에도 2분이라는 기준이 이상치를 판단하기에 적정한 기준이라 생각했던 것 같아요.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

다시 보니 1분 40초가 아니라 2분 40초 정도였네요... 3분으로 늘려주었습니다. GPT도 gradle test까지 2분은 너무 짧다고 하네요 😓

Comment on lines 43 to 65
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: ${{ github.workspace }}/build/test-results/**/*.xml

- name: JUnit Report Action
uses: mikepenz/action-junit-report@v4
if: always()
with:
report_paths: ${{ github.workspace }}/build/test-results/**/*.xml

- name: Report test Coverage to PR
id: jacoco
uses: madrapps/[email protected]
with:
title: 📝 Test Coverage Report
paths: ${{ github.workspace }}/build/reports/jacoco/test/jacocoTestReport.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 80
min-coverage-changed-files: 80
update-comment: true
debug-mode: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이건 제가 잘 몰라서 질문드립니다.
지금 Publish Test ResultsJUnit Report Actionif: always()를 통해 앞의 step이 실패해도 동작하게 하는 것 같은데 Report test Coverage to PR는 그런 조건이 없어도 앞의 step에서 실패해도 동작하나요?
해당 부분이 테스트 결과를 PR에 코멘트로 올리는 부분 같은데 if: always()이게 없어도 작동하는 지 궁금해서 질문드립니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ [반영 완료]

if: always()추가해주었습니다.

이전에 실패한 스크립트 파일을 보니 실행이 되지 않네요! 디테일한 부분 리뷰남겨주어서 고마워요 비토! 역시 👍
image

@coli-geonwoo
Copy link
Contributor Author

/noti

@unifolio0

리뷰 모두 반영하였고 의견도 남겼으니 천천히 살펴봐주세요~

Copy link
Contributor

@unifolio0 unifolio0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/noti
리뷰 관련해서 다 확인했습니다!
근데 정말 사소한 궁금증 있어서 RC 남겨요~

Comment on lines 3 to 8
on:
push:
branches:
- chore/#20
pull_request:
branches:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 조건은 왜 필요한가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

permissions 관련해서 push하면서 실험해보다가 원상복구 해주었는데, local에서만 반영되고 push가 안되었어요 😓 복구해주었습니다!

@coli-geonwoo
Copy link
Contributor Author

/noti

트리거 원상복구 반영하였습니다! (local에서 수정하고 복구된 부분이 push가 안되었었네요 😓 ) ㅎㅎ 꼼꼼한 비토와의 PR 벌써부터 기대되어요 💪

Copy link
Contributor

@unifolio0 unifolio0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/noti
깔끔하네요. merge도 바로 하겠습니다!

@unifolio0 unifolio0 merged commit edd7dfb into develop Dec 15, 2024
5 checks passed
@unifolio0 unifolio0 deleted the chore/#20 branch December 15, 2024 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore 기타
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[CHORE] CI 스크립트 캐싱 추가 & jacocoTest 로컬 제외 [CHORE] CI 스크립트 작성
3 participants