Some checks failed
Docker Build and Push / build-and-push (push) Failing after 34s
LabFusion CI/CD Pipeline / api-gateway (push) Failing after 1m7s
API Gateway (Java Spring Boot) / test (17) (push) Failing after 1m17s
LabFusion CI/CD Pipeline / service-adapters (push) Failing after 22s
LabFusion CI/CD Pipeline / api-docs (push) Successful in 47s
API Gateway (Java Spring Boot) / test (21) (push) Failing after 2m45s
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 1m46s
LabFusion CI/CD Pipeline / integration-tests (push) Has been skipped
Integration Tests / integration-tests (push) Failing after 2m22s
Integration Tests / performance-tests (push) Has been skipped
## Test Requirements Enforcement ### 1. Remove Dummy Test Report Fallback - Removed dummy test report creation - Pipeline will now fail if no test reports are generated - Ensures proper test coverage requirements ### 2. Early Test File Validation - Added 'Check for test files' step before test execution - Counts test files in src/test/java/ directory - Sets TEST_FILES_EXIST environment variable ### 3. Fail Fast for Missing Test Files - Added 'Fail if no test files exist' step - Fails pipeline immediately if no test files found - Provides clear guidance on test file requirements - Shows example of proper test file naming ### 4. Enhanced Test Report Validation - Added 'Fail if no test reports found' step - Fails pipeline if no test reports are generated after test execution - Provides detailed error messages explaining possible causes - Ensures test execution actually produces reports ### 5. Clear Error Messages - Specific guidance on test file naming conventions - Examples of proper test file structure - Clear indication of what's required for pipeline success ## Pipeline Behavior - **Fails early** if no test files exist - **Fails** if tests don't generate reports - **Provides clear guidance** on test requirements - **Enforces test coverage** as a quality gate ## Expected Results - Pipeline will fail if no test files are present - Pipeline will fail if test execution doesn't produce reports - Clear error messages guide developers to add proper tests - Ensures all code changes include corresponding tests
211 lines
6.2 KiB
YAML
211 lines
6.2 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: Generate test report
|
|
uses: dorny/test-reporter@v1
|
|
if: env.TEST_REPORTS_EXIST == 'true'
|
|
with:
|
|
name: Maven Tests (Java ${{ matrix.java-version }})
|
|
path: target/surefire-reports/*.xml
|
|
reporter: java-junit
|
|
|
|
- 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: ./mvnw jacoco:report
|
|
|
|
- name: Upload coverage to Codecov
|
|
uses: codecov/codecov-action@v3
|
|
with:
|
|
file: ./services/api-gateway/target/site/jacoco/jacoco.xml
|
|
flags: api-gateway
|
|
name: api-gateway-coverage
|
|
|
|
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
|
|
|