Skip to content

Changes in sql and database config #335

Changes in sql and database config

Changes in sql and database config #335

Workflow file for this run

name: CI - Spring Boot
on:
push:
branches:
- main
- dev
pull_request:
branches:
- main
- dev
jobs:
build:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: sleepuptest
MYSQL_USER: testuser
MYSQL_PASSWORD: password
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping --silent"
--health-interval=10s
--health-timeout=5s
--health-retries=5
env:
DB_URL_TEST: jdbc:mysql://127.0.0.1:3306/sleepuptest?createDatabaseIfNotExist=true&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
DB_USER: root
DB_PASSWORD: password
SERVER_PORT: 8080
# Cloudinary dummy variables for testing
CLOUDINARY_CLOUD_NAME: ${{ secrets.CLOUDINARY_CLOUD_NAME }}
CLOUDINARY_API_KEY: ${{ secrets.CLOUDINARY_API_KEY }}
CLOUDINARY_API_SECRET: ${{ secrets.CLOUDINARY_API_SECRET }}
# Email dummy variables for testing
EMAIL: test@example.com
EMAIL_PASSWORD: dummy_password
steps:
# 1. Check the repository
- name: Check out code
uses: actions/checkout@v3
# 2. Configure Java 21
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
# 3. Configuring cache for Maven
- name: Cache Maven dependencies
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-m2
# 4. Build the project
- name: Build with Maven
run: mvn clean compile
# 5. Wait for MySQL to be ready
- name: Wait for MySQL to be ready
run: |
for i in {1..30}; do
if mysqladmin ping -h "127.0.0.1" -P 3306 -u root -ppassword --silent; then
echo "MySQL is up!"
exit 0
else
echo "Waiting for MySQL... ($i/30)"
sleep 5
fi
done
echo "MySQL did not start in time."
exit 1
# 6. Create database schema and data (since ddl-auto=none in test profile)
- name: Initialize database
run: |
mysql -h 127.0.0.1 -P 3306 -u root -ppassword sleepuptest < src/test/resources/schema.sql || echo "Schema already exists or file not found"
mysql -h 127.0.0.1 -P 3306 -u root -ppassword sleepuptest < src/test/resources/data.sql || echo "Data already exists or file not found"
# 7. Run tests with test profile
- name: Compile Tests
run: mvn test-compile
- name: Run Tests
run: mvn test -Dspring.profiles.active=test