Add Docker testing instructions to README #23
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: Java CI with Maven | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
env: | |
DB_HOST: localhost | |
DB_PORT: 5432 | |
DB_NAME: testdb | |
DB_USERNAME: ${{ secrets.DB_USERNAME }} | |
DB_PASSWORD: ${{ secrets.DB_PASSWORD }} | |
services: | |
postgres: | |
image: postgres:latest | |
env: | |
POSTGRES_DB: ${{ env.DB_NAME }} | |
POSTGRES_USER: ${{ secrets.DB_USERNAME }} | |
POSTGRES_PASSWORD: ${{ secrets.DB_PASSWORD }} | |
ports: | |
- 5432:5432 | |
options: >- | |
--health-cmd="pg_isready" | |
--health-interval=10s | |
--health-timeout=5s | |
--health-retries=5 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'adopt' | |
- name: Wait for PostgreSQL to be ready | |
run: | | |
until pg_isready --host=localhost --port=5432 --username=${{ secrets.DB_USERNAME }}; do | |
echo "Waiting for PostgreSQL to be ready..." | |
sleep 5 | |
done | |
- name: Create schema and initial setup | |
env: | |
PGPASSWORD: ${{ secrets.DB_PASSWORD }} | |
run: | | |
psql -h localhost -U ${{ secrets.DB_USERNAME }} -d ${{ env.DB_NAME }} -c "CREATE SCHEMA IF NOT EXISTS leetcode;" | |
- name: Build with Maven | |
run: mvn clean install -DskipTests | |
- name: Run tests | |
run: mvn test -Dspring.profiles.active=test | |
env: | |
DB_HOST: localhost | |
DB_PORT: 5432 | |
DB_NAME: testdb | |
DB_USERNAME: ${{ secrets.DB_USERNAME }} | |
DB_PASSWORD: ${{ secrets.DB_PASSWORD }} |