Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
12b9257
adds listServices fn and adds trigger to endpointFromService fn
brittanycho Oct 31, 2025
0a30722
updates functions-list to use listServices to use cloud run api instead
brittanycho Oct 31, 2025
df189ee
adds listServices tests
brittanycho Oct 31, 2025
66cf473
fix linting errors
brittanycho Oct 31, 2025
3af536c
Merge branch 'master' into fr/cloud-run-fns-list
brittanycho Oct 31, 2025
f6ef8c0
Update src/commands/functions-list.ts
brittanycho Nov 3, 2025
d9fd843
Update src/gcp/runv2.ts
brittanycho Nov 3, 2025
84725cf
corrects import error
brittanycho Nov 3, 2025
6a45457
add relevant labelSelectors
brittanycho Nov 4, 2025
9cedf12
adding v1 fns in
brittanycho Nov 5, 2025
481d02f
adding in deduplication
brittanycho Nov 5, 2025
0362303
Merge branch 'master' into fr/cloud-run-fns-list
brittanycho Nov 5, 2025
d4ed0f9
Update src/gcp/runv2.ts
brittanycho Nov 5, 2025
2de426f
linting
brittanycho Nov 5, 2025
7cb75d8
Merge branch 'master' into fr/cloud-run-fns-list
brittanycho Nov 6, 2025
4d06024
Merge branch 'master' into fr/cloud-run-fns-list
brittanycho Nov 8, 2025
3712d0c
Merge branch 'master' into fr/cloud-run-fns-list
brittanycho Nov 10, 2025
d1986ac
follow-up on feedback: move parts of implementation to backend.ts, ad…
brittanycho Nov 11, 2025
8f1c06d
correct lint error
brittanycho Nov 11, 2025
1cef2a6
Update src/commands/functions-list.ts
brittanycho Nov 11, 2025
0de7514
addressing feedback on parsing
brittanycho Nov 11, 2025
66e5d6f
feat: upgrade functions::list to use Cloud Run API and bump version t…
brittanycho Nov 11, 2025
c1f2e7b
adjust how v2 functions are being called from listServices
brittanycho Nov 11, 2025
bd8ea09
add updated tests to backend.spec.ts
brittanycho Nov 11, 2025
86ef3f6
addresses feedback from code review
brittanycho Nov 12, 2025
9287590
updates changelog
brittanycho Nov 12, 2025
896d3a1
Merge branch 'master' into fr/cloud-run-fns-list
brittanycho Nov 12, 2025
a38b669
Merge branch 'master' into fr/cloud-run-fns-list
brittanycho Nov 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- Upgraded functions::list command to use cloud run api for v2 functions (#9425)
- [Added] support for new google-genai plugin during `init genkit` (#8957)
- Updated to v2.17.1 of the Data Connect emulator, which fixes an admin SDK bug for operation without argument #9449 (#9454).
45 changes: 36 additions & 9 deletions src/commands/functions-list.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,65 @@
import { Command } from "../command";
import * as args from "../deploy/functions/args";
import { needProjectId } from "../projectUtils";
import { Options } from "../options";
import { requirePermissions } from "../requirePermissions";
import * as backend from "../deploy/functions/backend";
import { logger } from "../logger";
import * as Table from "cli-table3";
import { Options } from "../options";
import { FunctionsPlatform } from "../deploy/functions/backend";

type PLATFORM_DISPLAY_NAME = "v1" | "v2" | "run";
const PLATFORM_TO_DISPLAY_NAME: Record<FunctionsPlatform, PLATFORM_DISPLAY_NAME> = {
gcfv1: "v1",
gcfv2: "v2",
run: "run",
};

export const command = new Command("functions:list")
.description("list all deployed functions in your Firebase project")
.before(requirePermissions, ["cloudfunctions.functions.list"])
.before(requirePermissions, ["cloudfunctions.functions.list", "run.services.list"])
.action(async (options: Options) => {
const projectId = needProjectId(options);
const context = {
projectId: needProjectId(options),
projectId,
} as args.Context;
const existing = await backend.existingBackend(context);
const endpointsList = backend.allEndpoints(existing).sort(backend.compareFunctions);

let endpoints: backend.Endpoint[] = [];
try {
const existing = await backend.existingBackend(context);
endpoints = backend.allEndpoints(existing);
} catch (err: any) {

Check warning on line 31 in src/commands/functions-list.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
logger.debug(`Failed to list functions:`, err);
logger.warn(
`Failed to list functions: ${err.message}. Ensure you have the Cloud Functions and Cloud Run APIs enabled and the necessary permissions.`,

Check warning on line 34 in src/commands/functions-list.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .message on an `any` value

Check warning on line 34 in src/commands/functions-list.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "any" of template literal expression
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit* This error message could be more helpful. For example, can it link to the links to enable the API or check the permission?

I might actually remove it all together and print out the error message for the first cut.

);
}

endpoints.sort(backend.compareFunctions);

if (endpoints.length === 0) {
logger.info(`No functions found in project ${projectId}.`);
return [];
}

const table = new Table({

Check warning on line 45 in src/commands/functions-list.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
head: ["Function", "Version", "Trigger", "Location", "Memory", "Runtime"],
style: { head: ["yellow"] },
});
for (const endpoint of endpointsList) {
}) as any;

Check warning on line 48 in src/commands/functions-list.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type

for (const endpoint of endpoints) {
const trigger = backend.endpointTriggerType(endpoint);
const availableMemoryMb = endpoint.availableMemoryMb || "---";
const entry = [
endpoint.id,
endpoint.platform === "gcfv2" ? "v2" : "v1",
PLATFORM_TO_DISPLAY_NAME[endpoint.platform] || "v1",
trigger,
endpoint.region,
availableMemoryMb,
endpoint.runtime,
];
table.push(entry);

Check warning on line 61 in src/commands/functions-list.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe call of an `any` typed value

Check warning on line 61 in src/commands/functions-list.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .push on an `any` value
}
logger.info(table.toString());

Check warning on line 63 in src/commands/functions-list.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe call of an `any` typed value

Check warning on line 63 in src/commands/functions-list.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .toString on an `any` value

Check warning on line 63 in src/commands/functions-list.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `Error`
return endpointsList;
return endpoints;
});
1 change: 0 additions & 1 deletion src/deploy/functions/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export interface Context {
existingBackendPromise?: Promise<backend.Backend>;
unreachableRegions?: {
gcfV1: string[];
gcfV2: string[];
run: string[];
};

Expand Down
131 changes: 63 additions & 68 deletions src/deploy/functions/backend.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import * as backend from "./backend";
import * as gcf from "../../gcp/cloudfunctions";
import * as gcfV2 from "../../gcp/cloudfunctionsv2";
import * as runv2 from "../../gcp/runv2";
import * as utils from "../../utils";
import * as projectConfig from "../../functions/projectConfig";

Expand Down Expand Up @@ -54,7 +55,7 @@
},
};
const GCF_URL = "https://region-project.cloudfunctions.net/id";
const HAVE_CLOUD_FUNCTION_V2: gcfV2.OutputCloudFunction = {

Check failure on line 58 in src/deploy/functions/backend.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

'HAVE_CLOUD_FUNCTION_V2' is assigned a value but never used

Check failure on line 58 in src/deploy/functions/backend.spec.ts

View workflow job for this annotation

GitHub Actions / unit (20)

'HAVE_CLOUD_FUNCTION_V2' is assigned a value but never used

Check failure on line 58 in src/deploy/functions/backend.spec.ts

View workflow job for this annotation

GitHub Actions / unit (22)

'HAVE_CLOUD_FUNCTION_V2' is assigned a value but never used

Check failure on line 58 in src/deploy/functions/backend.spec.ts

View workflow job for this annotation

GitHub Actions / unit (20)

'HAVE_CLOUD_FUNCTION_V2' is assigned a value but never used

Check failure on line 58 in src/deploy/functions/backend.spec.ts

View workflow job for this annotation

GitHub Actions / unit (22)

'HAVE_CLOUD_FUNCTION_V2' is assigned a value but never used
...CLOUD_FUNCTION_V2,
serviceConfig: {
service: "service",
Expand Down Expand Up @@ -126,17 +127,20 @@
describe("existing backend", () => {
let listAllFunctions: sinon.SinonStub;
let listAllFunctionsV2: sinon.SinonStub;
let listServices: sinon.SinonStub;
let logLabeledWarning: sinon.SinonSpy;

beforeEach(() => {
listAllFunctions = sinon.stub(gcf, "listAllFunctions").rejects("Unexpected call");
listAllFunctionsV2 = sinon.stub(gcfV2, "listAllFunctions").rejects("Unexpected v2 call");
listServices = sinon.stub(runv2, "listServices").resolves([]);
logLabeledWarning = sinon.spy(utils, "logLabeledWarning");
});

afterEach(() => {
listAllFunctions.restore();
listAllFunctionsV2.restore();
listServices.restore();
logLabeledWarning.restore();
});

Expand All @@ -163,18 +167,14 @@
],
unreachable: ["region"],
});
listAllFunctionsV2.onFirstCall().resolves({
functions: [],
unreachable: [],
});
const firstBackend = await backend.existingBackend(context);

const secondBackend = await backend.existingBackend(context);
await backend.checkAvailability(context, backend.empty());

expect(firstBackend).to.deep.equal(secondBackend);
expect(listAllFunctions).to.be.calledOnce;
expect(listAllFunctionsV2).to.be.calledOnce;
expect(listServices).to.be.calledOnce;
});

