-
Notifications
You must be signed in to change notification settings - Fork 378
198 lines (185 loc) · 7.58 KB
/
Copy pathci.yml
File metadata and controls
198 lines (185 loc) · 7.58 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
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:
code-quality:
runs-on: ubuntu-latest
steps:
- name: "[Checkout] Repo"
uses: actions/checkout@v7
with:
submodules: recursive
- 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
test:
runs-on: ubuntu-latest
steps:
- name: "[Checkout] Repo"
uses: actions/checkout@v7
with:
fetch-depth: 0
submodules: recursive
- name: "[Setup] Project"
uses: ./.github/actions/project-setup
with:
# Keep untrusted fork PRs read-only; this is the sole cache writer for other runs.
cache-read-only: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository }}
- name: "[Test] SDK Unit Tests"
id: unit_tests
working-directory: OneSignalSDK
run: |
./gradlew testDebugUnitTest --console=plain --continue
- name: "[Diff Coverage] Check for bypass"
id: coverage_bypass
if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
env:
# Evaluate in Actions expressions (not shell) so label names with spaces cannot break quoting.
HAS_SKIP_COVERAGE_LABEL: ${{ github.event_name == 'pull_request' && (contains(github.event.pull_request.labels.*.name, 'Skip Coverage Check') || contains(github.event.pull_request.labels.*.name, 'skip-coverage-check')) }}
run: |
if [ "$HAS_SKIP_COVERAGE_LABEL" = "true" ]; 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
- 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@v9
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() && steps.unit_tests.outcome == 'failure'
uses: actions/upload-artifact@v7
with:
name: unit-tests-results
path: |
OneSignalSDK/**/build/reports/tests/
OneSignalSDK/**/build/test-results/
if-no-files-found: warn
demo-build:
runs-on: ubuntu-latest
steps:
- name: "[Checkout] Repo"
uses: actions/checkout@v7
with:
submodules: recursive
- name: "[Setup] Project"
uses: ./.github/actions/project-setup
- name: "[Build] Demo app (minified GMS + Huawei release)"
working-directory: OneSignalSDK
run: |
./gradlew :app:assembleGmsRelease :app:assembleHuaweiRelease --console=plain
# Keep the existing required check stable while the workloads run independently.
build:
if: always()
needs:
- code-quality
- test
- demo-build
runs-on: ubuntu-latest
steps:
- name: Verify parallel jobs
env:
CODE_QUALITY_RESULT: ${{ needs.code-quality.result }}
TEST_RESULT: ${{ needs.test.result }}
DEMO_BUILD_RESULT: ${{ needs.demo-build.result }}
run: |
if [ "$CODE_QUALITY_RESULT" != "success" ] ||
[ "$TEST_RESULT" != "success" ] ||
[ "$DEMO_BUILD_RESULT" != "success" ]; then
echo "One or more required jobs failed or were cancelled."
exit 1
fi