Skip to content
Open
Show file tree
Hide file tree
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
168 changes: 168 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
name: CI Pipeline

on:
push:
branches: ["main", "develop", "feature/**"]
pull_request:
branches: ["main"]

permissions:
contents: read
actions: read
checks: write

env:
JAVA_VERSION: "17"
MIN_COVERAGE: "70"

jobs:
detect-changes:
name: Detect changed services
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.detect.outputs.changed }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Detect changed microservices
id: detect
run: |
git fetch origin main || true
CHANGED=$(git diff --name-only origin/main...HEAD | grep -E '^(customers-service|vets-service|visit-service|api-gateway|admin-server|discovery-server|config-server)/' | cut -d'/' -f1 | sort -u | xargs)
echo "Changed services: $CHANGED"
echo "changed=$CHANGED" >> $GITHUB_OUTPUT

test:
name: Unit Test & Coverage
needs: detect-changes
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: ${{ env.JAVA_VERSION }}

- uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-

- name: Run tests
run: |
if [ -z "${{ needs.detect-changes.outputs.changed }}" ]; then
echo "No changed services — running all tests."
mvn -B clean test
else
for s in ${{ needs.detect-changes.outputs.changed }}; do
echo "Testing $s ..."
cd $s
mvn -B clean test
cd ..
done
fi

- name: Debug list files in workspace
if: always()
run: |
echo "Listing coverage files..."
find . -type f -name "jacoco*.xml" | sort || true
echo "Listing target directories..."
find . -type d -name "jacoco" | sort || true

- name: Upload test reports
if: always()
uses: actions/upload-artifact@v4
with:
name: junit-reports
path: '**/target/surefire-reports/*.xml'

- name: Upload JaCoCo reports
if: always()
uses: actions/upload-artifact@v4
with:
name: jacoco-reports
path: '**/target/site/jacoco/jacoco.xml'

coverage-check:
name: Verify coverage threshold
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/download-artifact@v4
with:
name: jacoco-reports
path: ./reports

- name: Calculate coverage and validate
env:
MIN_COVERAGE: ${{ env.MIN_COVERAGE }}
run: |
total_missed=0
total_covered=0
for file in $(find ./reports -name "jacoco.xml" || true); do
while read -r line; do
missed=$(echo "$line" | grep -oP 'missed="\K[0-9]+' || echo 0)
covered=$(echo "$line" | grep -oP 'covered="\K[0-9]+' || echo 0)
total_missed=$((total_missed + missed))
total_covered=$((total_covered + covered))
done < <(grep '<counter type="INSTRUCTION"' "$file" || true)
done
if [ "$total_covered" -eq 0 ] && [ "$total_missed" -eq 0 ]; then
echo "No coverage data found."
exit 1
fi
coverage=$(awk -v c=$total_covered -v m=$total_missed 'BEGIN {printf "%.2f", c*100/(c+m)}')
echo "Coverage: $coverage%"
if (( $(echo "$coverage < $MIN_COVERAGE" | bc -l) )); then
echo "Coverage below $MIN_COVERAGE%"
exit 1
else
echo "Coverage OK ($coverage%)"
fi

build:
name: Build Changed Services
needs: [test, coverage-check]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: ${{ env.JAVA_VERSION }}

- uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-

- name: Build services
run: |
if [ -z "${{ needs.detect-changes.outputs.changed }}" ]; then
echo "No changed services — building all modules."
mvn -B clean package -DskipTests
else
for s in ${{ needs.detect-changes.outputs.changed }}; do
echo "Building $s ..."
cd $s
mvn -B clean package -DskipTests
cd ..
done
fi

- name: Upload build artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: built-jars
path: '**/target/*.jar'
28 changes: 15 additions & 13 deletions .github/workflows/maven-build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Java CI with Maven

on:
Expand All @@ -11,19 +8,24 @@ on:

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
java: [ '17' ]

steps:
- uses: actions/checkout@v4
- name: Set up JDK ${{matrix.java}}
uses: actions/setup-java@v4
with:
java-version: ${{matrix.java}}
distribution: 'adopt'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml
- uses: actions/checkout@v4
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
cache: maven
- name: Build, test, and generate coverage
run: mvn -B clean verify
- name: Upload JaCoCo report
if: always()
uses: actions/upload-artifact@v4
with:
name: jacoco-reports
path: '**/target/site/jacoco/jacoco.xml'
26 changes: 26 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,5 +198,31 @@
</build>
</profile>
</profiles>
<build>
<plugins>
<!-- JaCoCo for all child modules -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>


</project>
8 changes: 8 additions & 0 deletions spring-petclinic-admin-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@
<packaging>jar</packaging>
<description>Spring Boot Admin server</description>

<!-- <parent>
<groupId>org.springframework.samples</groupId>
<artifactId>spring-petclinic-microservices</artifactId>
<version>3.4.1</version>
</parent> -->

<parent>
<groupId>org.springframework.samples</groupId>
<artifactId>spring-petclinic-microservices</artifactId>
<version>3.4.1</version>
<relativePath>../pom.xml</relativePath> <!-- path to your parent -->
</parent>


<properties>
<spring-boot-admin.version>3.4.1</spring-boot-admin.version>
<docker.image.exposed.port>9090</docker.image.exposed.port>
Expand Down
1 change: 1 addition & 0 deletions spring-petclinic-api-gateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<groupId>org.springframework.samples</groupId>
<artifactId>spring-petclinic-microservices</artifactId>
<version>3.4.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

<properties>
Expand Down
1 change: 1 addition & 0 deletions spring-petclinic-config-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<groupId>org.springframework.samples</groupId>
<artifactId>spring-petclinic-microservices</artifactId>
<version>3.4.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

<properties>
Expand Down
3 changes: 2 additions & 1 deletion spring-petclinic-customers-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

<parent>
<groupId>org.springframework.samples</groupId>
<artifactId>spring-petclinic-microservices</artifactId>
<artifactId>spring-petclinic-microservices</artifactId>
<version>3.4.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

<properties>
Expand Down
1 change: 1 addition & 0 deletions spring-petclinic-discovery-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<groupId>org.springframework.samples</groupId>
<artifactId>spring-petclinic-microservices</artifactId>
<version>3.4.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

<properties>
Expand Down
3 changes: 2 additions & 1 deletion spring-petclinic-genai-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

<parent>
<groupId>org.springframework.samples</groupId>
<artifactId>spring-petclinic-microservices</artifactId>
<artifactId>spring-petclinic-microservices</artifactId>
<version>3.4.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

<properties>
Expand Down
3 changes: 2 additions & 1 deletion spring-petclinic-vets-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

<parent>
<groupId>org.springframework.samples</groupId>
<artifactId>spring-petclinic-microservices</artifactId>
<artifactId>spring-petclinic-microservices</artifactId>
<version>3.4.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

<properties>
Expand Down
1 change: 1 addition & 0 deletions spring-petclinic-visits-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<groupId>org.springframework.samples</groupId>
<artifactId>spring-petclinic-microservices</artifactId>
<version>3.4.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

<properties>
Expand Down