it("should translate functions", async () => {
Expand All @@ -187,10 +187,7 @@
],
unreachable: [],
});
listAllFunctionsV2.onFirstCall().resolves({
functions: [],
unreachable: [],
});
listServices.resolves([]);
const have = await backend.existingBackend(newContext());

expect(have).to.deep.equal(backend.of({ ...ENDPOINT, httpsTrigger: {} }));
Expand All @@ -201,7 +198,7 @@
functions: [],
unreachable: [],
});
listAllFunctionsV2.throws(
listServices.throws(

Check failure on line 201 in src/deploy/functions/backend.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Replace `⏎··········new·FirebaseError("HTTP·Error:·500,·Internal·Error",·{·status:·500·}),⏎········` with `new·FirebaseError("HTTP·Error:·500,·Internal·Error",·{·status:·500·})`

Check failure on line 201 in src/deploy/functions/backend.spec.ts

View workflow job for this annotation

GitHub Actions / unit (20)

Replace `⏎··········new·FirebaseError("HTTP·Error:·500,·Internal·Error",·{·status:·500·}),⏎········` with `new·FirebaseError("HTTP·Error:·500,·Internal·Error",·{·status:·500·})`

Check failure on line 201 in src/deploy/functions/backend.spec.ts

View workflow job for this annotation

GitHub Actions / unit (22)

Replace `⏎··········new·FirebaseError("HTTP·Error:·500,·Internal·Error",·{·status:·500·}),⏎········` with `new·FirebaseError("HTTP·Error:·500,·Internal·Error",·{·status:·500·})`

Check failure on line 201 in src/deploy/functions/backend.spec.ts

View workflow job for this annotation

GitHub Actions / unit (20)

Replace `⏎··········new·FirebaseError("HTTP·Error:·500,·Internal·Error",·{·status:·500·}),⏎········` with `new·FirebaseError("HTTP·Error:·500,·Internal·Error",·{·status:·500·})`

Check failure on line 201 in src/deploy/functions/backend.spec.ts

View workflow job for this annotation

GitHub Actions / unit (22)

Replace `⏎··········new·FirebaseError("HTTP·Error:·500,·Internal·Error",·{·status:·500·}),⏎········` with `new·FirebaseError("HTTP·Error:·500,·Internal·Error",·{·status:·500·})`
new FirebaseError("HTTP Error: 500, Internal Error", { status: 500 }),
);

Expand All @@ -220,7 +217,7 @@
],
unreachable: [],
});
listAllFunctionsV2.throws(
listServices.throws(
new FirebaseError("HTTP Error: 404, Method not found", { status: 404 }),
);

Expand Down Expand Up @@ -267,24 +264,10 @@
functions: [],
unreachable: [],
});
listAllFunctionsV2.onFirstCall().resolves({
functions: [HAVE_CLOUD_FUNCTION_V2],
unreachable: [],
});
listServices.onFirstCall().resolves([]);
const have = await backend.existingBackend(newContext());

