Skip to content

Commit a7de0aa

Browse files
committed
Merge branch 'master' of https://github.com/firebase/firebase-functions into @invertase/integration-tests
2 parents e67996b + 3577d9b commit a7de0aa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+8697
-2923
lines changed

.eslintignore

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

.eslintrc.js

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

.github/workflows/docs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- uses: actions/checkout@v4
1313
- uses: actions/setup-node@v4
1414
with:
15-
node-version: "20"
15+
node-version: "24"
1616
- name: Cache npm
1717
uses: actions/cache@v4
1818
with:

.github/workflows/postmerge.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- uses: actions/checkout@v3
3131
- uses: actions/setup-node@v3
3232
with:
33-
node-version: 18
33+
node-version: 24
3434

3535
- uses: google-github-actions/auth@v0
3636
with:

.github/workflows/test.yaml

Lines changed: 61 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ on:
44
- pull_request
55
- push
66

7+
permissions:
8+
contents: read
9+
710
env:
811
CI: true
912

@@ -14,17 +17,36 @@ jobs:
1417
strategy:
1518
matrix:
1619
node-version:
17-
- 18.x
20+
- 22.x
1821
steps:
19-
- uses: actions/checkout@v3
20-
with:
21-
fetch-depth: 0
22-
- uses: actions/setup-node@v3
22+
- uses: actions/checkout@v4
23+
- uses: actions/setup-node@v4
2324
with:
2425
node-version: ${{ matrix.node-version }}
2526
cache: npm
2627
- run: npm ci
2728
- run: npm run lint
29+
30+
build:
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v4
34+
- uses: actions/setup-node@v4
35+
with:
36+
node-version: 22.x
37+
cache: npm
38+
- run: npm ci
39+
- run: npm run build
40+
- run: npm pack
41+
- uses: actions/upload-artifact@v4
42+
with:
43+
name: lib
44+
path: lib/
45+
- uses: actions/upload-artifact@v4
46+
with:
47+
name: tarball
48+
path: firebase-functions-*.tgz
49+
2850
unit:
2951
runs-on: ubuntu-latest
3052
strategy:
@@ -33,51 +55,58 @@ jobs:
3355
- 18.x
3456
- 20.x
3557
- 22.x
58+
- 24.x
3659
steps:
37-
- uses: actions/checkout@v1
38-
- uses: actions/setup-node@v1
60+
- uses: actions/checkout@v4
61+
- uses: actions/setup-node@v4
3962
with:
4063
node-version: ${{ matrix.node-version }}
41-
- name: Cache npm
42-
uses: actions/cache@v4
43-
with:
44-
path: ~/.npm
45-
key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
64+
cache: npm
4665
- run: npm ci
4766
- run: npm run test
67+
4868
integration:
49-
needs: "unit"
69+
needs: build
5070
runs-on: ubuntu-latest
5171
strategy:
5272
matrix:
5373
node-version:
5474
- 18.x
5575
- 20.x
5676
- 22.x
77+
- 24.x
5778
steps:
58-
- uses: actions/checkout@v1
59-
- uses: actions/setup-node@v1
79+
- uses: actions/checkout@v4
80+
- uses: actions/setup-node@v4
6081
with:
6182
node-version: ${{ matrix.node-version }}
62-
- name: Cache npm
63-
uses: actions/cache@v4
64-
with:
65-
path: ~/.npm
66-
key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
83+
cache: npm
6784
- run: npm ci
85+
- uses: actions/download-artifact@v4
86+
with:
87+
name: lib
88+
path: lib
6889
- run: npm run test:bin
69-
cloud-build-integration:
70-
needs: "unit"
90+
env:
91+
SKIP_BUILD: true
92+
93+
packaging:
94+
needs: build
7195
runs-on: ubuntu-latest
96+
strategy:
97+
matrix:
98+
node-version:
99+
- 18.x
100+
- 20.x
101+
- 22.x
102+
- 24.x
72103
steps:
73-
- uses: actions/checkout@v1
74-
- uses: google-github-actions/auth@v2
104+
- uses: actions/checkout@v4
105+
- uses: actions/setup-node@v4
75106
with:
76-
credentials_json: "${{ secrets.CF3_INTEGRATION_TEST_GOOGLE_CREDENTIALS }}"
77-
create_credentials_file: true
78-
- name: "Run Cloud Build Integration Tests"
79-
run: |
80-
cd integration_test
81-
PROJECT_ID=cf3-integration-tests-v2-qa gcloud builds submit --config=cloudbuild-all.yaml --project=cf3-integration-tests-v2-qa
82-
env:
83-
PROJECT_ID: ${{ secrets.PROJECT_ID }}
107+
node-version: ${{ matrix.node-version }}
108+
- uses: actions/download-artifact@v4
109+
with:
110+
name: tarball
111+
path: .
112+
- run: chmod +x ./scripts/test-packaging.sh && ./scripts/test-packaging.sh firebase-functions-*.tgz

