Skip to content

Commit cbbc9bd

Browse files
committed
Edit GH actions workflow file
1 parent 937f26f commit cbbc9bd

File tree

1 file changed

+96
-35
lines changed

1 file changed

+96
-35
lines changed

.github/workflows/ci.yml

Lines changed: 96 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,58 @@
1-
name: Java CI with Maven
1+
name: Java CI with Maven (multi-job)
22

33
on:
44
workflow_dispatch:
55
pull_request:
66
branches: [ main ]
77

88
jobs:
9-
build:
9+
checkout:
1010
runs-on: ubuntu-latest
11-
12-
services:
13-
redis:
14-
image: redis:latest
15-
ports: [ "6379:6379" ]
16-
# Healthcheck so dependent steps wait until ready
17-
options: >-
18-
--health-cmd "redis-cli ping || exit 1"
19-
--health-interval 5s
20-
--health-timeout 3s
21-
--health-retries 20
22-
23-
postgres:
24-
image: postgres:16
25-
env:
26-
POSTGRES_DB: session_db
27-
POSTGRES_USER: postgres
28-
POSTGRES_PASSWORD: password
29-
ports: [ "5432:5432" ]
30-
# Healthcheck so we can safely run psql next
31-
options: >-
32-
--health-cmd "pg_isready -U postgres -d session_db"
33-
--health-interval 5s
34-
--health-timeout 3s
35-
--health-retries 20
36-
3711
steps:
3812
- uses: actions/checkout@v5
3913

14+
setup-java:
15+
runs-on: ubuntu-latest
16+
needs: [checkout]
17+
steps:
18+
- uses: actions/checkout@v5
4019
- name: Set up JDK 21
4120
uses: actions/setup-java@v5
4221
with:
4322
java-version: '21'
4423
distribution: 'temurin'
4524
cache: 'maven'
4625

47-
- name: Grant execute permission for mvnw
48-
run: chmod +x ./mvnw
26+
chmod-mvnw:
27+
runs-on: ubuntu-latest
28+
needs: [setup-java]
29+
steps:
30+
- uses: actions/checkout@v5
31+
- run: chmod +x ./mvnw
4932

33+
install-psql-client:
34+
runs-on: ubuntu-latest
35+
needs: [chmod-mvnw]
36+
steps:
37+
- uses: actions/checkout@v5
5038
- name: Install Postgres client
5139
run: |
5240
sudo apt-get update
5341
sudo apt-get install -y postgresql-client
5442
43+
redis-ready:
44+
runs-on: ubuntu-latest
45+
needs: [install-psql-client]
46+
services:
47+
redis:
48+
image: redis:latest
49+
ports: [ "6379:6379" ]
50+
options: >-
51+
--health-cmd "redis-cli ping || exit 1"
52+
--health-interval 5s
53+
--health-timeout 3s
54+
--health-retries 20
55+
steps:
5556
- name: Wait for Redis (defensive)
5657
run: |
5758
for i in {1..30}; do
@@ -65,11 +66,31 @@ jobs:
6566
echo "Redis did not become healthy in time"
6667
exit 1
6768
68-
- name: Create Spring Session tables in Postgres
69+
postgres-init:
70+
runs-on: ubuntu-latest
71+
needs: [redis-ready]
72+
services:
73+
postgres:
74+
image: postgres:16
75+
env:
76+
POSTGRES_DB: session_db
77+
POSTGRES_USER: postgres
78+
POSTGRES_PASSWORD: password
79+
ports: [ "5432:5432" ]
80+
options: >-
81+
--health-cmd "pg_isready -U postgres -d session_db"
82+
--health-interval 5s
83+
--health-timeout 3s
84+
--health-retries 20
85+
steps:
86+
- name: Install Postgres client
87+
run: |
88+
sudo apt-get update
89+
sudo apt-get install -y postgresql-client
90+
- name: Create Spring Session tables
6991
env:
7092
PGPASSWORD: password
7193
run: |
72-
# Wait for Postgres (defensive even with healthcheck)
7394
until pg_isready -h localhost -p 5432 -U postgres -d session_db; do
7495
echo "Waiting for Postgres..."
7596
sleep 2
@@ -103,10 +124,50 @@ jobs:
103124
REFERENCES SPRING_SESSION(PRIMARY_ID) ON DELETE CASCADE
104125
);
105126
SQL
106-
107127
- name: Show Postgres logs (verification)
108-
run: |
109-
docker logs ${{ job.services.postgres.id }} --since=10m || true
128+
run: docker logs ${{ job.services.postgres.id }} --since=10m || true
110129

130+
build:
131+
runs-on: ubuntu-latest
132+
needs: [postgres-init]
133+
services:
134+
redis:
135+
image: redis:latest
136+
ports: [ "6379:6379" ]
137+
options: >-
138+
--health-cmd "redis-cli ping || exit 1"
139+
--health-interval 5s
140+
--health-timeout 3s
141+
--health-retries 20
142+
postgres:
143+
image: postgres:16
144+
env:
145+
POSTGRES_DB: session_db
146+
POSTGRES_USER: postgres
147+
POSTGRES_PASSWORD: password
148+
ports: [ "5432:5432" ]
149+
options: >-
150+
--health-cmd "pg_isready -U postgres -d session_db"
151+
--health-interval 5s
152+
--health-timeout 3s
153+
--health-retries 20
154+
steps:
155+
- uses: actions/checkout@v5
156+
- name: Set up JDK 21
157+
uses: actions/setup-java@v5
158+
with:
159+
java-version: '21'
160+
distribution: 'temurin'
161+
cache: 'maven'
162+
- run: chmod +x ./mvnw
163+
- name: Wait for services
164+
run: |
165+
for i in {1..30}; do
166+
if echo PING | nc -w 1 localhost 6379 | grep -q PONG; then break; fi
167+
echo "Waiting for Redis..."; sleep 1
168+
done
169+
until pg_isready -h localhost -p 5432 -U postgres -d session_db; do
170+
echo "Waiting for Postgres..."; sleep 2
171+
done
111172
- name: Build with Maven (test profile)
112173
run: ./mvnw clean package -Dspring.profiles.active=test

0 commit comments

Comments
 (0)