expect(have).to.deep.equal(
backend.of({
...ENDPOINT,
platform: "gcfv2",
concurrency: 80,
cpu: 1,
httpsTrigger: {},
runServiceId: HAVE_CLOUD_FUNCTION_V2.serviceConfig?.service,
source: HAVE_CLOUD_FUNCTION_V2.buildConfig.source,
uri: HAVE_CLOUD_FUNCTION_V2.serviceConfig?.uri,
}),
);
expect(have).to.deep.equal(backend.empty());
});

it("should deduce features of scheduled functions", async () => {
Expand All @@ -303,10 +286,7 @@
],
unreachable: [],
});
listAllFunctionsV2.onFirstCall().resolves({
functions: [],
unreachable: [],
});
listServices.resolves([]);
const have = await backend.existingBackend(newContext());
const want = backend.of({
...ENDPOINT,
Expand All @@ -318,6 +298,19 @@

expect(have).to.deep.equal(want);
});

it("should list services with correct filter", async () => {
listAllFunctions.onFirstCall().resolves({
functions: [],
unreachable: [],
});
listServices.resolves([]);
const context = { projectId: "project" } as args.Context;

await backend.existingBackend(context);

expect(listServices).to.have.been.calledWith("project");
});
});

describe("checkAvailability", () => {
Expand All @@ -333,15 +326,12 @@
functions: [],
unreachable: [],
});
listAllFunctionsV2.onFirstCall().resolves({
functions: [],
unreachable: [],
});
listServices.resolves([]);

await backend.checkAvailability(newContext(), backend.empty());

expect(listAllFunctions).to.have.been.called;
expect(listAllFunctionsV2).to.have.been.called;
expect(listServices).to.have.been.called;
expect(logLabeledWarning).to.not.have.been.called;
});

