-
-
Notifications
You must be signed in to change notification settings - Fork 1
344 lines (286 loc) · 10.4 KB
/
Copy pathci.yml
File metadata and controls
344 lines (286 loc) · 10.4 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
name: CI
on:
pull_request:
branches:
- main
- dev
push:
branches:
- main
- dev
permissions:
contents: write
pull-requests: write
issues: write
jobs:
analyze:
name: Analyze & Format Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.27.0'
channel: 'stable'
cache: true
- name: Get dependencies
run: flutter pub get
- name: Format code
run: dart format .
- name: Check for formatting changes
id: verify_diff
run: |
if ! git diff --quiet --exit-code; then
echo "formatted=true" >> $GITHUB_OUTPUT
echo "✨ Code was auto-formatted"
else
echo "formatted=false" >> $GITHUB_OUTPUT
echo "✅ Code is already properly formatted"
fi
- name: Commit formatted code
if: steps.verify_diff.outputs.formatted == 'true' && github.event_name == 'pull_request'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "style: auto-format code with dart format [skip ci]"
git push
- name: Analyze project source
run: flutter analyze --no-fatal-infos
- name: Check for outdated dependencies
run: flutter pub outdated
test:
name: Run Tests
runs-on: ubuntu-latest
needs: analyze
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.27.0'
channel: 'stable'
cache: true
- name: Get dependencies
run: flutter pub get
- name: Run tests
run: flutter test --coverage
- name: Generate coverage report
if: github.event_name == 'pull_request'
run: |
dart pub global activate coverage
dart pub global run coverage:format_coverage --lcov --in=coverage --out=coverage/lcov.info --report-on=lib
- name: Generate coverage summary
if: github.event_name == 'pull_request'
run: |
# Install lcov if not available
sudo apt-get update
sudo apt-get install -y lcov
# Generate summary
lcov --summary coverage/lcov.info > coverage_summary.txt 2>&1 || true
# Parse coverage percentage
COVERAGE=$(grep -oP 'lines......: \K[0-9.]+' coverage_summary.txt || echo "0")
# Create a detailed report
echo "## 📊 Test Coverage Report" > coverage_report.md
echo "" >> coverage_report.md
echo "### Overall Coverage: **${COVERAGE}%**" >> coverage_report.md
echo "" >> coverage_report.md
# Add coverage badge
if (( $(echo "$COVERAGE >= 80" | bc -l) )); then
echo "" >> coverage_report.md
elif (( $(echo "$COVERAGE >= 60" | bc -l) )); then
echo "" >> coverage_report.md
else
echo "" >> coverage_report.md
fi
echo "" >> coverage_report.md
echo "### Details" >> coverage_report.md
echo "\`\`\`" >> coverage_report.md
cat coverage_summary.txt >> coverage_report.md
echo "\`\`\`" >> coverage_report.md
# Generate per-file coverage if available
echo "" >> coverage_report.md
echo "### File Coverage" >> coverage_report.md
echo "\`\`\`" >> coverage_report.md
lcov --list coverage/lcov.info >> coverage_report.md 2>&1 || echo "Detailed file coverage not available" >> coverage_report.md
echo "\`\`\`" >> coverage_report.md
- name: Comment PR with coverage
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const report = fs.readFileSync('coverage_report.md', 'utf8');
// Find existing coverage comment
const { data: comments } = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('📊 Test Coverage Report')
);
const commentBody = `${report}\n\n---\n*Updated: ${new Date().toUTCString()}*`;
if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
comment_id: botComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
} else {
// Create new comment
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
}
- name: Upload coverage artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: |
coverage/
coverage_report.md
retention-days: 30
package-analysis:
name: Package Analysis
runs-on: ubuntu-latest
needs: analyze
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.27.0'
channel: 'stable'
cache: true
- name: Get dependencies
run: flutter pub get
- name: Run package analysis
run: |
dart pub global activate pana
pana --no-warning --exit-code-threshold 0
- name: Dry run pub publish
run: flutter pub publish --dry-run
build-example:
name: Build Example App
runs-on: ${{ matrix.os }}
needs: test
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
include:
- os: ubuntu-latest
build-command: flutter build web
platform: web
- os: macos-latest
build-command: flutter build ios --no-codesign
platform: ios
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.27.0'
channel: 'stable'
cache: true
- name: Get dependencies (example)
working-directory: ./example
run: flutter pub get
- name: Build ${{ matrix.platform }}
working-directory: ./example
run: ${{ matrix.build-command }}
security-scan:
name: Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.27.0'
channel: 'stable'
cache: true
- name: Get dependencies
run: flutter pub get
- name: Check for known security issues
run: |
dart pub global activate dependency_validator
# Ignore references in documentation (README, example mentions)
dependency_validator --ignore=example,file_picker || true
# Check for actual security vulnerabilities
flutter pub outdated --show-all 2>&1 | grep -i "security\|vulnerability" || echo "No known security issues found"
lint-report:
name: Generate Lint Report
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.27.0'
channel: 'stable'
cache: true
- name: Get dependencies
run: flutter pub get
- name: Run analyzer and save output
run: |
flutter analyze > analyze_report.txt 2>&1 || true
# Create formatted report
echo "## 🔍 Static Analysis Report" > lint_report.md
echo "" >> lint_report.md
echo "\`\`\`" >> lint_report.md
cat analyze_report.txt >> lint_report.md
echo "\`\`\`" >> lint_report.md
- name: Comment PR with analysis results
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const report = fs.readFileSync('lint_report.md', 'utf8');
// Find existing lint comment
const { data: comments } = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('🔍 Static Analysis Report')
);
const commentBody = `${report}\n\n---\n*Updated: ${new Date().toUTCString()}*`;
if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
comment_id: botComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
} else {
// Create new comment
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
}