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
55 changes: 55 additions & 0 deletions .github/workflows/Backend_Dev_CI.yml
coli-geonwoo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: backend-ci-dev

on:
pull_request:
branches:
- develop

permissions: write-all

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

steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Grant Permission
run: chmod +x ./gradlew

- name: Clean And Test With Gradle
run: ./gradlew clean test

- 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
15 changes: 15 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'java'
id 'jacoco'
id 'org.springframework.boot' version '3.4.0'
id 'io.spring.dependency-management' version '1.1.6'
}
Expand Down Expand Up @@ -39,6 +40,20 @@ dependencies {
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0'
}

jacoco {
toolVersion = '0.8.9'
}

jacocoTestReport {
dependsOn test
reports {
xml.required.set(true)
csv.required.set(false)
html.required.set(false)
}
}

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

Loading