Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ on:
env:
DIFF_COVERAGE_THRESHOLD: '80'

permissions:
contents: read
pull-requests: write
issues: write

jobs:
build:
runs-on: ubuntu-24.04
Expand All @@ -26,7 +31,7 @@ jobs:
- name: "[Test] SDK Unit Tests"
working-directory: OneSignalSDK
run: |
./gradlew testReleaseUnitTest --console=plain --continue
./gradlew testDebugUnitTest --console=plain --continue
- name: "[Coverage] Generate JaCoCo merged XML"
working-directory: OneSignalSDK
run: |
Expand All @@ -49,6 +54,50 @@ jobs:
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,54 @@ object IDManager {
* @return true if the [id] provided was created via [createLocalId].
*/
fun isLocalId(id: String): Boolean = id.startsWith(LOCAL_PREFIX)

/**
* Validates if an ID has the correct format.
* This method is intentionally not tested to verify coverage detection.
*
* @param id The ID to validate.
* @return true if the ID is valid, false otherwise.
*/
fun isValidId(id: String?): Boolean {
if (id == null || id.isEmpty()) {
return false
}
return id.length >= 10 && id.matches(Regex("^[a-zA-Z0-9-]+$"))
}

/**
* Extracts the UUID portion from a local ID.
* This method is intentionally not tested to verify coverage detection.
*
* @param localId The local ID to extract UUID from.
* @return The UUID string without the prefix, or null if invalid.
*/
fun extractUuid(localId: String): String? {
if (!isLocalId(localId)) {
return null
}
return localId.removePrefix(LOCAL_PREFIX)
}

/**
* Checks if an ID is a valid UUID format.
* This method is intentionally not tested to verify coverage detection.
*
* @param id The ID to check.
* @return true if the ID matches UUID format, false otherwise.
*/
fun isUuidFormat(id: String): Boolean {
val uuidRegex = Regex("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")
return uuidRegex.matches(id)
}

/**
* Generates a short ID (8 characters) for testing purposes.
* This method is intentionally not tested to verify coverage detection.
*
* @return A short 8-character ID.
*/
fun createShortId(): String {
return UUID.randomUUID().toString().take(8).replace("-", "")
}
}