shinsunyoung / springboot-developer

📚 <스프링부트 3 백엔드 개발자 되기> 예제코드
230 stars 92 forks source link

[Chapter 12] 깃허브 액션 빌드 에러 발생 #62

Open SummerToday opened 5 months ago

SummerToday commented 5 months ago
Downloading https://services.gradle.org/distributions/gradle-8.5-bin.zip
............10%.............20%............30%.............40%.............50%............60%.............[7](https://github.com/SummerToday/Blog_SpringProject/actions/runs/9050079781/job/24865312477#step:5:8)0%.............[8](https://github.com/SummerToday/Blog_SpringProject/actions/runs/9050079781/job/24865312477#step:5:9)0%............90%.............100%

Welcome to Gradle 8.5!

Here are the highlights of this release:
 - Support for running on Java 21
 - Faster first use with Kotlin DSL
 - Improved error and warning messages

For more details see https://docs.gradle.org/8.5/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)
> Task :clean UP-TO-DATE

Note: /home/runner/work/Blog_SpringProject/Blog_SpringProject/src/main/java/me/InKyung/Blog/springbootdeveloper/util/CookieUtil.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
> Task :compileJava

> Task :processResources
> Task :classes
> Task :resolveMainClassName
> Task :bootJar
> Task :jar
> Task :assemble
> Task :compileTestJava
> Task :processTestResources NO-SOURCE
> Task :testClasses

> Task :test

BlogApplicationTest > contextLoads() FAILED
    java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:180
        Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException at ConstructorResolver.java:7[9](https://github.com/SummerToday/Blog_SpringProject/actions/runs/9050079781/job/24865312477#step:5:10)8
            Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException at AutowiredAnnotationBeanPostProcessor.java:895
                Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException at AutowiredAnnotationBeanPostProcessor.java:895
                    Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException at AutowiredAnnotationBeanPostProcessor.java:895
                        Caused by: org.springframework.beans.factory.BeanCreationException at ConstructorResolver.java:651
                            Caused by: org.springframework.beans.BeanInstantiationException at SimpleInstantiationStrategy.java:177
                                Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException at ConstructorResolver.java:798
                                    Caused by: org.springframework.beans.factory.BeanCreationException at AbstractAutowireCapableBeanFactory.java:1773
                                        Caused by: java.lang.IllegalStateException at OAuth2ClientProperties.java:68

TokenProviderTest > validToken(): 유효한 토큰인 경우에 유효성 검증에 성공한다. FAILED
    java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:145

TokenProviderTest > validToken(): 만료된 토큰인 경우에 유효성 검증에 실패한다. FAILED
    java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:145

TokenProviderTest > getAuthentication(): 토큰 기반으로 인증정보를 가져올 수 있다. FAILED
    java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:145

TokenProviderTest > getUserId(): 토큰으로 유저 ID를 가져올 수 있다. FAILED
    java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:145

TokenProviderTest > generateToken(): 유저 정보와 만료 기간을 전달해 토큰을 만들 수 있다. FAILED
    java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:145

BlogApiControllerTest > deleteArticle: 아티클 삭제에 성공한다. FAILED
    java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:180
        Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException at ConstructorResolver.java:798
            Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException at AutowiredAnnotationBeanPostProcessor.java:895
                Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException at AutowiredAnnotationBeanPostProcessor.java:895
                    Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException at AutowiredAnnotationBeanPostProcessor.java:895
                        Caused by: org.springframework.beans.factory.BeanCreationException at ConstructorResolver.java:651
                            Caused by: org.springframework.beans.BeanInstantiationException at SimpleInstantiationStrategy.java:177
                                Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException at ConstructorResolver.java:798
                                    Caused by: org.springframework.beans.factory.BeanCreationException at AbstractAutowireCapableBeanFactory.java:1773
                                        Caused by: java.lang.IllegalStateException at OAuth2ClientProperties.java:68

BlogApiControllerTest > findArticle: 아티클 단건 조회에 성공한다. FAILED
    java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:145

BlogApiControllerTest > findAllArticles: 아티클 목록 조회에 성공한다. FAILED
    java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:145

BlogApiControllerTest > addArticle: 아티클 추가에 성공한다. FAILED
    java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:145

BlogApiControllerTest > updateArticle: 아티클 수정에 성공한다. FAILED
    java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:145

TokenApiControllerTest > createNewAccessToken: 새로운 액세스 토큰을 발급한다. FAILED
    java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:145

[12](https://github.com/SummerToday/Blog_SpringProject/actions/runs/9050079781/job/24865312477#step:5:13) tests completed, 12 failed

FAILURE: Build failed with an exception.

* What went wrong:
> Task :test FAILED
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///home/runner/work/Blog_SpringProject/Blog_SpringProject/build/reports/tests/test/index.html

* Try:
> Run with --scan to get full insights.

BUILD FAILED in 33s

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.5/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
8 actionable tasks: 7 executed, 1 up-to-date
Error: Process completed with exit code 1.

깃허브 액션을 이용해 CI를 도입하면 위와 같이 Build with Gradle 단계에서 오류가 발생합니다.. 왜 그러는거죠..?? elastic beanstalk에 배포까지는 문제없이 잘 됐는데 CI를 적용하니까 문제가 발생하네요ㅜㅜ 깃허브 링크 첨부합니다! https://github.com/SummerToday/Blog_SpringProject.git

shinsunyoung commented 5 months ago

안녕하세요 로컬에서 테스트 돌렸을 때는 잘 되는데 CI 적용 이후 발생한 문제인가요??

SummerToday commented 5 months ago

네 로컬에서도 잘 돌아갔었고. elastic beanstalk에 배포 후에도 정상적으로 동작하였습니다. 깃허브 액션 CI 적용 하면 저 오류들이 발생합니다..

SummerToday commented 4 months ago

깃허브 액션 시크릿으로 환경변수를 설정하고, application.yml 파일을 다음과 같이 수정하고,

spring:
  jpa:
    show-sql: true
    properties:
      hibernate:
        format_sql: true
    defer-datasource-initialization: true

  h2:
    console:
      enabled: true
  security:
    oauth2:
      client:
        registration:
          google:
            client-id: ${OAUTH2_CLIENT_ID}
            client-secret: ${OAUTH2_CLIENT_SECRET}
            scope:
              - email
              - profile

jwt:
  issuer: qlql7748@gmail.com
  secret_key: study-springboot

ci.yml을 다음과 같이

name: CI

on:
  push:
    branches: [ main ]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - uses: actions/setup-java@v3
        with:
          distribution: 'corretto'
          java-version: '17'

      - name: Set up environment variables
        run: |
          echo "SPRING_PROFILES_ACTIVE=test" >> $GITHUB_ENV
          echo "OAUTH2_CLIENT_ID=${{ secrets.OAUTH2_CLIENT_ID }}" >> $GITHUB_ENV
          echo "OAUTH2_CLIENT_SECRET=${{ secrets.OAUTH2_CLIENT_SECRET }}" >> $GITHUB_ENV
          echo "OAUTH2_CLIENT_PROVIDER=google" >> $GITHUB_ENV
          echo "JWT_SECRET=study-springboot" >> $GITHUB_ENV

      - name: Grant execute permission for gradlew
        run: chmod +x gradlew

      - name: Build with Gradle
        run: ./gradlew clean build --warning-mode all

수정하였더니, 깃허브 액션에서 빌드가 성공적으로 되어 CI가 성공적으로 도입 되었습니다. 하지만 정확히 왜 고쳐진 것인지는 잘 모르겠습니다. 처음 제 생각으로는 깃허브 액션에서 OAuth2 변수들을 잡지 못하는 것 같아, ci.yml에 환경변수로 설정해주면 해결될 줄 알았는데, 결국은 application.yml까지 설정하고 나서야 해결이 되었습니다.. 왜 해결된 것인지 설명 좀 부탁드립니다ㅜㅜ 또한 작가님의 코드를 보면 이러한 설정 없이도 실행이 되시는 것 같았는데, 저는 왜 실행이 안되었던 것인지 궁금합니다.

shinsunyoung commented 2 months ago

안녕하세요! 제가 이 레포 알림 받는 것을 실수로 꺼두어서 이제 울렸네요 ㅠㅠ 늦게 답변드려서 죄송합니다. 자세한 로그를 봐야 알 수 있겠지만, 첨부해주신 로그를 보면

Caused by: java.lang.IllegalStateException at OAuth2ClientProperties.java:68

요 부분을 보아 OAuth2 관련 문제인 것 같은데요. https://github.com/SummerToday/Blog_SpringProject/blob/67d622ca41102cbba3bc5417f8784b340695614d/src/main/resources/application.yml 에 설정하신 것 보다 client-id, secret을 물결표시(~)로 해두셨는데 이렇게 설정하면 client-id 값을 가져올때 제대로 인식을 못하기 때문에 싱글 쿼터(')로 감싸주시거나 제가 예제에 작성한 것처럼 GOCSP.. 같이 입력하셔야 CI가 정상적으로 돌아갑니다.