-
Notifications
You must be signed in to change notification settings - Fork 378
149 lines (139 loc) · 5.91 KB
/
Copy pathci.yml
File metadata and controls
149 lines (139 loc) · 5.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
name: Build and Test SDK
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
pull_request:
branches: ["**"]
push:
branches:
- main
- "*-main"
workflow_dispatch:
env:
DIFF_COVERAGE_THRESHOLD: "80"
permissions:
contents: read
pull-requests: write
issues: write
jobs:
build:
runs-on: ubuntu-latest
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: "[Build] Demo app (minified GMS + Huawei release)"
working-directory: OneSignalSDK
run: |
./gradlew :app:assembleGmsRelease :app:assembleHuaweiRelease --console=plain
- name: "[Diff Coverage] Check for bypass"
id: coverage_bypass
if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
run: |
# Check if PR has Skip Coverage Check label
if [ "${{ github.event_name }}" = "pull_request" ]; then
LABELS="${{ toJson(github.event.pull_request.labels.*.name) }}"
if echo "$LABELS" | grep -qiE "Skip Coverage Check|skip-coverage-check"; then
echo "bypass=true" >> $GITHUB_OUTPUT
echo "reason=PR has 'Skip Coverage Check' label" >> $GITHUB_OUTPUT
echo "⚠️ Coverage check will not fail build (PR has 'Skip Coverage Check' label)"
echo " Coverage will still be checked and reported"
else
echo "bypass=false" >> $GITHUB_OUTPUT
fi
else
echo "bypass=false" >> $GITHUB_OUTPUT
fi
- name: "[PR] Coverage on changed lines (min ${{ env.DIFF_COVERAGE_THRESHOLD }}%)"
if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
working-directory: OneSignalSDK
env:
# Exact PR diff (vs merge ref / wrong base branch)
DIFF_BASE_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || '' }}
DIFF_HEAD_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || '' }}
run: |
# Use the shared coverage check script for consistency
# Generate markdown report for PR comments
# If bypassed, still run the check but don't fail the build
set +e # Don't exit on error - we want to generate the report even if coverage fails
if [ "${{ steps.coverage_bypass.outputs.bypass }}" = "true" ]; then
SKIP_COVERAGE_CHECK=true GENERATE_MARKDOWN=true DIFF_COVERAGE_THRESHOLD=$DIFF_COVERAGE_THRESHOLD ./coverage/checkCoverage.sh
else
GENERATE_MARKDOWN=true DIFF_COVERAGE_THRESHOLD=$DIFF_COVERAGE_THRESHOLD ./coverage/checkCoverage.sh
fi
COVERAGE_EXIT_CODE=$?
set -e # Re-enable exit on error
# Check if markdown report was generated
if [ -f "diff_coverage.md" ]; then
echo "✅ Coverage report generated"
else
echo "⚠️ Coverage report not generated"
fi
# Only fail the build if coverage is below threshold AND not bypassed
if [ "${{ steps.coverage_bypass.outputs.bypass }}" != "true" ] && [ $COVERAGE_EXIT_CODE -ne 0 ]; then
echo "❌ Coverage check failed - build will fail"
exit $COVERAGE_EXIT_CODE
elif [ "${{ steps.coverage_bypass.outputs.bypass }}" = "true" ]; then
echo "⚠️ Coverage check completed (bypassed - build will not fail)"
exit 0
else
echo "✅ Coverage check passed"
exit 0
fi
- 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📥 [View workflow run](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: Unit tests results
if: failure()
uses: actions/upload-artifact@v4
with:
name: unit-tests-results
path: OneSignalSDK/unittest/build