Some checks failed
Docker Build and Push / build-and-push (push) Failing after 35s
Integration Tests / integration-tests (push) Failing after 36s
Integration Tests / performance-tests (push) Has been skipped
API Gateway (Java Spring Boot) / test (17) (push) Failing after 2m4s
API Gateway (Java Spring Boot) / test (21) (push) Failing after 2m17s
API Gateway (Java Spring Boot) / build (push) Has been skipped
API Gateway (Java Spring Boot) / security (push) Has been skipped
### Summary of Changes - Enclosed the SonarQube host URL and token parameters in quotes in the CI workflows for both `all-services.yml` and `api-gateway.yml` to ensure proper parsing of the values. ### Expected Results - Improved reliability of SonarQube integration in the CI process by preventing potential issues with parameter interpretation.
231 lines
6.8 KiB
YAML
231 lines
6.8 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/**'
|
|
workflow_dispatch:
|
|
inputs:
|
|
run_tests:
|
|
description: 'Run tests'
|
|
required: false
|
|
default: true
|
|
type: boolean
|
|
run_lint:
|
|
description: 'Run linting'
|
|
required: false
|
|
default: true
|
|
type: boolean
|
|
run_build:
|
|
description: 'Run build'
|
|
required: false
|
|
default: true
|
|
type: boolean
|
|
run_sonar:
|
|
description: 'Run SonarQube analysis'
|
|
required: false
|
|
default: true
|
|
type: boolean
|
|
|
|
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..."
|
|
./mvnw clean verify sonar:sonar \
|
|
-Dsonar.projectKey=labfusion-api-gateway \
|
|
-Dsonar.projectName="LabFusion API Gateway" \
|
|
-Dsonar.host.url="${{ secrets.SONAR_HOST_URL }}" \
|
|
-Dsonar.token="${{ secrets.SONAR_TOKEN }}"
|
|
|
|
- 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
|
|
|