|
| 1 | +name: CI Reports |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - 'features/**' |
| 8 | + pull_request: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + |
| 12 | +jobs: |
| 13 | + ci-reports: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + env: |
| 16 | + RUN_LIVE_E2E: "false" |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Set up JDK 17 |
| 23 | + uses: actions/setup-java@v4 |
| 24 | + with: |
| 25 | + java-version: '17' |
| 26 | + distribution: 'temurin' |
| 27 | + cache: 'maven' |
| 28 | + |
| 29 | + # ===== TESTING ===== |
| 30 | + - name: Run unit tests from module root |
| 31 | + run: ./mvnw -B -ntp clean test |
| 32 | + working-directory: . |
| 33 | + |
| 34 | + # ===== CODE COVERAGE ===== |
| 35 | + - name: Generate JaCoCo coverage report |
| 36 | + run: ./mvnw -B -ntp jacoco:report |
| 37 | + |
| 38 | + # ===== STATIC ANALYSIS ===== |
| 39 | + - name: Generate PMD HTML report |
| 40 | + run: ./mvnw -B -ntp pmd:pmd -Dpmd.failOnViolation=false |
| 41 | + |
| 42 | + - name: Run Checkstyle |
| 43 | + run: ./mvnw -B -ntp checkstyle:checkstyle |
| 44 | + |
| 45 | + # ===== OPTIONAL LIVE E2E (requires LIVE_E2E env + external deps) ===== |
| 46 | + - name: Run live E2E (opt-in) |
| 47 | + if: env.RUN_LIVE_E2E == 'true' |
| 48 | + env: |
| 49 | + LIVE_E2E: "true" |
| 50 | + run: ./mvnw -B -ntp -Dtest=dev.coms4156.project.metadetect.e2e.ClientServiceLiveE2eTest test |
| 51 | + |
| 52 | + # ===== CONVERT TO PNG ===== |
| 53 | + - name: Install wkhtmltopdf for report conversion |
| 54 | + run: | |
| 55 | + sudo apt-get update |
| 56 | + sudo apt-get install -y wkhtmltopdf |
| 57 | + |
| 58 | + - name: Make conversion script executable |
| 59 | + run: chmod +x scripts/html_to_png.sh |
| 60 | + |
| 61 | + - name: Convert HTML reports to PNG |
| 62 | + run: bash scripts/html_to_png.sh |
| 63 | + |
| 64 | + - name: Collect additional raw artifacts into /reports |
| 65 | + if: always() |
| 66 | + run: | |
| 67 | + mkdir -p reports/test-results reports/raw |
| 68 | + if [ -d "target/surefire-reports" ]; then |
| 69 | + cp -R target/surefire-reports/. reports/test-results/ |
| 70 | + fi |
| 71 | + if [ -f "target/pmd.xml" ]; then |
| 72 | + cp target/pmd.xml reports/raw/pmd.xml |
| 73 | + fi |
| 74 | + if [ -f "target/checkstyle-result.xml" ]; then |
| 75 | + cp target/checkstyle-result.xml reports/raw/checkstyle-result.xml |
| 76 | + fi |
| 77 | + if [ -f "target/site/jacoco/jacoco.xml" ]; then |
| 78 | + cp target/site/jacoco/jacoco.xml reports/raw/jacoco.xml |
| 79 | + fi |
| 80 | + |
| 81 | + # ===== QUALITY GATES ===== |
| 82 | + - name: Enforce PMD violations |
| 83 | + run: ./mvnw -B -ntp pmd:check |
| 84 | + |
| 85 | + # ===== UPLOAD ARTIFACTS ===== |
| 86 | + - name: Upload CI reports (HTML, PNG, XML) |
| 87 | + uses: actions/upload-artifact@v4 |
| 88 | + if: always() |
| 89 | + with: |
| 90 | + name: ci-reports |
| 91 | + path: | |
| 92 | + reports/ |
| 93 | + target/surefire-reports/ |
| 94 | + retention-days: 30 |
| 95 | + |
| 96 | + # ===== SUMMARY ===== |
| 97 | + - name: Generate CI Summary |
| 98 | + if: always() |
| 99 | + run: | |
| 100 | + echo "## 📊 CI Report Summary" >> $GITHUB_STEP_SUMMARY |
| 101 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 102 | + echo "### Test Results" >> $GITHUB_STEP_SUMMARY |
| 103 | + if [ -d "target/surefire-reports" ]; then |
| 104 | + TESTS=$(find target/surefire-reports -name "TEST-*.xml" | wc -l) |
| 105 | + echo "- Test suites executed: $TESTS" >> $GITHUB_STEP_SUMMARY |
| 106 | + fi |
| 107 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 108 | + echo "### Available Reports" >> $GITHUB_STEP_SUMMARY |
| 109 | + echo "- ✅ JaCoCo coverage (HTML + PNG snapshot)" >> $GITHUB_STEP_SUMMARY |
| 110 | + echo "- ✅ PMD static analysis (HTML + PNG snapshot)" >> $GITHUB_STEP_SUMMARY |
| 111 | + echo "- ✅ Unit test XML results" >> $GITHUB_STEP_SUMMARY |
| 112 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 113 | + echo "### 📥 Download Artifacts" >> $GITHUB_STEP_SUMMARY |
| 114 | + echo "All consolidated under the 'ci-reports' artifact (reports/ + surefire XML)." >> $GITHUB_STEP_SUMMARY |
0 commit comments