Skip to content

Refactor/#397 experience #211

Refactor/#397 experience

Refactor/#397 experience #211

name: Run Test When Push Or PR To Develop
# develop 브런치에 push가 되면 아래의 flow가 실행됩니다.
on:
push:
branches: [ "develop" ]
pull_request:
branches: [ "develop" ]
# flow에서 사용할 변수
env:
AWS_REGION: ap-northeast-2
S3_BUCKET_NAME: nanaland-github-actions-s3-bucket
CODE_DEPLOY_APPLICATION_NAME: nanaland-codedeploy-app
CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: nanaland-codedeploy-deployment-group
permissions: write-all
jobs:
test:
runs-on: ubuntu-latest
environment: production
steps:
# 1) 기본 체크아웃
- name: Checkout
uses: actions/checkout@v4
# 2) JDK 17 셋팅
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
# 2.5) secret설정한 test yml 등록
- name: Set Test YML
run: |
mkdir -p src/main/resources
echo "${{ secrets.TEST_YML }}" | base64 --decode > src/main/resources/application-test.yml
find src
# 2.7) caching을 사용한 속도 향상
- name: Cache Gradle packages
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
# 3) gradlew 권한 설정
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Test with Gradle
run: SPRING_PROFILES_ACTIVE=[test] ./gradlew test -i
# 테스트 결과 확인하기
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: ${{ always() }}
with:
files: build/test-results/**/*.xml
# cache 관련 파일 제거
- name: Cleanup Gradle Cache
if: ${{ always() }}
run: |
rm -f ~/.gradle/caches/modules-2/modules-2.lock
rm -f ~/.gradle/caches/modules-2/gc.properties
build:
runs-on: ubuntu-latest
environment: production
steps:
# 1) 기본 체크아웃
- name: Checkout
uses: actions/checkout@v4
# 2) JDK 17 셋팅
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
# 2.5) secret설정한 yml 등록
- name: Set YML
run: |
mkdir -p src/main/resources
echo "${{ secrets.YML }}" | base64 --decode > src/main/resources/application.yml
find src
# # 4) gradle 테스트 빌드
# - name: Build Test with Gradle
# run: ./gradlew test -i
# # run: ./gradlew clean build -i
# # working-directory: ${{ env.working-directory }}
# 3) gradlew 권한 설정
- name: Grant execute permission for gradlew
run: chmod +x gradlew
# 4) gradle 빌드
- name: Build with Gradle
run: ./gradlew clean build -x test -i
# deploy:
# needs: [ test,build ]
# runs-on: ubuntu-latest
# environment: production
#
# steps:
# # 1) 기본 체크아웃
# - name: Checkout
# uses: actions/checkout@v4
# - name: result
# run: echo "SUCCESS"