-
Notifications
You must be signed in to change notification settings - Fork 2
345 lines (290 loc) · 10.1 KB
/
test.yml
File metadata and controls
345 lines (290 loc) · 10.1 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
# Copyright 2026 Firebase
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Tests
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
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 "**/test/fixtures/nodejs_reference/**" \
--ignore "**/test/fixtures/with_options_nodejs/**" \
.
# Dart package analysis and formatting
lint-analyze:
name: Format & Analyze (${{ matrix.sdk }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sdk: [stable, beta]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Dart SDK
uses: dart-lang/setup-dart@v1
with:
sdk: ${{ matrix.sdk }}
- name: Print Dart version
run: dart --version
- name: Install dependencies
run: dart pub upgrade
- name: Verify formatting
run: dart format --output=none --set-exit-if-changed .
if: matrix.sdk == 'stable'
- name: Analyze all packages
run: |
dart analyze --fatal-infos
for dir in example/*/; do
if [ -f "$dir/pubspec.yaml" ]; then
echo "Analyzing $dir..."
dart analyze --fatal-infos "$dir"
fi
done
dart analyze --fatal-infos test/fixtures/dart_reference
# TODO: Re-enable when unit tests are added
# - name: Run unit tests
# run: dart test --exclude-tags=snapshot,integration,e2e
# Builder tests - generate and verify functions.yaml
builder-tests:
name: Builder Tests
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Dart SDK
uses: dart-lang/setup-dart@v1
with:
sdk: stable
- name: Install dependencies (root)
run: dart pub upgrade
- name: Install dependencies (fixture)
working-directory: test/fixtures/dart_reference
run: dart pub upgrade
- name: Run build_runner
working-directory: test/fixtures/dart_reference
run: dart run build_runner build --delete-conflicting-outputs
- name: Verify functions.yaml was generated
run: |
if [ ! -f "test/fixtures/dart_reference/functions.yaml" ]; then
echo "Error: functions.yaml was not generated"
exit 1
fi
echo "✓ functions.yaml generated successfully"
- name: Display generated manifest
run: |
echo "Generated Dart manifest:"
cat test/fixtures/dart_reference/functions.yaml
- name: Upload generated manifest
uses: actions/upload-artifact@v4
with:
name: dart-manifest
path: test/fixtures/dart_reference/functions.yaml
retention-days: 7
# Snapshot tests - compare Dart manifest with Node.js reference
snapshot-tests:
name: Snapshot Tests
runs-on: ubuntu-latest
needs: builder-tests
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Dart SDK
uses: dart-lang/setup-dart@v1
with:
sdk: stable
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: test/fixtures/nodejs_reference/package-lock.json
- name: Install Dart dependencies
run: dart pub upgrade
- name: Download Dart manifest from builder-tests
uses: actions/download-artifact@v4
with:
name: dart-manifest
path: test/fixtures/dart_reference
- name: Install Node.js dependencies (nodejs_reference)
working-directory: test/fixtures/nodejs_reference
run: npm ci
- name: Generate Node.js manifest
working-directory: test/fixtures/nodejs_reference
run: |
echo "Starting firebase-functions server..."
GCLOUD_PROJECT="test-project" \
PORT="8080" \
FUNCTIONS_CONTROL_API="true" \
npx firebase-functions > /tmp/ff.log 2>&1 &
FF_PID=$!
echo "Server PID: $FF_PID"
# Wait for server to be ready
echo "Waiting for server to start..."
for i in {1..30}; do
if curl -s http://localhost:8080/__/functions.yaml > /dev/null 2>&1; then
echo "✓ Server is ready"
break
fi
if [ $i -eq 30 ]; then
echo "Error: Server failed to start"
cat /tmp/ff.log
exit 1
fi
sleep 1
done
# Fetch manifest
echo "Fetching manifest..."
curl -s http://localhost:8080/__/functions.yaml | python3 -m json.tool > nodejs_manifest.json
# Stop server
kill $FF_PID 2>/dev/null || true
echo "Node.js manifest generated:"
cat nodejs_manifest.json
- name: Display all manifests
run: |
echo "========== DART MANIFEST =========="
cat test/fixtures/dart_reference/functions.yaml
echo ""
echo "========== NODE.JS MANIFEST =========="
cat test/fixtures/nodejs_reference/nodejs_manifest.json
- name: Run snapshot comparison tests
run: dart test test/snapshots/manifest_snapshot_test.dart --reporter=expanded
- name: Upload manifests on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: manifests-comparison
path: |
test/fixtures/dart_reference/functions.yaml
test/fixtures/nodejs_reference/nodejs_manifest.json
retention-days: 30
# E2E tests with Firebase Emulator
e2e-tests:
name: E2E Tests (Emulator)
runs-on: ubuntu-latest
needs: builder-tests
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout custom firebase-tools
uses: actions/checkout@v4
with:
repository: invertase/firebase-tools
ref: '@invertase/dart'
path: custom-firebase-tools
- name: Setup Dart SDK
uses: dart-lang/setup-dart@v1
with:
sdk: stable
- name: Setup Java 21
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Link custom firebase-tools
working-directory: custom-firebase-tools
run: npm i && npm link
- name: Verify Firebase CLI
run: firebase --version
- name: Install dependencies (root)
run: dart pub upgrade
- name: Download Dart manifest from builder-tests
uses: actions/download-artifact@v4
with:
name: dart-manifest
path: test/fixtures/dart_reference
- name: Create .env.local for params
run: |
cat > test/fixtures/dart_reference/.env.local << 'EOF'
WELCOME_MESSAGE=Hello from Dart Functions!
MIN_INSTANCES=0
IS_PRODUCTION=false
EOF
echo "✓ Created .env.local with default param values"
- name: Run E2E tests
run: dart test test/e2e/e2e_test.dart --reporter=expanded
timeout-minutes: 5
- name: Upload test logs on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: e2e-test-logs
path: |
test/fixtures/dart_reference/functions.yaml
test/fixtures/dart_reference/firebase-debug.log
retention-days: 7
# Test result summary
test-summary:
name: Test Summary
runs-on: ubuntu-latest
needs: [check-license-header, lint-analyze, builder-tests, snapshot-tests, e2e-tests]
if: always()
steps:
- name: Check test results
run: |
if [ "${{ needs.check-license-header.result }}" != "success" ]; then
echo "❌ License header check failed"
exit 1
fi
if [ "${{ needs.lint-analyze.result }}" != "success" ]; then
echo "❌ Format & Analyze failed"
exit 1
fi
if [ "${{ needs.builder-tests.result }}" != "success" ]; then
echo "❌ Builder tests failed"
exit 1
fi
if [ "${{ needs.snapshot-tests.result }}" != "success" ]; then
echo "❌ Snapshot tests failed"
exit 1
fi
if [ "${{ needs.e2e-tests.result }}" != "success" ]; then
echo "❌ E2E tests failed"
exit 1
fi
echo "✅ All tests passed!"