Skip to content

Commit 22ddd26

Browse files
committed
feat: split across different cloudbuilds
1 parent 1584e07 commit 22ddd26

File tree

6 files changed

+217
-88
lines changed

6 files changed

+217
-88
lines changed

integration_test/README.md

Lines changed: 88 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ Functions and test data are automatically cleaned up:
247247
## Commands
248248

249249
### Running Tests
250+
251+
#### Local Testing
250252
```bash
251253
# Run all tests sequentially
252254
npm run test:all:sequential
@@ -266,6 +268,20 @@ npm run run-tests -- --sequential v1_firestore v1_database
266268
npm run run-tests -- --filter=v2 --exclude=auth
267269
```
268270

271+
#### Cloud Build Testing
272+
```bash
273+
# Run V1 tests in Cloud Build
274+
npm run cloudbuild:v1
275+
276+
# Run V2 tests in Cloud Build
277+
npm run cloudbuild:v2
278+
279+
# Run both V1 and V2 tests in parallel
280+
npm run cloudbuild:both
281+
# or
282+
npm run cloudbuild:all
283+
```
284+
269285
### Generate Functions Only
270286
```bash
271287
npm run generate <suite-name>
@@ -335,32 +351,84 @@ Cloud Build uses Application Default Credentials (ADC) automatically. However, t
335351
- `roles/cloudtestservice.testAdmin` - For Firebase Test Lab integration tests
336352
- `roles/firebase.admin` - For Firebase services (already included)
337353
- `roles/pubsub.publisher` - For Pub/Sub integration tests (already included)
354+
- `roles/iam.serviceAccountUser` - For Firebase Functions deployment (Service Account User)
338355

339356
**Multi-Project Setup:**
340-
Tests deploy to multiple projects (typically one for V1 tests and one for V2 tests). The Cloud Build service account needs the above permissions on **all target projects**:
357+
Tests deploy to multiple projects (V1 tests to `functions-integration-tests`, V2 tests to `functions-integration-tests-v2`). Each Cloud Build runs on its own project, so **no cross-project permissions are needed**.
341358

359+
**V1 Project Setup:**
342360
```bash
343-
# Grant permissions to each target project
344-
gcloud projects add-iam-policy-binding TARGET_PROJECT_ID \
361+
# Grant permissions to V1 project (functions-integration-tests)
362+
gcloud projects add-iam-policy-binding functions-integration-tests \
345363
--member="serviceAccount:[email protected]" \
346364
--role="roles/cloudtasks.admin"
347365
348-
gcloud projects add-iam-policy-binding TARGET_PROJECT_ID \
366+
gcloud projects add-iam-policy-binding functions-integration-tests \
349367
--member="serviceAccount:[email protected]" \
350368
--role="roles/cloudscheduler.admin"
351369
352-
gcloud projects add-iam-policy-binding TARGET_PROJECT_ID \
370+
gcloud projects add-iam-policy-binding functions-integration-tests \
353371
--member="serviceAccount:[email protected]" \
354372
--role="roles/cloudtestservice.testAdmin"
355373
356-
gcloud projects add-iam-policy-binding TARGET_PROJECT_ID \
374+
gcloud projects add-iam-policy-binding functions-integration-tests \
357375
--member="serviceAccount:[email protected]" \
358376
--role="roles/firebase.admin"
377+
378+
gcloud projects add-iam-policy-binding functions-integration-tests \
379+
--member="serviceAccount:[email protected]" \
380+
--role="roles/iam.serviceAccountUser"
359381
```
360382

361-
Replace:
362-
- `TARGET_PROJECT_ID` with each project where tests will be deployed
363-
- `CLOUD_BUILD_PROJECT_NUMBER` with the project number where Cloud Build runs
383+
**V2 Project Setup:**
384+
```bash
385+
# Grant permissions to V2 project (functions-integration-tests-v2)
386+
gcloud projects add-iam-policy-binding functions-integration-tests-v2 \
387+
--member="serviceAccount:[email protected]" \
388+
--role="roles/cloudtasks.admin"
389+
390+
gcloud projects add-iam-policy-binding functions-integration-tests-v2 \
391+
--member="serviceAccount:[email protected]" \
392+
--role="roles/cloudscheduler.admin"
393+
394+
gcloud projects add-iam-policy-binding functions-integration-tests-v2 \
395+
--member="serviceAccount:[email protected]" \
396+
--role="roles/cloudtestservice.testAdmin"
397+
398+
gcloud projects add-iam-policy-binding functions-integration-tests-v2 \
399+
--member="serviceAccount:[email protected]" \
400+
--role="roles/firebase.admin"
401+
402+
gcloud projects add-iam-policy-binding functions-integration-tests-v2 \
403+
--member="serviceAccount:[email protected]" \
404+
--role="roles/iam.serviceAccountUser"
405+
```
406+
407+
Replace `CLOUD_BUILD_PROJECT_NUMBER` with the project number where Cloud Build runs.
408+
409+
#### Running Cloud Build
410+
411+
The integration tests use **separate Cloud Build configurations** for V1 and V2 tests to avoid cross-project permission complexity:
412+
413+
**V1 Tests:**
414+
```bash
415+
# Run V1 tests on functions-integration-tests project
416+
gcloud builds submit --config=integration_test/cloudbuild-v1.yaml
417+
```
418+
419+
**V2 Tests:**
420+
```bash
421+
# Run V2 tests on functions-integration-tests-v2 project
422+
gcloud builds submit --config=integration_test/cloudbuild-v2.yaml
423+
```
424+
425+
**Both Tests (Parallel):**
426+
```bash
427+
# Run both V1 and V2 tests simultaneously
428+
gcloud builds submit --config=integration_test/cloudbuild-v1.yaml &
429+
gcloud builds submit --config=integration_test/cloudbuild-v2.yaml &
430+
wait
431+
```
364432

365433
#### Running Cloud Build with Custom Projects
366434

@@ -378,9 +446,13 @@ To use your own projects, edit the YAML configuration files:
378446
projectId: your-v2-project-id
379447
```
380448

