본문 바로가기
개인 공부/TIL

TIL : gradle-build-action (짧)

by 희조당 2023. 10. 27.

🏃‍♂️ Github Action

이번에 CI를 작성하면서 시간이 생각보다 더 걸려서 gradle을 캐싱해야 하는 일이 생겼다.

처음에는 "CI를 굳이 어렵게 가야하나? 적당히 긁어와서 쓰자"라는 생각으로 다음 코드를 붙여서 사용했다.

- name: Gradle Caching
  uses: actions/cache@v3
  with:
    path: |  
        ~/.gradle/caches
        ~/.gradle/wrapper
    key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
    restore-keys: |
        ${{ runner.os }}-gradle-

 

근데 뭔가 시간적으로 개선이 안되는 것 같아서 "다른 방법이 없을까 🤔..?" 하고 조금 알아봤다.

찾아보니 3가지 방법으로 gradle을 캐싱할 수 있었다.

  1. actions/setup-java에서 cache 옵션에 'gradle' 넣어주기
  2. actions/cache 위와 같이 사용하기
  3. actions/gradle-build-action 사용하기

"어느 것이 더 좋을까?" 고민하면서 각각을 비교하다가 gradle-build-action을 선택했다.

🙉 gradle-build-action

공식문서를 들어가서 읽어보니까 다음과 같이 설명되어 있다.

However, the gradle-build-action offers a number of advantages over this approach:
  1. Easily configure your workflow to use a specific version of Gradle using the gradle-version parameter. Gradle distributions are automatically downloaded and cached.
  2. More sophisticated and more efficient caching of Gradle User Home between invocations, compared to setup-java and most custom configurations using actions/cache.
  3. Detailed reporting of cache usage and cache configuration options allow you to optimize the use of the GitHub actions cache.
  4. Generate and Submit a GitHub Dependency Graph for your project, enabling Dependabot security alerts.
  5. Automatic capture of Build Scan® links from the build, making these easier to locate for workflow run.

 

번역해서 요약하면 다음과 같다.

  • 다른 action들과 비교했을 때 caching이 더 효율적이다.
  • 특정 버전을 명시해서 사용할 수 있다.
  • Github 의존성 그래프를 자동으로 생성하고 제출해준다. (잘 모르겠음 🥹, 굳이 알아야할까?)
  • 빌드 스캔으로 워크플로우를 더 쉽게 찾을 수 있다. (잘 모르겠음 🥹, 굳이 알아야할까?)
  • 사용 시 후속 단계에 사용되는 모든 gradle 옵션에 적용된다.

단순히 캐싱이 더 효율적이라는 말 때문에만 선택한 것은 아니다.

캐싱을 할 때 특정 브랜치는 read-only로 지정할 수 있다는 점과 debug 모드를 지원한다는 점 때문에 선택했다.

 

다음과 같이 적용해서 사용했다.

여기서 cache-read-only 조건은 main 브랜치는 읽기만 가능하다고 명시해주었다. (사실 브랜치가 많을 때나 의미가 있을 것 같다.)

- name: Setup Gradle w/ caching
  uses: gradle/gradle-build-action@v2.9.0
  with:
    gradle-version: ${{ env.GRADLE_VERSION }}
    cache-read-only: ${{ github.ref == 'refs/heads/main' }}

 

어쨌거나 저쨌거나 캐싱을 통해서 많이 시간을 줄일 수 있었다.


 

😋 지극히 개인적인 블로그지만 댓글, 조언 그리고 좋아요는 제 성장에 도움이 됩니다 😋

댓글