.guides/config.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"description": "Use this library to build serverless functions for event triggers and HTTP using Cloud Functions for Firebase",
3+
"mcpServers": {
4+
"firebase": {
5+
"command": "npx",
6+
"args": ["-y", "firebase-tools@latest", "experimental:mcp"]
7+
}
8+
}
9+
}

.guides/setup.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Cloud Functions for Firebase setup guide
2+
3+
This guide provides a step-by-step process for setting up Cloud Functions, tailored for coding agents.
4+
5+
## 1. Create a 2nd-gen HTTP function
6+
7+
Replace the contents of `src/index.ts` (or `index.js`) with the following code to create a simple, modern v2 HTTP endpoint.
8+
9+
```typescript
10+
import { onRequest } from "firebase-functions/https";
11+
import { onDocumentCreated } from "firebase-functions/firestore";
12+
import * as logger from "firebase-functions/logger";
13+
import { defineString, defineInt } from "firebase-functions/params";
14+
15+
// Configurable parameters
16+
const scaleLimit = defineInt("MAX_INSTANCES", { default: 1 });
17+
const greeting = defineString("GREETING", { default: "Hello" });
18+
19+
export const helloWorld = onRequest({ maxInstances: scaleLimit }, async (request, response) => {
20+
logger.info("Request received!", request);
21+
response.send(`${greeting.value()} from Firebase!`);
22+
});
23+
24+
export const newDoc = onDocumentCreated(
25+
{ maxInstances: scaleLimit },
26+
"/words/{wordId}",
27+
async (event) => {
28+
logger.info("New word!", event.data.data());
29+
}
30+
);
31+
```
32+
33+
**Key points for the agent:**
34+
35+
- Use `logger` for structured logging.
36+
- Use `defineString`, `defineInt`, `defineSecret` for environment configuration instead of `functions.config()`.
37+
- Recommend a `maxInstances` setting of 1 for all functions until correct behavior can be verified.
38+
39+
## 2. Build TypeScript
40+
41+
Compile your TypeScript code to JavaScript.
42+
43+
```bash
44+
npm run build
45+
```
46+
47+
## 3. Local Development and Testing
48+
49+
Use the Firebase Emulators to test your function locally before deploying.
50+
51+
A human should run the following command in a separate terminal window to start the emulators:
52+
53+
```bash
54+
# Start the functions emulator
55+
firebase emulators:start --only functions
56+
```
57+
58+
A human can then interact with the function at the local URL provided by the emulator.
59+
60+
## 4. Deploy to Firebase
61+
62+
Once testing is complete, deploy the function to your Firebase project.
63+
64+
```bash
65+
# Deploy only the functions
66+
firebase deploy --only functions
67+
```
68+
69+
The agent will be prompted to set any parameters defined with `defineString` or other `define` functions that do not have a default value.

0 commit comments

Comments
 (0)