Hubobe 51 be 포토 포인트 #64
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 | |
elasticsearch: | |
image: docker.elastic.co/elasticsearch/elasticsearch:8.5.3 | |
env: | |
discovery.type: single-node | |
xpack.security.enabled: true | |
ELASTIC_PASSWORD: ${{ secrets.MYSQL_ROOT_PASSWORD }} | |
xpack.security.authc.api_key.enabled: true | |
xpack.security.transport.ssl.enabled: false | |
ports: | |
- 9200:9200 | |
mongodb: | |
image: mongo:latest | |
env: | |
MONGO_INITDB_ROOT_USERNAME: ${{ secrets.MONGO_ROOT_USERNAME }} | |
MONGO_INITDB_ROOT_PASSWORD: ${{ secrets.MONGO_ROOT_PASSWORD }} | |
ports: | |
- 27017:27017 | |
options: >- | |
--health-cmd "mongosh --eval 'db.runCommand({ping:1})'" | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
steps: | |
- name: Wait for Elasticsearch | |
run: | | |
timeout 600 bash -c ' | |
while ! curl -s -u elastic:${{ secrets.MYSQL_ROOT_PASSWORD }} -o /dev/null -w "%{http_code}" http://127.0.0.1:9200 | grep -q "200"; do | |
echo "Waiting for Elasticsearch..." | |
sleep 5 | |
done | |
' | |
- name: Verify Elasticsearch Health | |
run: | | |
curl -u elastic:${{ secrets.MYSQL_ROOT_PASSWORD }} http://127.0.0.1:9200/_cluster/health | |
- name: Install Elasticsearch plugin | |
run: | | |
docker exec $(docker ps -q --filter "name=elasticsearch") \ | |
/usr/share/elasticsearch/bin/elasticsearch-plugin install --batch analysis-nori | |
- name: Restart Elasticsearch | |
run: | | |
docker restart $(docker ps -q --filter "name=elasticsearch") | |
- name: Wait for Elasticsearch after restart | |
run: | | |
timeout 600 bash -c ' | |
until curl -s -u elastic:${{ secrets.MYSQL_ROOT_PASSWORD }} http://127.0.0.1:9200/_cluster/health | grep -q "status\":\"[green|yellow]"; do | |
echo "Waiting for Elasticsearch to be operational..." | |
sleep 15 | |
done | |
' | |
- name: Verify Elasticsearch Health | |
run: | | |
curl -u elastic:${{ secrets.MYSQL_ROOT_PASSWORD }} http://127.0.0.1:9200/_cluster/health | |
- 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: | | |
echo "Showing initial databases:" | |
mysql --host 127.0.0.1 --port 3306 -uroot -p${{ secrets.MYSQL_ROOT_PASSWORD }} -e "SHOW DATABASES;" || echo "Failed to show initial databases" | |
echo "Creating hubo database:" | |
mysql --host 127.0.0.1 --port 3306 -uroot -p${{ secrets.MYSQL_ROOT_PASSWORD }} -e "CREATE DATABASE IF NOT EXISTS hubo;" || echo "Failed to create hubo database" | |
echo "Creating root user:" | |
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 }}';" || echo "Failed to create root user" | |
echo "Granting privileges:" | |
mysql --host 127.0.0.1 --port 3306 -uroot -p${{ secrets.MYSQL_ROOT_PASSWORD }} -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;" || echo "Failed to grant privileges" | |
echo "Flushing privileges:" | |
mysql --host 127.0.0.1 --port 3306 -uroot -p${{ secrets.MYSQL_ROOT_PASSWORD }} -e "FLUSH PRIVILEGES;" || echo "Failed to flush privileges" | |
echo "Showing final databases:" | |
mysql --host 127.0.0.1 --port 3306 -uroot -p${{ secrets.MYSQL_ROOT_PASSWORD }} -e "SHOW DATABASES;" || echo "Failed to show final databases" | |
- name: Debug Elasticsearch before tests | |
run: | | |
echo "Checking Elasticsearch status before running tests..." | |
curl -s -u elastic:${{ secrets.MYSQL_ROOT_PASSWORD }} http://127.0.0.1:9200/_cluster/health | jq . | |
echo "Listing Elasticsearch indices..." | |
curl -s -u elastic:${{ secrets.MYSQL_ROOT_PASSWORD }} http://127.0.0.1:9200/_cat/indices?v | |
echo "Checking Elasticsearch plugins..." | |
curl -s -u elastic:${{ secrets.MYSQL_ROOT_PASSWORD }} http://127.0.0.1:9200/_cat/plugins?v | |
echo "Checking Elasticsearch settings..." | |
curl -s -u elastic:${{ secrets.MYSQL_ROOT_PASSWORD }} http://127.0.0.1:9200/_cluster/settings?pretty | |
- 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 }} | |