Skip to content

Feature/kafka

Feature/kafka #33

name: spring-kafka-example CI Build
on:
pull_request:
branches: [master]
paths:
- "spring-kafka-example/**"
types:
- opened
- synchronize
- reopened
jobs:
integration-tests:
name: Run Unit & Integration Tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: spring-kafka-example
strategy:
matrix:
distribution: [ 'temurin' ]
java: [ '21' ]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK ${{ matrix.java }}
uses: actions/[email protected]
with:
java-version: ${{ matrix.java }}
distribution: ${{ matrix.distribution }}
cache: 'maven'
- name: Build and analyze
run: ./mvnw clean verify
health-check:
name: Health Check on Services
runs-on: ubuntu-latest
steps:
- name: Checkout repository and submodules
uses: actions/checkout@v4
with:
submodules: true
- name: Extract service names from docker compose
id: services
run: |
echo "services<<EOF" >> $GITHUB_OUTPUT
docker compose -f ./spring-kafka-example/compose.yaml config --services >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Start containers with Compose Action
uses: hoverkraft-tech/[email protected]
with:
compose-file: './spring-kafka-example/compose.yaml'
services: ${{ steps.services.outputs.services }}
up-flags: '--build'
down-flags: '--volumes'
- name: Wait for containers to initialize
run: sleep 10
- name: Check container health
run: |
echo "Checking the health of the containers..."
SERVICES="${{ steps.services.outputs.services }}"
for service in $SERVICES; do
running=$(docker inspect -f '{{.State.Running}}' "$service" 2>/dev/null || echo "false")
if [ "$running" = "true" ]; then
echo "$service is running ✔️"
else
exit_code=$(docker inspect -f '{{.State.ExitCode}}' "$service" 2>/dev/null || echo "1")
if [ "$exit_code" = "0" ]; then
echo "$service is stopped but exited with code 0 ✔️"
else
echo "::error ::$service is stopped and exited with code $exit_code ❌"
exit 1
fi
fi
done