Expand All @@ -350,15 +340,12 @@
functions: [],
unreachable: ["region"],
});
listAllFunctionsV2.resolves({
functions: [],
unreachable: [],
});
listServices.resolves([]);

await backend.checkAvailability(newContext(), backend.empty());

expect(listAllFunctions).to.have.been.called;
expect(listAllFunctionsV2).to.have.been.called;
expect(listServices).to.have.been.called;
expect(logLabeledWarning).to.have.been.called;
});

Expand All @@ -367,15 +354,20 @@
functions: [],
unreachable: [],
});
listAllFunctionsV2.onFirstCall().resolves({
functions: [],
unreachable: ["region"],
});
listServices.onFirstCall().resolves([]);
// Simulate unreachable run/v2 regions by manually setting context
const context = newContext();

await backend.checkAvailability(newContext(), backend.empty());
await backend.existingBackend(context);

Check failure on line 362 in src/deploy/functions/backend.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Delete `········`

Check failure on line 362 in src/deploy/functions/backend.spec.ts

View workflow job for this annotation

GitHub Actions / unit (20)

Delete `········`

Check failure on line 362 in src/deploy/functions/backend.spec.ts

View workflow job for this annotation

GitHub Actions / unit (22)

Delete `········`

Check failure on line 362 in src/deploy/functions/backend.spec.ts

View workflow job for this annotation

GitHub Actions / unit (20)

Delete `········`

Check failure on line 362 in src/deploy/functions/backend.spec.ts

View workflow job for this annotation

GitHub Actions / unit (22)

Delete `········`
// Manually set the run region as unreachable to test the warning
if (!context.unreachableRegions) {
context.unreachableRegions = { gcfV1: [], run: [] };
}
context.unreachableRegions.run = ["region"];

await backend.checkAvailability(context, backend.empty());

expect(listAllFunctions).to.have.been.called;
expect(listAllFunctionsV2).to.have.been.called;
expect(logLabeledWarning).to.have.been.called;
});

Expand All @@ -384,10 +376,7 @@
functions: [],
unreachable: ["region"],
});
listAllFunctionsV2.resolves({
functions: [],
unreachable: [],
});
listServices.resolves([]);
const want = backend.of({ ...ENDPOINT, httpsTrigger: {} });
await expect(backend.checkAvailability(newContext(), want)).to.eventually.be.rejectedWith(
FirebaseError,
Expand All @@ -400,17 +389,22 @@
functions: [],
unreachable: [],
});
listAllFunctionsV2.onFirstCall().resolves({
functions: [],
unreachable: ["region"],
});
listServices.onFirstCall().resolves([]);
const want: backend.Backend = backend.of({
...ENDPOINT,
platform: "gcfv2",
httpsTrigger: {},
});

await expect(backend.checkAvailability(newContext(), want)).to.eventually.be.rejectedWith(
// Manually set the run region as unreachable to simulate unavailability
const context = newContext();
await backend.existingBackend(context);
if (!context.unreachableRegions) {
context.unreachableRegions = { gcfV1: [], run: [] };
}
context.unreachableRegions.run = ["region"];

await expect(backend.checkAvailability(context, want)).to.eventually.be.rejectedWith(
FirebaseError,
/The following Cloud Functions V2 regions are currently unreachable:/,
);
Expand All @@ -421,16 +415,20 @@
functions: [],
unreachable: [],
});
listAllFunctionsV2.onFirstCall().resolves({
functions: [],
unreachable: ["us-central1"],
});
listServices.resolves([]);

const want = backend.of({ ...ENDPOINT, httpsTrigger: {} });
await backend.checkAvailability(newContext(), want);
const context = newContext();
await backend.existingBackend(context);
if (!context.unreachableRegions) {
context.unreachableRegions = { gcfV1: [], run: [] };
}
context.unreachableRegions.run = ["us-central1"];

await backend.checkAvailability(context, want);

expect(listAllFunctions).to.have.been.called;
expect(listAllFunctionsV2).to.have.been.called;
expect(listServices).to.have.been.called;
expect(logLabeledWarning).to.have.been.called;
});

Expand All @@ -439,16 +437,13 @@
functions: [],
unreachable: ["us-central1"],
});
listAllFunctionsV2.onFirstCall().resolves({
functions: [],
unreachable: [],
});
listServices.resolves([]);

const want: backend.Backend = backend.of({ ...ENDPOINT, httpsTrigger: {} });
await backend.checkAvailability(newContext(), want);

expect(listAllFunctions).to.have.been.called;
expect(listAllFunctionsV2).to.have.been.called;
expect(listServices).to.have.been.called;
expect(logLabeledWarning).to.have.been.called;
});
});
Expand Down
Loading
Loading