-
Notifications
You must be signed in to change notification settings - Fork 66
430 lines (354 loc) · 13.4 KB
/
build.yml
File metadata and controls
430 lines (354 loc) · 13.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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
name: Build
on:
push:
branches:
- main
pull_request:
paths-ignore:
- "**.md"
- "**.mdx"
schedule:
# runs the CI everyday at 10AM
- cron: "0 10 * * *"
workflow_dispatch:
inputs:
dart_version:
description: 'Dart version to test (stable or beta)'
required: false
default: 'stable'
jobs:
# Check license headers on all source files
check-license-header:
name: Check License Headers
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download addlicense
run: |
curl -sL https://github.com/google/addlicense/releases/download/v1.2.0/addlicense_v1.2.0_Linux_x86_64.tar.gz | tar xz -C /usr/local/bin addlicense
chmod +x /usr/local/bin/addlicense
- name: Check license headers
run: |
addlicense -f header_template.txt \
--check \
--ignore "**/*.yml" \
--ignore "**/*.yaml" \
--ignore "**/*.xml" \
--ignore "**/*.g.dart" \
--ignore "**/*.sh" \
--ignore "**/*.html" \
--ignore "**/*.js" \
--ignore "**/*.ts" \
--ignore "**/*.txt" \
--ignore "**/.dart_tool/**" \
--ignore "LICENSE" \
.
lint:
name: Lint (Dart ${{ matrix.dart-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
dart-version: [stable, beta]
defaults:
run:
working-directory: packages/dart_firebase_admin
steps:
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2.7.1
with:
channel: ${{ matrix.dart-version }}
- name: Cache pub dependencies
uses: actions/cache@v4
with:
path: ~/.pub-cache
key: pub-${{ matrix.dart-version }}-${{ hashFiles('**/pubspec.lock') }}
restore-keys: |
pub-${{ matrix.dart-version }}-
pub-
- name: Install Melos
run: dart pub global activate melos
working-directory: .
- name: Bootstrap workspace
run: melos bootstrap
working-directory: .
- name: Check format
run: dart format --set-exit-if-changed .
- name: Analyze
run: dart analyze
test:
name: Test (Dart ${{ matrix.dart-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
dart-version: [stable, beta]
defaults:
run:
working-directory: packages/dart_firebase_admin
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
- uses: actions/setup-node@v4
- uses: subosito/flutter-action@v2.7.1
with:
channel: ${{ matrix.dart-version }}
- name: Cache pub dependencies
uses: actions/cache@v4
with:
path: ~/.pub-cache
key: pub-${{ matrix.dart-version }}-${{ hashFiles('**/pubspec.lock') }}
restore-keys: |
pub-${{ matrix.dart-version }}-
pub-
- name: Cache Firebase CLI
uses: actions/cache@v4
with:
path: ~/.cache/firebase/emulators
key: firebase-emulators
restore-keys: |
firebase-
- name: Add pub cache bin to PATH
run: |
echo "$HOME/.pub-cache/bin" >> $GITHUB_PATH
echo "PUB_CACHE=$HOME/.pub-cache" >> $GITHUB_ENV
- name: Install Melos
run: dart pub global activate melos
working-directory: .
- name: Bootstrap workspace
run: melos bootstrap
working-directory: .
- name: Install Firebase CLI
run: npm install -g firebase-tools
- name: Run dart_firebase_admin tests with coverage
run: ${{ github.workspace }}/scripts/coverage.sh
- name: Run google_cloud_firestore tests with coverage
run: ${{ github.workspace }}/scripts/firestore-coverage.sh
- name: Merge coverage reports
run: |
# Save individual package coverage files before merging
cp coverage.lcov coverage_admin.lcov
cp ../google_cloud_firestore/coverage.lcov coverage_firestore.lcov
# Merge coverage reports from all packages (relative to packages/dart_firebase_admin)
# Only merge files that exist
COVERAGE_FILES=""
[ -f coverage.lcov ] && COVERAGE_FILES="$COVERAGE_FILES coverage.lcov"
[ -f ../google_cloud_firestore/coverage.lcov ] && COVERAGE_FILES="$COVERAGE_FILES ../google_cloud_firestore/coverage.lcov"
if [ -n "$COVERAGE_FILES" ]; then
cat $COVERAGE_FILES > merged_coverage.lcov
mv merged_coverage.lcov coverage.lcov
else
echo "No coverage files found!"
exit 1
fi
- name: Check coverage threshold and generate report
if: matrix.dart-version == 'stable'
id: coverage
run: |
# Calculate coverage for each package
calculate_coverage() {
local file=$1
if [ -f "$file" ]; then
local total=$(grep -E "^LF:" "$file" | awk -F: '{sum+=$2} END {print sum}')
local hit=$(grep -E "^LH:" "$file" | awk -F: '{sum+=$2} END {print sum}')
if [ "$total" -gt 0 ]; then
local pct=$(awk "BEGIN {printf \"%.2f\", ($hit/$total)*100}")
echo "$pct|$hit|$total"
else
echo "0.00|0|0"
fi
else
echo "0.00|0|0"
fi
}
# Get individual package coverage from saved copies
ADMIN_COV=$(calculate_coverage "coverage_admin.lcov")
FIRESTORE_COV=$(calculate_coverage "coverage_firestore.lcov")
STORAGE_COV=$(calculate_coverage "coverage_storage.lcov")
ADMIN_PCT=$(echo $ADMIN_COV | cut -d'|' -f1)
ADMIN_HIT=$(echo $ADMIN_COV | cut -d'|' -f2)
ADMIN_TOTAL=$(echo $ADMIN_COV | cut -d'|' -f3)
FIRESTORE_PCT=$(echo $FIRESTORE_COV | cut -d'|' -f1)
FIRESTORE_HIT=$(echo $FIRESTORE_COV | cut -d'|' -f2)
FIRESTORE_TOTAL=$(echo $FIRESTORE_COV | cut -d'|' -f3)
STORAGE_PCT=$(echo $STORAGE_COV | cut -d'|' -f1)
STORAGE_HIT=$(echo $STORAGE_COV | cut -d'|' -f2)
STORAGE_TOTAL=$(echo $STORAGE_COV | cut -d'|' -f3)
# Calculate total coverage from merged file
TOTAL_LINES=$(grep -E "^(DA|LF):" coverage.lcov | grep "^LF:" | awk -F: '{sum+=$2} END {print sum}')
HIT_LINES=$(grep -E "^(DA|LH):" coverage.lcov | grep "^LH:" | awk -F: '{sum+=$2} END {print sum}')
if [ "$TOTAL_LINES" -gt 0 ]; then
COVERAGE_PCT=$(awk "BEGIN {printf \"%.2f\", ($HIT_LINES/$TOTAL_LINES)*100}")
else
COVERAGE_PCT="0.00"
fi
# Output for GitHub Actions
echo "coverage=${COVERAGE_PCT}" >> $GITHUB_OUTPUT
echo "total_lines=${TOTAL_LINES}" >> $GITHUB_OUTPUT
echo "hit_lines=${HIT_LINES}" >> $GITHUB_OUTPUT
echo "admin_coverage=${ADMIN_PCT}" >> $GITHUB_OUTPUT
echo "firestore_coverage=${FIRESTORE_PCT}" >> $GITHUB_OUTPUT
echo "storage_coverage=${STORAGE_PCT}" >> $GITHUB_OUTPUT
# Console output
echo "=== Coverage Report ==="
echo "dart_firebase_admin: ${ADMIN_PCT}% (${ADMIN_HIT}/${ADMIN_TOTAL} lines)"
echo "google_cloud_firestore: ${FIRESTORE_PCT}% (${FIRESTORE_HIT}/${FIRESTORE_TOTAL} lines)"
echo "----------------------"
echo "Total: ${COVERAGE_PCT}% (${HIT_LINES}/${TOTAL_LINES} lines)"
# Check threshold
if (( $(echo "$COVERAGE_PCT < 40" | bc -l) )); then
echo "status=❌ Coverage ${COVERAGE_PCT}% is below 40% threshold" >> $GITHUB_OUTPUT
exit 1
else
echo "status=✅ Coverage ${COVERAGE_PCT}% meets 40% threshold" >> $GITHUB_OUTPUT
fi
- name: Comment coverage on PR
if: matrix.dart-version == 'stable' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false
uses: actions/github-script@v7
with:
script: |
const coverage = '${{ steps.coverage.outputs.coverage }}';
const status = '${{ steps.coverage.outputs.status }}';
const hitLines = '${{ steps.coverage.outputs.hit_lines }}';
const totalLines = '${{ steps.coverage.outputs.total_lines }}';
const adminCov = '${{ steps.coverage.outputs.admin_coverage }}';
const firestoreCov = '${{ steps.coverage.outputs.firestore_coverage }}';
const storageCov = '${{ steps.coverage.outputs.storage_coverage }}';
const body = `## Coverage Report
${status}
**Total Coverage:** ${coverage}%
**Lines Covered:** ${hitLines}/${totalLines}
### Package Breakdown
| Package | Coverage |
|---------|----------|
| dart_firebase_admin | ${adminCov}% |
| google_cloud_firestore | ${firestoreCov}% |
_Minimum threshold: 40%_`;
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('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 coverage to codecov
if: matrix.dart-version == 'stable'
continue-on-error: true
uses: codecov/codecov-action@v4
with:
files: packages/dart_firebase_admin/coverage.lcov
flags: unittests
fail_ci_if_error: false
test-wif:
name: Test - WIF Auth (Dart ${{ matrix.dart-version }})
runs-on: ubuntu-latest
# Skip for fork PRs — secrets are not available
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false
permissions:
contents: 'read'
id-token: 'write'
strategy:
fail-fast: false
matrix:
dart-version: [stable, beta]
defaults:
run:
working-directory: packages/dart_firebase_admin
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: subosito/flutter-action@v2.7.1
with:
channel: ${{ matrix.dart-version }}
- name: Authenticate to Google Cloud/Firebase
uses: google-github-actions/auth@v2
with:
workload_identity_provider: '${{ secrets.WORKLOAD_IDENTITY_PROVIDER }}'
service_account: '${{ secrets.SERVICE_ACCOUNT }}'
- name: Cache pub dependencies
uses: actions/cache@v4
with:
path: ~/.pub-cache
key: pub-${{ matrix.dart-version }}-${{ hashFiles('**/pubspec.lock') }}
restore-keys: |
pub-${{ matrix.dart-version }}-
pub-
- name: Add pub cache bin to PATH
run: |
echo "$HOME/.pub-cache/bin" >> $GITHUB_PATH
echo "PUB_CACHE=$HOME/.pub-cache" >> $GITHUB_ENV
- name: Install Melos
run: dart pub global activate melos
working-directory: .
- name: Bootstrap workspace
run: melos bootstrap
working-directory: .
- name: Run WIF auth test
run: dart test test/integration/app/firebase_app_prod_test.dart --concurrency=1
build:
name: Build verification (Dart ${{ matrix.dart-version }})
runs-on: ubuntu-latest
needs: [check-license-header, lint, test, test-wif]
# Run even if test-wif was skipped (fork PRs), but not if other jobs failed
if: |
always() &&
needs.check-license-header.result == 'success' &&
needs.lint.result == 'success' &&
needs.test.result == 'success' &&
(needs.test-wif.result == 'success' || needs.test-wif.result == 'skipped')
strategy:
fail-fast: false
matrix:
dart-version: [stable, beta]
defaults:
run:
working-directory: packages/dart_firebase_admin
steps:
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2.7.1
with:
channel: ${{ matrix.dart-version }}
- name: Cache pub dependencies
uses: actions/cache@v4
with:
path: ~/.pub-cache
key: pub-${{ matrix.dart-version }}-${{ hashFiles('**/pubspec.lock') }}
restore-keys: |
pub-${{ matrix.dart-version }}-
pub-
- name: Install Melos
run: dart pub global activate melos
working-directory: .
- name: Bootstrap workspace
run: melos bootstrap
working-directory: .
- name: Verify package
run: dart pub publish --dry-run