381-
3. **Run Cloud Build**:
449+
3. **Run Cloud Build** (use the appropriate config for your target project):
382450
```bash
383-
gcloud builds submit --config=integration_test/cloudbuild.yaml
451+
# For V1 tests
452+
gcloud builds submit --config=integration_test/cloudbuild-v1.yaml
453+
454+
# For V2 tests
455+
gcloud builds submit --config=integration_test/cloudbuild-v2.yaml
384456
```
385457

386458
**Default behavior (Firebase team):**
@@ -447,6 +519,11 @@ If you see authentication errors like "Could not refresh access token" or "Permi
447519
gcloud projects add-iam-policy-binding TARGET_PROJECT_ID \
448520
--member="serviceAccount:[email protected]" \
449521
--role="roles/firebase.admin"
522+
523+
# For Service Account User (required for Functions deployment)
524+
gcloud projects add-iam-policy-binding TARGET_PROJECT_ID \
525+
--member="serviceAccount:[email protected]" \
526+
--role="roles/iam.serviceAccountUser"
450527
```
451528

452529
### Cleanup Issues
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Cloud Build configuration for Firebase Functions V1 Integration Tests
2+
# Runs all V1 test suites sequentially to avoid rate limits
3+
4+
options:
5+
machineType: 'E2_HIGHCPU_8'
6+
logging: CLOUD_LOGGING_ONLY
7+
8+
timeout: '3600s'
9+
10+
steps:
11+
# Build SDK and run all V1 test suites sequentially
12+
- name: 'node:20'
13+
id: 'build-sdk-and-test-v1'
14+
entrypoint: 'bash'
15+
args:
16+
- '-c'
17+
- |
18+
# Step 1: Build and pack the firebase-functions SDK from source
19+
echo "Building firebase-functions SDK from source..."
20+
npm ci
21+
npm run build
22+
npm pack
23+
# Move the tarball to where integration tests expect it
24+
mv firebase-functions-*.tgz integration_test/firebase-functions-local.tgz
25+
echo "SDK built and packed successfully"
26+
27+
# Step 2: Run V1 integration tests with the local SDK
28+
cd integration_test
29+
echo "Installing test dependencies..."
30+
npm ci
31+
# Install firebase-tools globally
32+
npm install -g firebase-tools
33+
# Install gcloud CLI for Cloud Tasks cleanup
34+
curl https://sdk.cloud.google.com | bash
35+
export PATH="$PATH:/root/google-cloud-sdk/bin"
36+
# Verify tools are installed
37+
firebase --version
38+
gcloud --version
39+
# V1 tests use functions-integration-tests project
40+
echo "Running V1 tests on project: functions-integration-tests"
41+
# Use Application Default Credentials (Cloud Build service account)
42+
# Run all V1 test suites sequentially
43+
node scripts/run-tests.js --sequential --filter=v1 --use-published-sdk=file:firebase-functions-local.tgz
44+
45+
# Artifacts to store
46+
artifacts:
47+
objects:
48+
location: 'gs://${PROJECT_ID}-test-results/${BUILD_ID}'
49+
paths:
50+
- 'logs/**/*.log'
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Cloud Build configuration for Firebase Functions V2 Integration Tests
2+
# Runs all V2 test suites sequentially to avoid rate limits
3+
4+
options:
5+
machineType: 'E2_HIGHCPU_8'
6+
logging: CLOUD_LOGGING_ONLY
7+
8+
timeout: '3600s'
9+
10+
steps:
11+
# Build SDK and run all V2 test suites sequentially
12+
- name: 'node:20'
13+
id: 'build-sdk-and-test-v2'
14+
entrypoint: 'bash'
15+
args:
16+
- '-c'
17+
- |
18+
# Step 1: Build and pack the firebase-functions SDK from source
19+
echo "Building firebase-functions SDK from source..."
20+
npm ci
21+
npm run build
22+
npm pack
23+
# Move the tarball to where integration tests expect it
24+
mv firebase-functions-*.tgz integration_test/firebase-functions-local.tgz
25+
echo "SDK built and packed successfully"
26+
27+
# Step 2: Run V2 integration tests with the local SDK
28+
cd integration_test
29+
echo "Installing test dependencies..."
30+
npm ci
31+
# Install firebase-tools globally
32+
npm install -g firebase-tools
33+
# Install gcloud CLI for Cloud Tasks cleanup
34+
curl https://sdk.cloud.google.com | bash
35+
export PATH="$PATH:/root/google-cloud-sdk/bin"
36+
# Verify tools are installed
37+
firebase --version
38+
gcloud --version
39+
# V2 tests use functions-integration-tests-v2 project
40+
echo "Running V2 tests on project: functions-integration-tests-v2"
41+
# Use Application Default Credentials (Cloud Build service account)
42+
# Run all V2 test suites sequentially
43+
node scripts/run-tests.js --sequential --filter=v2 --use-published-sdk=file:firebase-functions-local.tgz
44+
45+
# Artifacts to store
46+
artifacts:
47+
objects:
48+
location: 'gs://${PROJECT_ID}-test-results/${BUILD_ID}'
49+
paths:
50+
- 'logs/**/*.log'

integration_test/cloudbuild.yaml

Lines changed: 0 additions & 52 deletions
This file was deleted.

integration_test/config/v1/suites.yaml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -107,35 +107,35 @@ suites:
107107
trigger: onDelete
108108

109109
# Auth beforeCreate blocking function (must run separately)
110-
- name: v1_auth_before_create
111-
description: "V1 Auth beforeCreate blocking trigger test"
112-
version: v1
113-
service: auth
114-
functions:
115-
- name: authUserBeforeCreateTests
116-
trigger: beforeCreate
117-
collection: authBeforeCreateTests
118-
blocking: true
110+
# - name: v1_auth_before_create
111+
# description: "V1 Auth beforeCreate blocking trigger test"
112+
# version: v1
113+
# service: auth
114+
# functions:
115+
# - name: authUserBeforeCreateTests
116+
# trigger: beforeCreate
117+
# collection: authBeforeCreateTests
118+
# blocking: true
119119

120120
# Auth beforeSignIn blocking function (must run separately)
121-
- name: v1_auth_before_signin
122-
description: "V1 Auth beforeSignIn blocking trigger test"
123-
version: v1
124-
service: auth
125-
functions:
126-
- name: authUserBeforeSignInTests
127-
trigger: beforeSignIn
128-
collection: authBeforeSignInTests
129-
blocking: true
121+
# - name: v1_auth_before_signin
122+
# description: "V1 Auth beforeSignIn blocking trigger test"
123+
# version: v1
124+
# service: auth
125+
# functions:
126+
# - name: authUserBeforeSignInTests
127+
# trigger: beforeSignIn
128+
# collection: authBeforeSignInTests
129+
# blocking: true
130130

131131
# Cloud Tasks triggers
132-
- name: v1_tasks
133-
description: "V1 Cloud Tasks trigger tests"
134-
version: v1
135-
service: tasks
136-
functions:
137-
- name: tasksOnDispatchTests
138-
trigger: onDispatch
132+
# - name: v1_tasks
133+
# description: "V1 Cloud Tasks trigger tests"
134+
# version: v1
135+
# service: tasks
136+
# functions:
137+
# - name: tasksOnDispatchTests
138+
# trigger: onDispatch
139139

140140
# Remote Config triggers
141141
- name: v1_remoteconfig

integration_test/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
"test:all:sequential": "node scripts/run-tests.js --sequential",
1818
"test:v1:auth-before-create": "node scripts/run-tests.js v1_auth_before_create",
1919
"test:v1:auth-before-signin": "node scripts/run-tests.js v1_auth_before_signin",
20+
"cloudbuild:v1": "gcloud builds submit --config=cloudbuild-v1.yaml",
21+
"cloudbuild:v2": "gcloud builds submit --config=cloudbuild-v2.yaml",
22+
"cloudbuild:both": "gcloud builds submit --config=cloudbuild-v1.yaml & gcloud builds submit --config=cloudbuild-v2.yaml & wait",
23+
"cloudbuild:all": "npm run cloudbuild:both",
2024
"cleanup": "./scripts/cleanup-suite.sh",
2125
"cleanup:list": "./scripts/cleanup-suite.sh --list-artifacts",
2226
"clean": "rm -rf generated/*",

0 commit comments

Comments
 (0)