Files
labFusion/.gitea/workflows/api-gateway.yml
GSRN 6f8d7f6ca9
Some checks failed
Docker Build and Push / build-and-push (push) Failing after 43s
LabFusion CI/CD Pipeline / service-adapters (push) Failing after 25s
API Gateway (Java Spring Boot) / test (17) (push) Failing after 1m50s
LabFusion CI/CD Pipeline / api-docs (push) Failing after 50s
LabFusion CI/CD Pipeline / api-gateway (push) Failing after 1m34s
API Gateway (Java Spring Boot) / test (21) (push) Failing after 1m44s
API Gateway (Java Spring Boot) / build (push) Has been skipped
API Gateway (Java Spring Boot) / security (push) Has been skipped
LabFusion CI/CD Pipeline / frontend (push) Failing after 1m57s
LabFusion CI/CD Pipeline / integration-tests (push) Has been skipped
Frontend (React) / test (16) (push) Failing after 1m44s
Frontend (React) / test (20) (push) Failing after 1m31s
Frontend (React) / test (18) (push) Failing after 1m47s
Frontend (React) / build (push) Has been skipped
Service Adapters (Python FastAPI) / test (3.1) (push) Failing after 19s
Service Adapters (Python FastAPI) / test (3.11) (push) Failing after 26s
Service Adapters (Python FastAPI) / test (3.9) (push) Failing after 23s
Service Adapters (Python FastAPI) / build (push) Has been skipped
Frontend (React) / lighthouse (push) Has been skipped
Service Adapters (Python FastAPI) / test (3.12) (push) Failing after 22s
Integration Tests / performance-tests (push) Has been skipped
Integration Tests / integration-tests (push) Failing after 2m23s
API Docs (Node.js Express) / test (16) (push) Failing after 54s
API Docs (Node.js Express) / test (18) (push) Failing after 55s
API Docs (Node.js Express) / test (20) (push) Failing after 58s
API Docs (Node.js Express) / build (push) Has been skipped
feat: Integrate SonarQube analysis into CI workflows
### Summary of Changes
- Added SonarQube analysis steps to all CI workflows (API Docs, API Gateway, Frontend, Service Adapters).
- Configured SonarQube properties for each service to ensure proper reporting and analysis.
- Enhanced test coverage reporting by specifying multiple coverage reporters in test commands.
- Updated Maven and Python dependencies to include SonarQube integration tools.

### Expected Results
- CI pipelines will now send test and coverage results to SonarQube for better quality tracking.
- Improved visibility into code quality and test coverage across all services.
2025-09-15 19:55:13 +02:00

234 lines
7.3 KiB
YAML

