Hubobe 51 be 포토 포인트 #43
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test workflows | |
on: | |
pull_request: | |
branches: [ "develop", "main", "hotfix" , "HUBOBE-*" ] | |
types: [ reopened, opened, synchronize ] | |
paths: | |
- 'src/main/java/**' | |
- 'src/test/java/**' | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
services: | |
mysql: | |
image: mysql:8.0.33 | |
env: | |
MYSQL_DATABASE: ${{ secrets.MYSQL_DATABASE }} | |
MYSQL_ROOT_HOST: '%' | |
MYSQL_ROOT_PASSWORD: ${{ secrets.MYSQL_ROOT_PASSWORD }} | |
TZ: Asia/Seoul | |
MYSQL_CHARACTER_SET_SERVER: utf8mb4 | |
MYSQL_COLLATION_SERVER: utf8mb4_unicode_ci | |
ports: | |
- 3306:3306 | |
options: >- | |
--health-cmd="mysqladmin ping" | |
--health-interval=10s | |
--health-timeout=5s | |
--health-retries=3 | |
redis: | |
image: redis:latest | |
ports: | |
- 6379:6379 | |
mongodb: | |
image: mongo:latest | |
env: | |
MONGO_INITDB_ROOT_USERNAME: ${{ secrets.MONGO_ROOT_USERNAME }} | |
MONGO_INITDB_ROOT_PASSWORD: ${{ secrets.MONGO_ROOT_PASSWORD }} | |
ports: | |
- 27017:27017 | |
steps: | |
- name: MySQL connection health check | |
run: | | |
for i in {30..0}; do | |
if mysqladmin ping -h 127.0.0.1 --silent; then | |
break | |
fi | |
echo 'MySQL을 기다리는 중...' | |
sleep 1 | |
done | |
if [ $i -eq 0 ]; then | |
echo 'MySQL이 30초 내에 시작되지 않았습니다.' | |
exit 1 | |
fi | |
- name: Verify MySQL connection and configure access | |
run: | | |
mysql --host 127.0.0.1 --port 3306 -uroot -p${{ secrets.MYSQL_ROOT_PASSWORD }} -e "SHOW DATABASES;" | |
mysql --host 127.0.0.1 --port 3306 -uroot -p${{ secrets.MYSQL_ROOT_PASSWORD }} -e "CREATE DATABASE IF NOT EXISTS hubo;" | |
mysql --host 127.0.0.1 --port 3306 -uroot -p${{ secrets.MYSQL_ROOT_PASSWORD }} -e "CREATE USER IF NOT EXISTS 'root'@'%' IDENTIFIED BY '${{ secrets.MYSQL_ROOT_PASSWORD }}';" | |
mysql --host 127.0.0.1 --port 3306 -uroot -p${{ secrets.MYSQL_ROOT_PASSWORD }} -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;" | |
mysql --host 127.0.0.1 --port 3306 -uroot -p${{ secrets.MYSQL_ROOT_PASSWORD }} -e "FLUSH PRIVILEGES;" | |
mysql --host 127.0.0.1 --port 3306 -uroot -p${{ secrets.MYSQL_ROOT_PASSWORD }} -e "SHOW DATABASES;" | |
- name: Checkout secret code | |
uses: actions/checkout@v3 | |
with: | |
submodules: true | |
token: ${{ secrets.ACTION_SECRETS }} | |
- name: Initialize and update submodules | |
run: | | |
git submodule sync | |
git submodule update --init --recursive | |
- name: set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: 17 | |
distribution: 'zulu' | |
- name: Copy application.yml files from submodule | |
run: | | |
mkdir -p src/main/resources | |
cp -r BE-hubo-gillajabi-resources/resources/application*.yml src/main/resources/ | |
echo "Copied $(ls -1 src/main/resources/application*.yml | wc -l) application.yml files" | |
- name: Copy resources db files from submodule | |
run: | | |
mkdir -p src/main/resources/db | |
cp -r BE-hubo-gillajabi-resources/resources/db/* src/main/resources/db/ | |
echo "Copied $(ls -1 src/main/resources/db/* | wc -l) db files" | |
- name: Copy test mocked files from submodule | |
run: | | |
mkdir -p src/test/resources | |
cp -r BE-hubo-gillajabi-resources/test/mockedResponses/* src/test/resources/ | |
- 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- | |
# - name: Start test environment on remote server | |
# uses: appleboy/ssh-action@master | |
# with: | |
# host: ${{ secrets.BE_HOST }} | |
# username: ${{ secrets.BE_USER }} | |
# port: ${{ secrets.BE_PORT }} | |
# password: ${{ secrets.BE_PW }} | |
# script: | | |
# cd ~/hubo/test | |
# ./start-test-docker-compose.sh | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./gradlew | |
- name: Test with Gradle | |
run: ./gradlew test -Dspring.profiles.active=test | |
# - name: Stop test environment on remote server | |
# if: always() # 무조건 실행 | |
# uses: appleboy/ssh-action@master | |
# with: | |
# host: ${{ secrets.BE_HOST }} | |
# username: ${{ secrets.BE_USER }} | |
# port: ${{ secrets.BE_PORT }} | |
# password: ${{ secrets.BE_PW }} | |
# script: | | |
# cd ~/hubo/test | |
# ./stop-test-docker-compose.sh | |
- name: Upload coverage reports to Codecov | |
uses: codecov/codecov-action@v4 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |