Code Coverage Report #163
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This workflow generates and deploys code coverage reports | |
| # It runs on a daily schedule (only if there were commits), or manually via workflow_dispatch | |
| name: Code Coverage Report | |
| on: | |
| schedule: | |
| - cron: '0 0 * * *' # Daily at midnight UTC | |
| workflow_dispatch: # Allow manual trigger | |
| # Optionally: push to main for immediate updates | |
| # push: | |
| # branches: [main] | |
| jobs: | |
| coverage: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write # Required: deploy coverage report to gh-pages | |
| env: | |
| DISPLAY: :0 | |
| MAVEN_OPTS: -Djava.awt.headless=true | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Check for recent commits (schedule only) | |
| if: github.event_name == 'schedule' | |
| id: check_commits | |
| run: | | |
| if git log --since="24 hours ago" --oneline | grep -q .; then | |
| echo "has_commits=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "has_commits=false" >> $GITHUB_OUTPUT | |
| echo "No commits in the last 24 hours, skipping coverage build" | |
| fi | |
| - name: Set up JDK 21 | |
| if: github.event_name != 'schedule' || steps.check_commits.outputs.has_commits == 'true' | |
| uses: actions/setup-java@v5 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| - name: Set up Node.js | |
| if: github.event_name != 'schedule' || steps.check_commits.outputs.has_commits == 'true' | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: '20' | |
| - name: Install CSS tools for testing | |
| if: github.event_name != 'schedule' || steps.check_commits.outputs.has_commits == 'true' | |
| run: | | |
| npm install -g prettier stylelint stylelint-config-standard | |
| - name: Install Xvfb | |
| if: github.event_name != 'schedule' || steps.check_commits.outputs.has_commits == 'true' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y xvfb xauth \ | |
| libgtk-3-0 libxext6 libxrender1 libxtst6 libxi6 libxrandr2 libxfixes3 \ | |
| libasound2t64 libnss3 libgbm1 | |
| sudo /usr/bin/Xvfb $DISPLAY -screen 0 1280x1024x24 & | |
| - name: Cache Maven dependencies | |
| if: github.event_name != 'schedule' || steps.check_commits.outputs.has_commits == 'true' | |
| uses: actions/cache@v5 | |
| with: | |
| path: ~/.m2/repository | |
| key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml', 'sandbox_target/*.target') }} | |
| restore-keys: ${{ runner.os }}-maven- | |
| - name: Set up Maven | |
| if: github.event_name != 'schedule' || steps.check_commits.outputs.has_commits == 'true' | |
| uses: stCarolas/setup-maven@d6af6abeda15e98926a57b5aa970a96bb37f97d1 | |
| with: | |
| maven-version: 3.9.9 | |
| - name: Build with Coverage | |
| if: github.event_name != 'schedule' || steps.check_commits.outputs.has_commits == 'true' | |
| run: xvfb-run --auto-servernum mvn -e -V -T 1C --batch-mode -Dtycho.localArtifacts=ignore -Pjacoco,product,repo,benchmark,cli-dist,maven-plugin clean verify | |
| - name: Cleanup xvfb | |
| if: github.event_name != 'schedule' || steps.check_commits.outputs.has_commits == 'true' | |
| uses: bcomnes/cleanup-xvfb@v1 | |
| - name: Prepare Test Reports for GitHub Pages | |
| if: github.event_name != 'schedule' || steps.check_commits.outputs.has_commits == 'true' | |
| run: | | |
| # Create directory structure for test reports | |
| mkdir -p /tmp/gh-pages/tests | |
| # Create an index.html for the tests directory | |
| cat > /tmp/gh-pages/tests/index.html << 'EOF' | |
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Sandbox Test Reports</title> | |
| <style> | |
| body { font-family: Arial, sans-serif; max-width: 1200px; margin: 0 auto; padding: 20px; } | |
| h1 { color: #333; } | |
| .module { margin: 20px 0; padding: 15px; border: 1px solid #ddd; border-radius: 5px; } | |
| .module h2 { margin-top: 0; color: #0066cc; } | |
| a { color: #0066cc; text-decoration: none; } | |
| a:hover { text-decoration: underline; } | |
| .description { color: #666; margin: 10px 0; } | |
| .update-info { background: #f0f0f0; padding: 10px; border-radius: 5px; margin: 20px 0; } | |
| </style> | |
| </head> | |
| <body> | |
| <h1>Sandbox Test Reports</h1> | |
| <p class="description"> | |
| This page contains HTML test reports for all test modules in the Sandbox project. | |
| Each module's report shows test results including passed, failed, and disabled tests. | |
| </p> | |
| <div class="update-info"> | |
| <strong>Note:</strong> These reports are updated from the scheduled (daily) coverage build, | |
| which includes all test results alongside code coverage metrics. | |
| For the most recent test-only results (updated on every main commit), see the main build workflow. | |
| </div> | |
| <div class="modules"> | |
| EOF | |
| # Copy test reports and add links to index | |
| for module in sandbox_*_test; do | |
| if [ -d "$module/target/site" ] && [ -f "$module/target/site/surefire-report.html" ]; then | |
| echo "Processing test report for $module..." | |
| # Copy the entire site directory to preserve resources | |
| mkdir -p "/tmp/gh-pages/tests/$module" | |
| cp -r "$module/target/site/"* "/tmp/gh-pages/tests/$module/" | |
| # Add module entry to index with HTML escaping for display text | |
| module_escaped=$(echo "$module" | sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'\''/\'/g') | |
| cat >> /tmp/gh-pages/tests/index.html << EOF | |
| <div class="module"> | |
| <h2>${module_escaped}</h2> | |
| <p><a href="${module}/surefire-report.html">View Test Report</a></p> | |
| </div> | |
| EOF | |
| fi | |
| done | |
| # Close HTML | |
| cat >> /tmp/gh-pages/tests/index.html << 'EOF' | |
| </div> | |
| <hr> | |
| <p style="text-align: center; color: #666; margin-top: 30px;"> | |
| Generated by <a href="https://github.com/carstenartur/sandbox">Sandbox Project</a> | | |
| <a href="../coverage/">Coverage Reports</a> | |
| </p> | |
| </body> | |
| </html> | |
| EOF | |
| echo "Test reports prepared in /tmp/gh-pages/tests" | |
| - name: Deploy Test Reports to GitHub Pages | |
| if: github.event_name != 'schedule' || steps.check_commits.outputs.has_commits == 'true' | |
| uses: peaceiris/actions-gh-pages@v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: /tmp/gh-pages/tests | |
| destination_dir: tests | |
| keep_files: true | |
| user_name: 'github-actions[bot]' | |
| user_email: 'github-actions[bot]@users.noreply.github.com' | |
| commit_message: 'Deploy test reports (from scheduled coverage build)' | |
| - name: Deploy Coverage to GitHub Pages | |
| if: github.event_name != 'schedule' || steps.check_commits.outputs.has_commits == 'true' | |
| uses: peaceiris/actions-gh-pages@v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: ./sandbox_coverage/target/site/jacoco-aggregate | |
| destination_dir: coverage | |
| keep_files: true | |
| user_name: 'github-actions[bot]' | |
| user_email: 'github-actions[bot]@users.noreply.github.com' | |
| commit_message: 'Deploy JaCoCo coverage report' | |
| - name: Report Deployed URLs | |
| if: github.event_name != 'schedule' || steps.check_commits.outputs.has_commits == 'true' | |
| run: | | |
| echo "### 🔗 Deployed Reports" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "📊 [View Coverage Report](https://carstenartur.github.io/sandbox/coverage/)" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "🧪 [View Test Reports](https://carstenartur.github.io/sandbox/tests/)" >> $GITHUB_STEP_SUMMARY |