name: API Gateway (Java Spring Boot)
on:
push:
paths:
- 'services/api-gateway/**'
- '.gitea/workflows/api-gateway.yml'
pull_request:
paths:
- 'services/api-gateway/**'
env:
REGISTRY: gitea.example.com
IMAGE_PREFIX: labfusion
SERVICE_NAME: api-gateway
jobs:
test:
runs-on: [self-hosted]
env:
RUNNER_TOOL_CACHE: /toolcache
defaults:
run:
working-directory: ./services/api-gateway
strategy:
matrix:
java-version: [17, 21]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java-version }}
distribution: 'temurin'
cache: maven
- name: Make Maven wrapper executable
run: chmod +x ./mvnw
- name: Verify Maven installation
run: ./mvnw --version
- name: Cache Maven dependencies
uses: actions/cache@v4
with:
path: |
~/.m2/repository
~/.m2/wrapper
key: maven-${{ runner.os }}-${{ matrix.java-version }}-${{ hashFiles('**/pom.xml') }}
restore-keys: |
maven-${{ runner.os }}-${{ matrix.java-version }}-
maven-${{ runner.os }}-
maven-
fail-on-cache-miss: false
- name: Validate POM
run: ./mvnw validate
- name: Compile code
run: ./mvnw compile
- name: Check for test files
run: |
echo "Checking for test files in src/test/java/..."
if [ -d "src/test/java" ]; then
TEST_COUNT=$(find src/test/java -name "*Test*.java" -type f | wc -l)
echo "Found $TEST_COUNT test files"
if [ $TEST_COUNT -eq 0 ]; then
echo "⚠️ No test files found! Please add test files to src/test/java/"
echo "TEST_FILES_EXIST=false" >> $GITHUB_ENV
else
echo "✅ Test files found"
echo "TEST_FILES_EXIST=true" >> $GITHUB_ENV
fi
else
echo "❌ No src/test/java directory found!"
echo "TEST_FILES_EXIST=false" >> $GITHUB_ENV
fi
- name: Fail if no test files exist
if: env.TEST_FILES_EXIST == 'false'
run: |
echo "❌ No test files found in src/test/java/"
echo "This pipeline requires test files to be present."
echo "Please add test files with names ending in 'Test.java' or 'Tests.java'"
echo "Example: src/test/java/com/labfusion/MyServiceTest.java"
exit 1
- name: Run unit tests
run: |
echo "Running Maven tests..."
./mvnw test -X
echo "Maven test execution completed"
echo "Checking target directory structure..."
find target -name "*.xml" -type f 2>/dev/null || echo "No XML files found in target"
echo "Checking surefire-reports directory..."
if [ -d "target/surefire-reports" ]; then
echo "Contents of surefire-reports:"
ls -la target/surefire-reports/
else
echo "surefire-reports directory does not exist"
echo "Creating surefire-reports directory..."
mkdir -p target/surefire-reports
fi
- name: Check test reports
run: |
echo "Checking for test report files..."
if [ -d "target/surefire-reports" ]; then
echo "Surefire reports directory exists"
ls -la target/surefire-reports/
if [ -n "$(find target/surefire-reports -name '*.xml' -type f)" ]; then
echo "✅ Found test report XML files"
echo "TEST_REPORTS_EXIST=true" >> $GITHUB_ENV
else
echo "⚠️ No XML files found in surefire-reports"
echo "TEST_REPORTS_EXIST=false" >> $GITHUB_ENV
fi
else
echo "❌ Surefire reports directory does not exist"
echo "TEST_REPORTS_EXIST=false" >> $GITHUB_ENV
fi
- name: Send test results to SonarQube
if: env.TEST_REPORTS_EXIST == 'true'
run: |
echo "Sending test results to SonarQube..."
# Configure SonarQube properties
cat > sonar-project.properties << EOF
sonar.projectKey=labFusion
sonar.projectName=LabFusion
sonar.projectVersion=1.0.0
sonar.modules=api-gateway
sonar.sources=src/main/java
sonar.tests=src/test/java
sonar.java.binaries=target/classes
sonar.java.test.binaries=target/test-classes
sonar.junit.reportPaths=target/surefire-reports
sonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml
sonar.host.url=${{ secrets.SONAR_HOST_URL }}
sonar.login=${{ secrets.SONAR_TOKEN }}
EOF
# Run SonarQube analysis
./mvnw sonar:sonar \
-Dsonar.host.url=${{ secrets.SONAR_HOST_URL }} \
-Dsonar.login=${{ secrets.SONAR_TOKEN }} \
-Dsonar.projectKey=labFusion \
-Dsonar.projectName="LabFusion" \
-Dsonar.projectVersion=1.0.0 \
-Dsonar.modules=api-gateway \
-Dsonar.sources=src/main/java \
-Dsonar.tests=src/test/java \
-Dsonar.java.binaries=target/classes \
-Dsonar.java.test.binaries=target/test-classes \
-Dsonar.junit.reportPaths=target/surefire-reports \
-Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml
- name: Fail if no test reports found
if: env.TEST_REPORTS_EXIST == 'false'
run: |
echo "❌ No test reports were generated!"
echo "This indicates that either:"
echo "1. No test files were found in src/test/java/"
echo "2. Tests failed to execute properly"
echo "3. Maven Surefire plugin did not generate reports"
echo ""
echo "Please ensure you have test files and they are executing correctly."
exit 1
- name: Run code quality checks
run: |
./mvnw spotbugs:check
./mvnw checkstyle:check
./mvnw pmd:check
- name: Generate code coverage
run: |
echo "Generating JaCoCo code coverage report..."
./mvnw jacoco:report
echo "Code coverage report generated at target/site/jacoco/jacoco.xml"
build:
runs-on: [self-hosted]
needs: test
env:
RUNNER_TOOL_CACHE: /toolcache
defaults:
run:
working-directory: ./services/api-gateway
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Make Maven wrapper executable
run: chmod +x ./mvnw
- name: Verify Maven installation
run: ./mvnw --version
- name: Cache Maven dependencies
uses: actions/cache@v4
with:
path: |
~/.m2/repository
~/.m2/wrapper
key: maven-${{ runner.os }}-${{ hashFiles('**/pom.xml') }}
restore-keys: |
maven-${{ runner.os }}-
maven-
fail-on-cache-miss: false
- name: Build application
run: ./mvnw clean package -DskipTests
- name: Build Docker image (test only)
run: docker build -t api-gateway:test .
security:
runs-on: [self-hosted]
needs: build