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: 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: Send test results to SonarQube 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 }}" \ -Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml \ -Dsonar.junit.reportPaths=target/surefire-reports 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