test coverage test #1317
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
| name: Build and Test SDK | |
| on: | |
| pull_request: | |
| branches: "**" | |
| env: | |
| DIFF_COVERAGE_THRESHOLD: '80' | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| issues: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - name: "[Checkout] Repo" | |
| uses: actions/checkout@v4 | |
| - name: "[Setup] Project" | |
| uses: ./.github/actions/project-setup | |
| - name: "[Code Formatting] Spotless" | |
| working-directory: OneSignalSDK | |
| run: | | |
| ./gradlew spotlessCheck --console=plain | |
| - name: "[Static Code Analysis] Detekt" | |
| working-directory: OneSignalSDK | |
| run: | | |
| ./gradlew detekt --console=plain | |
| - name: "[Test] SDK Unit Tests" | |
| working-directory: OneSignalSDK | |
| run: | | |
| ./gradlew testDebugUnitTest --console=plain --continue | |
| - name: "[Coverage] Generate JaCoCo merged XML" | |
| working-directory: OneSignalSDK | |
| run: | | |
| ./gradlew jacocoTestReportAll jacocoMergedReport --console=plain --continue | |
| - name: "[Setup] Python" | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.x' | |
| - name: "[Diff Coverage] Install diff-cover" | |
| run: | | |
| python -m pip install --upgrade pip diff-cover | |
| - name: "[Diff Coverage] Check and HTML report" | |
| working-directory: OneSignalSDK | |
| run: | | |
| REPORT=build/reports/jacoco/merged/jacocoMergedReport.xml | |
| test -f "$REPORT" || { echo "Merged JaCoCo report not found at $REPORT" >&2; exit 1; } | |
| python -m diff_cover.diff_cover_tool "$REPORT" \ | |
| --compare-branch=origin/main \ | |
| --fail-under=$DIFF_COVERAGE_THRESHOLD | |
| python -m diff_cover.diff_cover_tool "$REPORT" \ | |
| --compare-branch=origin/main \ | |
| --html-report diff_coverage.html || true | |
| # Generate markdown summary for PR comment | |
| python -m diff_cover.diff_cover_tool "$REPORT" \ | |
| --compare-branch=origin/main \ | |
| --markdown-report diff_coverage.md || true | |
| - name: Comment PR with coverage summary | |
| if: always() && github.event_name == 'pull_request' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const path = 'OneSignalSDK/diff_coverage.md'; | |
| if (fs.existsSync(path)) { | |
| const content = fs.readFileSync(path, 'utf8'); | |
| const body = `## 📊 Diff Coverage Report\n\n${content}\n\n📥 [Download detailed HTML report](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})`; | |
| // Find existing comment | |
| const comments = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| }); | |
| const botComment = comments.data.find(comment => | |
| comment.user.type === 'Bot' && comment.body.includes('Diff Coverage Report') | |
| ); | |
| if (botComment) { | |
| // Update existing comment | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: botComment.id, | |
| body: body | |
| }); | |
| } else { | |
| // Create new comment | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body: body | |
| }); | |
| } | |
| } | |
| - name: Upload diff coverage HTML | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: diff-coverage-report | |
| path: OneSignalSDK/diff_coverage.html | |
| - name: Unit tests results | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: unit-tests-results | |
| path: OneSignalSDK/unittest/build |