|
| 1 | +name: Enhanced Quality Gate |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, develop ] |
| 8 | + schedule: |
| 9 | + # Run nightly for dependency scanning |
| 10 | + - cron: '0 2 * * *' |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + security-events: write |
| 15 | + issues: write |
| 16 | + pull-requests: write |
| 17 | + |
| 18 | +env: |
| 19 | + JAVA_VERSION: '21' |
| 20 | + MAVEN_OPTS: -Xmx2g |
| 21 | + |
| 22 | +jobs: |
| 23 | + # Fast feedback - unit tests only |
| 24 | + fast-feedback: |
| 25 | + name: Fast Feedback (Unit Tests) |
| 26 | + runs-on: ubuntu-latest |
| 27 | + timeout-minutes: 10 |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Checkout code |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Set up JDK ${{ env.JAVA_VERSION }} |
| 34 | + uses: actions/setup-java@v4 |
| 35 | + with: |
| 36 | + java-version: ${{ env.JAVA_VERSION }} |
| 37 | + distribution: 'temurin' |
| 38 | + cache: maven |
| 39 | + |
| 40 | + - name: Run unit tests only |
| 41 | + run: mvn test -Dtest.groups=unit -B |
| 42 | + |
| 43 | + - name: Upload unit test results |
| 44 | + if: always() |
| 45 | + uses: actions/upload-artifact@v4 |
| 46 | + with: |
| 47 | + name: unit-test-results |
| 48 | + path: '**/target/surefire-reports/**' |
| 49 | + retention-days: 30 |
| 50 | + |
| 51 | + # Code formatting check |
| 52 | + code-format: |
| 53 | + name: Code Formatting (Spotless) |
| 54 | + runs-on: ubuntu-latest |
| 55 | + timeout-minutes: 5 |
| 56 | + |
| 57 | + steps: |
| 58 | + - name: Checkout code |
| 59 | + uses: actions/checkout@v4 |
| 60 | + |
| 61 | + - name: Set up JDK ${{ env.JAVA_VERSION }} |
| 62 | + uses: actions/setup-java@v4 |
| 63 | + with: |
| 64 | + java-version: ${{ env.JAVA_VERSION }} |
| 65 | + distribution: 'temurin' |
| 66 | + cache: maven |
| 67 | + |
| 68 | + - name: Check code formatting |
| 69 | + run: mvn spotless:check -B |
| 70 | + |
| 71 | + - name: Comment on PR if formatting fails |
| 72 | + if: failure() && github.event_name == 'pull_request' |
| 73 | + uses: actions/github-script@v7 |
| 74 | + with: |
| 75 | + script: | |
| 76 | + github.rest.issues.createComment({ |
| 77 | + issue_number: context.issue.number, |
| 78 | + owner: context.repo.owner, |
| 79 | + repo: context.repo.repo, |
| 80 | + body: '❌ **Code formatting check failed**\n\nPlease run `mvn spotless:apply` to fix formatting issues.' |
| 81 | + }) |
| 82 | +
|
| 83 | + # Code style check |
| 84 | + code-style: |
| 85 | + name: Code Style (Checkstyle) |
| 86 | + runs-on: ubuntu-latest |
| 87 | + timeout-minutes: 10 |
| 88 | + |
| 89 | + steps: |
| 90 | + - name: Checkout code |
| 91 | + uses: actions/checkout@v4 |
| 92 | + |
| 93 | + - name: Set up JDK ${{ env.JAVA_VERSION }} |
| 94 | + uses: actions/setup-java@v4 |
| 95 | + with: |
| 96 | + java-version: ${{ env.JAVA_VERSION }} |
| 97 | + distribution: 'temurin' |
| 98 | + cache: maven |
| 99 | + |
| 100 | + - name: Run Checkstyle |
| 101 | + run: mvn checkstyle:check -B |
| 102 | + |
| 103 | + - name: Upload Checkstyle report |
| 104 | + if: always() |
| 105 | + uses: actions/upload-artifact@v4 |
| 106 | + with: |
| 107 | + name: checkstyle-report |
| 108 | + path: '**/target/checkstyle-result.xml' |
| 109 | + retention-days: 30 |
| 110 | + |
| 111 | + # Security tests |
| 112 | + security-tests: |
| 113 | + name: Security Tests |
| 114 | + runs-on: ubuntu-latest |
| 115 | + timeout-minutes: 10 |
| 116 | + |
| 117 | + steps: |
| 118 | + - name: Checkout code |
| 119 | + uses: actions/checkout@v4 |
| 120 | + |
| 121 | + - name: Set up JDK ${{ env.JAVA_VERSION }} |
| 122 | + uses: actions/setup-java@v4 |
| 123 | + with: |
| 124 | + java-version: ${{ env.JAVA_VERSION }} |
| 125 | + distribution: 'temurin' |
| 126 | + cache: maven |
| 127 | + |
| 128 | + - name: Run security tests |
| 129 | + run: mvn test -Dtest.groups=security -B |
| 130 | + |
| 131 | + - name: Upload security test results |
| 132 | + if: always() |
| 133 | + uses: actions/upload-artifact@v4 |
| 134 | + with: |
| 135 | + name: security-test-results |
| 136 | + path: '**/target/surefire-reports/**' |
| 137 | + retention-days: 30 |
| 138 | + |
| 139 | + # Full test suite with coverage |
| 140 | + full-test-suite: |
| 141 | + name: Full Test Suite + Coverage |
| 142 | + runs-on: ubuntu-latest |
| 143 | + timeout-minutes: 20 |
| 144 | + needs: [fast-feedback] |
| 145 | + |
| 146 | + steps: |
| 147 | + - name: Checkout code |
| 148 | + uses: actions/checkout@v4 |
| 149 | + with: |
| 150 | + fetch-depth: 0 # For better coverage analysis |
| 151 | + |
| 152 | + - name: Set up JDK ${{ env.JAVA_VERSION }} |
| 153 | + uses: actions/setup-java@v4 |
| 154 | + with: |
| 155 | + java-version: ${{ env.JAVA_VERSION }} |
| 156 | + distribution: 'temurin' |
| 157 | + cache: maven |
| 158 | + |
| 159 | + - name: Run all tests with coverage |
| 160 | + run: mvn clean test jacoco:report -B |
| 161 | + |
| 162 | + - name: Check coverage threshold |
| 163 | + run: mvn jacoco:check -B |
| 164 | + |
| 165 | + - name: Parse coverage metrics |
| 166 | + id: coverage |
| 167 | + run: | |
| 168 | + INSTRUCTION=$(grep -oP 'Total.*?<td class="ctr2">(\d+)%' target/site/jacoco/index.html | grep -oP '\d+' | head -1 || echo "0") |
| 169 | + BRANCH=$(grep -oP 'Total.*?<td class="ctr2">(\d+)%' target/site/jacoco/index.html | grep -oP '\d+' | sed -n '2p' || echo "0") |
| 170 | + echo "instruction_coverage=$INSTRUCTION" >> $GITHUB_OUTPUT |
| 171 | + echo "branch_coverage=$BRANCH" >> $GITHUB_OUTPUT |
| 172 | + echo "📊 Coverage: Instructions ${INSTRUCTION}%, Branches ${BRANCH}%" |
| 173 | +
|
| 174 | + - name: Upload coverage to Codecov |
| 175 | + uses: codecov/codecov-action@v4 |
| 176 | + with: |
| 177 | + files: '**/target/site/jacoco/jacoco.xml' |
| 178 | + flags: unittests |
| 179 | + name: codecov-umbrella |
| 180 | + |
| 181 | + - name: Upload coverage report |
| 182 | + uses: actions/upload-artifact@v4 |
| 183 | + with: |
| 184 | + name: coverage-report |
| 185 | + path: '**/target/site/jacoco/**' |
| 186 | + retention-days: 30 |
| 187 | + |
| 188 | + - name: Comment coverage on PR |
| 189 | + if: github.event_name == 'pull_request' |
| 190 | + uses: actions/github-script@v7 |
| 191 | + with: |
| 192 | + script: | |
| 193 | + const instruction = '${{ steps.coverage.outputs.instruction_coverage }}'; |
| 194 | + const branch = '${{ steps.coverage.outputs.branch_coverage }}'; |
| 195 | + const threshold = 60; |
| 196 | + const emoji = instruction >= threshold ? '✅' : '❌'; |
| 197 | +
|
| 198 | + github.rest.issues.createComment({ |
| 199 | + issue_number: context.issue.number, |
| 200 | + owner: context.repo.owner, |
| 201 | + repo: context.repo.repo, |
| 202 | + body: `${emoji} **Code Coverage Report**\n\n- Instruction Coverage: **${instruction}%** (threshold: ${threshold}%)\n- Branch Coverage: **${branch}%** (threshold: ${threshold}%)` |
| 203 | + }) |
| 204 | +
|
| 205 | + # OWASP Dependency Check |
| 206 | + dependency-security: |
| 207 | + name: Dependency Security Scan |
| 208 | + runs-on: ubuntu-latest |
| 209 | + timeout-minutes: 30 |
| 210 | + # Only run on schedule and main branch to avoid rate limits |
| 211 | + if: github.event_name == 'schedule' || github.ref == 'refs/heads/main' |
| 212 | + |
| 213 | + steps: |
| 214 | + - name: Checkout code |
| 215 | + uses: actions/checkout@v4 |
| 216 | + |
| 217 | + - name: Set up JDK ${{ env.JAVA_VERSION }} |
| 218 | + uses: actions/setup-java@v4 |
| 219 | + with: |
| 220 | + java-version: ${{ env.JAVA_VERSION }} |
| 221 | + distribution: 'temurin' |
| 222 | + cache: maven |
| 223 | + |
| 224 | + - name: Cache OWASP NVD data |
| 225 | + uses: actions/cache@v4 |
| 226 | + with: |
| 227 | + path: ~/.m2/repository/org/owasp/dependency-check-data |
| 228 | + key: ${{ runner.os }}-owasp-nvd-${{ hashFiles('**/pom.xml') }} |
| 229 | + restore-keys: | |
| 230 | + ${{ runner.os }}-owasp-nvd- |
| 231 | +
|
| 232 | + - name: Run OWASP Dependency Check |
| 233 | + env: |
| 234 | + NVD_API_KEY: ${{ secrets.NVD_API_KEY }} |
| 235 | + run: mvn dependency-check:check -B |
| 236 | + continue-on-error: true |
| 237 | + |
| 238 | + - name: Upload OWASP report |
| 239 | + if: always() |
| 240 | + uses: actions/upload-artifact@v4 |
| 241 | + with: |
| 242 | + name: owasp-dependency-check-report |
| 243 | + path: '**/target/dependency-check-report.html' |
| 244 | + retention-days: 30 |
| 245 | + |
| 246 | + - name: Create issue for HIGH/CRITICAL vulnerabilities |
| 247 | + if: failure() |
| 248 | + uses: actions/github-script@v7 |
| 249 | + with: |
| 250 | + script: | |
| 251 | + const fs = require('fs'); |
| 252 | + const title = '🔒 Security: HIGH/CRITICAL vulnerabilities detected'; |
| 253 | + const body = `OWASP Dependency Check has detected HIGH or CRITICAL vulnerabilities.\n\n` + |
| 254 | + `📊 [View detailed report](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId})\n\n` + |
| 255 | + `Please review and address these vulnerabilities.`; |
| 256 | +
|
| 257 | + github.rest.issues.create({ |
| 258 | + owner: context.repo.owner, |
| 259 | + repo: context.repo.repo, |
| 260 | + title: title, |
| 261 | + body: body, |
| 262 | + labels: ['security', 'dependencies'] |
| 263 | + }) |
| 264 | +
|
| 265 | + # Build validation |
| 266 | + build: |
| 267 | + name: Build All Modules |
| 268 | + runs-on: ubuntu-latest |
| 269 | + timeout-minutes: 15 |
| 270 | + needs: [code-format, code-style] |
| 271 | + |
| 272 | + steps: |
| 273 | + - name: Checkout code |
| 274 | + uses: actions/checkout@v4 |
| 275 | + |
| 276 | + - name: Set up JDK ${{ env.JAVA_VERSION }} |
| 277 | + uses: actions/setup-java@v4 |
| 278 | + with: |
| 279 | + java-version: ${{ env.JAVA_VERSION }} |
| 280 | + distribution: 'temurin' |
| 281 | + cache: maven |
| 282 | + |
| 283 | + - name: Build all modules |
| 284 | + run: mvn clean install -DskipTests -B |
| 285 | + |
| 286 | + - name: Upload build artifacts |
| 287 | + uses: actions/upload-artifact@v4 |
| 288 | + with: |
| 289 | + name: build-artifacts |
| 290 | + path: '**/target/*.jar' |
| 291 | + retention-days: 7 |
| 292 | + |
| 293 | + # Quality gate summary |
| 294 | + quality-gate-summary: |
| 295 | + name: Quality Gate Summary |
| 296 | + runs-on: ubuntu-latest |
| 297 | + needs: [fast-feedback, code-format, code-style, security-tests, full-test-suite, build] |
| 298 | + if: always() |
| 299 | + |
| 300 | + steps: |
| 301 | + - name: Check all jobs passed |
| 302 | + run: | |
| 303 | + if [[ "${{ needs.fast-feedback.result }}" != "success" || \ |
| 304 | + "${{ needs.code-format.result }}" != "success" || \ |
| 305 | + "${{ needs.code-style.result }}" != "success" || \ |
| 306 | + "${{ needs.security-tests.result }}" != "success" || \ |
| 307 | + "${{ needs.full-test-suite.result }}" != "success" || \ |
| 308 | + "${{ needs.build.result }}" != "success" ]]; then |
| 309 | + echo "❌ Quality gate FAILED" |
| 310 | + exit 1 |
| 311 | + else |
| 312 | + echo "✅ Quality gate PASSED" |
| 313 | + fi |
| 314 | +
|
| 315 | + - name: Post summary |
| 316 | + if: always() |
| 317 | + run: | |
| 318 | + echo "## 📊 Quality Gate Summary" >> $GITHUB_STEP_SUMMARY |
| 319 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 320 | + echo "| Check | Status |" >> $GITHUB_STEP_SUMMARY |
| 321 | + echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY |
| 322 | + echo "| Fast Feedback | ${{ needs.fast-feedback.result == 'success' && '✅' || '❌' }} |" >> $GITHUB_STEP_SUMMARY |
| 323 | + echo "| Code Formatting | ${{ needs.code-format.result == 'success' && '✅' || '❌' }} |" >> $GITHUB_STEP_SUMMARY |
| 324 | + echo "| Code Style | ${{ needs.code-style.result == 'success' && '✅' || '❌' }} |" >> $GITHUB_STEP_SUMMARY |
| 325 | + echo "| Security Tests | ${{ needs.security-tests.result == 'success' && '✅' || '❌' }} |" >> $GITHUB_STEP_SUMMARY |
| 326 | + echo "| Full Test Suite | ${{ needs.full-test-suite.result == 'success' && '✅' || '❌' }} |" >> $GITHUB_STEP_SUMMARY |
| 327 | + echo "| Build | ${{ needs.build.result == 'success' && '✅' || '❌' }} |" >> $GITHUB_STEP_SUMMARY |
0 commit comments