Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 96 additions & 35 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,57 +1,58 @@
name: Java CI with Maven
name: Java CI with Maven (multi-job)

on:
workflow_dispatch:
pull_request:
branches: [ main ]

jobs:
build:
checkout:
runs-on: ubuntu-latest

services:
redis:
image: redis:latest
ports: [ "6379:6379" ]
# Healthcheck so dependent steps wait until ready
options: >-
--health-cmd "redis-cli ping || exit 1"
--health-interval 5s
--health-timeout 3s
--health-retries 20

postgres:
image: postgres:16
env:
POSTGRES_DB: session_db
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
ports: [ "5432:5432" ]
# Healthcheck so we can safely run psql next
options: >-
--health-cmd "pg_isready -U postgres -d session_db"
--health-interval 5s
--health-timeout 3s
--health-retries 20

steps:
- uses: actions/checkout@v5

setup-java:
runs-on: ubuntu-latest
needs: [checkout]
steps:
- uses: actions/checkout@v5
- name: Set up JDK 21
uses: actions/setup-java@v5
with:
java-version: '21'
distribution: 'temurin'
cache: 'maven'

- name: Grant execute permission for mvnw
run: chmod +x ./mvnw
chmod-mvnw:
runs-on: ubuntu-latest
needs: [setup-java]
steps:
- uses: actions/checkout@v5
- run: chmod +x ./mvnw

install-psql-client:
runs-on: ubuntu-latest
needs: [chmod-mvnw]
steps:
- uses: actions/checkout@v5
- name: Install Postgres client
run: |
sudo apt-get update
sudo apt-get install -y postgresql-client

redis-ready:
runs-on: ubuntu-latest
needs: [install-psql-client]
services:
redis:
image: redis:latest
ports: [ "6379:6379" ]
options: >-
--health-cmd "redis-cli ping || exit 1"
--health-interval 5s
--health-timeout 3s
--health-retries 20
steps:
- name: Wait for Redis (defensive)
run: |
for i in {1..30}; do
Expand All @@ -65,11 +66,31 @@ jobs:
echo "Redis did not become healthy in time"
exit 1

- name: Create Spring Session tables in Postgres
postgres-init:
runs-on: ubuntu-latest
needs: [redis-ready]
services:
postgres:
image: postgres:16
env:
POSTGRES_DB: session_db
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
ports: [ "5432:5432" ]
options: >-
--health-cmd "pg_isready -U postgres -d session_db"
--health-interval 5s
--health-timeout 3s
--health-retries 20
steps:
- name: Install Postgres client
run: |
sudo apt-get update
sudo apt-get install -y postgresql-client
- name: Create Spring Session tables
env:
PGPASSWORD: password
run: |
# Wait for Postgres (defensive even with healthcheck)
until pg_isready -h localhost -p 5432 -U postgres -d session_db; do
echo "Waiting for Postgres..."
sleep 2
Expand Down Expand Up @@ -103,10 +124,50 @@ jobs:
REFERENCES SPRING_SESSION(PRIMARY_ID) ON DELETE CASCADE
);
SQL

- name: Show Postgres logs (verification)
run: |
docker logs ${{ job.services.postgres.id }} --since=10m || true
run: docker logs ${{ job.services.postgres.id }} --since=10m || true

build:
runs-on: ubuntu-latest
needs: [postgres-init]
services:
redis:
image: redis:latest
ports: [ "6379:6379" ]
options: >-
--health-cmd "redis-cli ping || exit 1"
--health-interval 5s
--health-timeout 3s
--health-retries 20
postgres:
image: postgres:16
env:
POSTGRES_DB: session_db
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
ports: [ "5432:5432" ]
options: >-
--health-cmd "pg_isready -U postgres -d session_db"
--health-interval 5s
--health-timeout 3s
--health-retries 20
steps:
- uses: actions/checkout@v5
- name: Set up JDK 21
uses: actions/setup-java@v5
with:
java-version: '21'
distribution: 'temurin'
cache: 'maven'
- run: chmod +x ./mvnw
- name: Wait for services
run: |
for i in {1..30}; do
if echo PING | nc -w 1 localhost 6379 | grep -q PONG; then break; fi
echo "Waiting for Redis..."; sleep 1
done
until pg_isready -h localhost -p 5432 -U postgres -d session_db; do
echo "Waiting for Postgres..."; sleep 2
done
- name: Build with Maven (test profile)
run: ./mvnw clean package -Dspring.profiles.active=test