Skip to content

Commit

Permalink
Merge branch 'jh-import-export-vsce' of github.com:firebase/firebase-…
Browse files Browse the repository at this point in the history
…tools into jh-import-export-vsce
  • Loading branch information
joehan committed Jan 2, 2025
2 parents 7f8800f + 9f41ee8 commit 4b5d2c6
Show file tree
Hide file tree
Showing 35 changed files with 346 additions and 126 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/node-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ jobs:
distribution: temurin

- uses: actions/checkout@v4
- name: Setup Chrome
uses: browser-actions/[email protected]
with:
install-dependencies: true
install-chromedriver: true
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
Expand Down Expand Up @@ -146,7 +151,7 @@ jobs:
integration:
needs: unit
if: contains(fromJSON('["push", "merge_group"]'), github.event_name)
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

env:
FIREBASE_EMULATORS_PATH: ${{ github.workspace }}/emulator-cache
Expand Down Expand Up @@ -184,6 +189,11 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: npm
cache-dependency-path: npm-shrinkwrap.json
- name: Setup Chrome
uses: browser-actions/[email protected]
with:
install-dependencies: true
install-chromedriver: true
- name: Cache firebase emulators
uses: actions/cache@v3
with:
Expand Down
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
- Changes default CF3 runtime to nodejs22 (#8037)
- Fixed an issue where `--import` would error for the Data Connect emulator if `dataDir` was also set.
5 changes: 5 additions & 0 deletions firebase-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

- [Added] Added support for emulator import/export.

## 0.12.0

- Updated internal firebase-tools dependency to 13.29.1
- [Fixed] Fixed firebase binary detection for analytics

## 0.11.1

- [Fixed] Fixed IDX analytics issue
Expand Down
4 changes: 2 additions & 2 deletions firebase-vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion firebase-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"publisher": "GoogleCloudTools",
"icon": "./resources/firebase_dataconnect_logo.png",
"description": "Firebase Data Connect for VSCode",
"version": "0.11.1",
"version": "0.12.0",
"engines": {
"vscode": "^1.69.0"
},
Expand Down
7 changes: 7 additions & 0 deletions firebase-vscode/src/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import vscode, { env, TelemetryLogger, TelemetrySender } from "vscode";
import { pluginLogger } from "./logger-wrapper";
import { AnalyticsParams, trackVSCode } from "../../src/track";
import { env as monospaceEnv } from "../src/core/env";
import { getSettings } from "./utils/settings";

export const IDX_METRIC_NOTICE = `
When you use the Firebase Data Connect Extension, Google collects telemetry data such as usage statistics, error metrics, and crash reports. Telemetry helps us better understand how the Firebase Extension is performing, where improvements need to be made, and how features are being used. Firebase uses this data, consistent with our [Google Privacy Policy](https://policies.google.com/privacy?hl=en-US), to provide, improve, and develop Firebase products and services.
Expand Down Expand Up @@ -184,6 +185,7 @@ class GA4TelemetrySender implements TelemetrySender {
}
}
data = { ...data };
data = addFirebaseBinaryMetadata(data);
if (!this.hasSentData) {
trackVSCode(
DATA_CONNECT_EVENT_NAME.EXTENSION_USED,
Expand All @@ -199,3 +201,8 @@ class GA4TelemetrySender implements TelemetrySender {
// TODO: Sanatize error messages for user data
}
}

function addFirebaseBinaryMetadata(data?: Record<string, any> | undefined) {
const settings = getSettings();
return { ...data, binary_kind: settings.firebaseBinaryKind };
}
8 changes: 2 additions & 6 deletions firebase-vscode/src/data-connect/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,12 @@ export function registerFdcDeploy(
);

const deployAllCmd = vscode.commands.registerCommand("fdc.deploy-all", () => {
analyticsLogger.logger.logUsage(DATA_CONNECT_EVENT_NAME.DEPLOY_ALL, {
firebase_binary_kind: settings.firebaseBinaryKind,
});
analyticsLogger.logger.logUsage(DATA_CONNECT_EVENT_NAME.DEPLOY_ALL);
deploySpy.call(`${settings.firebasePath} deploy --only dataconnect`);
});

const deployCmd = vscode.commands.registerCommand("fdc.deploy", async () => {
analyticsLogger.logger.logUsage(DATA_CONNECT_EVENT_NAME.DEPLOY_INDIVIDUAL, {
firebase_binary_kind: settings.firebaseBinaryKind,
});
analyticsLogger.logger.logUsage(DATA_CONNECT_EVENT_NAME.DEPLOY_INDIVIDUAL);
const configs = await firstWhereDefined(dataConnectConfigs).then(
(c) => c.requireValue,
);
Expand Down
4 changes: 1 addition & 3 deletions firebase-vscode/src/data-connect/sdk-generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ export function registerFdcSdkGeneration(
const initSdkCmd = vscode.commands.registerCommand(
"fdc.init-sdk",
(args: { appFolder: string }) => {
analyticsLogger.logger.logUsage(DATA_CONNECT_EVENT_NAME.INIT_SDK_CLI, {
firebase_binary_kind: settings.firebaseBinaryKind,
});
analyticsLogger.logger.logUsage(DATA_CONNECT_EVENT_NAME.INIT_SDK_CLI);
// Lets do it from the right directory
setTerminalEnvVars(FDC_APP_FOLDER, args.appFolder);
runCommand(`${settings.firebasePath} init dataconnect:sdk`);
Expand Down
13 changes: 4 additions & 9 deletions firebase-vscode/src/data-connect/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ export function registerTerminalTasks(
const settings = getSettings();

const loginTaskBroker = broker.on("executeLogin", () => {
analyticsLogger.logger.logUsage(DATA_CONNECT_EVENT_NAME.IDX_LOGIN, {
firebase_binary_kind: settings.firebaseBinaryKind,
});
analyticsLogger.logger.logUsage(DATA_CONNECT_EVENT_NAME.IDX_LOGIN);
runTerminalTask(
"firebase login",
`${settings.firebasePath} login --no-localhost`,
Expand All @@ -86,19 +84,16 @@ export function registerTerminalTasks(
});

const startEmulatorsTaskBroker = broker.on("runStartEmulators", () => {
analyticsLogger.logger.logUsage(DATA_CONNECT_EVENT_NAME.START_EMULATORS, {
firebase_binary_kind: settings.firebaseBinaryKind,
});
analyticsLogger.logger.logUsage(DATA_CONNECT_EVENT_NAME.START_EMULATORS);

let cmd = `${settings.firebasePath} emulators:start --project ${currentProjectId.value}`;
console.log(settings);

if (settings.importPath) {
cmd += ` --import ${settings.importPath}`;
}
if (settings.exportOnExit) {
cmd += ` --export-on-exit ${settings.exportPath}`;
}
console.log(cmd);
// TODO: optional debug mode
runTerminalTask(
"firebase emulators",
cmd,
Expand Down
51 changes: 30 additions & 21 deletions firebase-vscode/src/logger-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,37 @@ export function logSetup() {

// Log to file
// Only log to file if firebase.debug extension setting is true.
// Re-implement file logger call from ../../src/bin/firebase.ts to not bring
// in the entire firebase.ts file
const rootFolders = getRootFolders();
// Default to a central path, but write files to a local path if we're in a Firebase directory.
let filePath = path.join(os.homedir(), ".cache", "firebase", "logs", "vsce-debug.log");
if (fs.existsSync(path.join(rootFolders[0], "firebase.json"))) {
filePath = path.join(rootFolders[0], ".firebase", "logs", "vsce-debug.log");
}
pluginLogger.info("Logging to path", filePath);
cliLogger.add(
new transports.File({
level: "debug",
filename: filePath,
format: format.printf((info) => {
const segments = [info.message, ...(info[SPLAT] || [])].map(
tryStringify,
);
return `[${info.level}] ${stripVTControlCharacters(segments.join(" "))}`;
}),
// Re-implement file logger call from ../../src/bin/firebase.ts to not bring
// in the entire firebase.ts file
const rootFolders = getRootFolders();
// Default to a central path, but write files to a local path if we're in a Firebase directory.
let filePath = path.join(
os.homedir(),
".cache",
"firebase",
"logs",
"vsce-debug.log",
);
if (
rootFolders.length > 0 &&
fs.existsSync(path.join(rootFolders[0], "firebase.json"))
) {
filePath = path.join(rootFolders[0], ".firebase", "logs", "vsce-debug.log");
}
pluginLogger.info("Logging to path", filePath);
cliLogger.add(
new transports.File({
level: "debug",
filename: filePath,
format: format.printf((info) => {
const segments = [info.message, ...(info[SPLAT] || [])].map(
tryStringify,
);
return `[${info.level}] ${stripVTControlCharacters(segments.join(" "))}`;
}),
);
cliLogger.add(new VSCodeOutputTransport({ level: "info" }));
}),
);
cliLogger.add(new VSCodeOutputTransport({ level: "info" }));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firebase-tools",
"version": "13.28.0",
"version": "13.29.1",
"description": "Command-Line Interface for Firebase",
"main": "./lib/index.js",
"bin": {
Expand Down
9 changes: 9 additions & 0 deletions scripts/storage-emulator-integration/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@ firebase setup:emulators:storage

mocha scripts/storage-emulator-integration/internal/tests.ts

# Brief sleep between tests to make sure emulators shut down fully.
sleep 5

mocha scripts/storage-emulator-integration/rules/*.test.ts

sleep 5

mocha scripts/storage-emulator-integration/import/tests.ts

sleep 5

mocha scripts/storage-emulator-integration/multiple-targets/tests.ts

sleep 5

mocha scripts/storage-emulator-integration/conformance/*.test.ts
2 changes: 1 addition & 1 deletion src/commands/appdistribution-distribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const command = new Command("appdistribution:distribute <release-binary-f
const testDevices = parseTestDevices(options.testDevices, options.testDevicesFile);
if (testCases.length && (options.testUsernameResource || options.testPasswordResource)) {
throw new FirebaseError(
"Password and username resource names are not supported for the AI testing agent.",
"Password and username resource names are not supported for the testing agent.",
);
}
const loginCredential = getLoginCredential({
Expand Down
3 changes: 3 additions & 0 deletions src/dataconnect/fileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ function validateConnectorYaml(unvalidated: any): ConnectorYaml {
}

export async function readGQLFiles(sourceDir: string): Promise<File[]> {
if (!fs.existsSync(sourceDir)) {
return [];
}
const files = await fs.readdir(sourceDir);
// TODO: Handle files in subdirectories such as `foo/a.gql` and `bar/baz/b.gql`.
return files
Expand Down
17 changes: 12 additions & 5 deletions src/dataconnect/freeTrial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,40 @@ export async function getFreeTrialInstanceId(projectId: string): Promise<string
return instances.find((i) => i.settings.userLabels?.["firebase-data-connect"] === "ft")?.name;
}

export async function isFreeTrialError(err: any, projectId: string): Promise<boolean> {
// checkFreeTrialInstanceUsed is also called to ensure the request didn't fail due to an unrelated quota issue.
return err.message.includes("Quota Exhausted") && (await checkFreeTrialInstanceUsed(projectId))
? true
: false;
}

export function printFreeTrialUnavailable(
projectId: string,
configYamlPath: string,
instanceId?: string,
): void {
if (!instanceId) {
utils.logLabeledError(
"data connect",
"dataconnect",
"The CloudSQL free trial has already been used on this project.",
);
utils.logLabeledError(
"data connect",
"dataconnect",
`You may create or use a paid CloudSQL instance by visiting https://console.cloud.google.com/sql/instances`,
);
return;
}
utils.logLabeledError(
"data connect",
"dataconnect",
`Project '${projectId} already has a CloudSQL instance '${instanceId}' on the Firebase Data Connect no-cost trial.`,
);
const reuseHint =
`To use a different database in the same instance, ${clc.bold(`change the ${clc.blue("instanceId")} to "${instanceId}"`)} and update ${clc.blue("location")} in ` +
`${clc.green(configYamlPath)}.`;

utils.logLabeledError("data connect", reuseHint);
utils.logLabeledError("dataconnect", reuseHint);
utils.logLabeledError(
"data connect",
"dataconnect",
`Alternatively, you may create a new (paid) CloudSQL instance at https://console.cloud.google.com/sql/instances`,
);
}
Expand Down
Loading

0 comments on commit 4b5d2c6

Please sign in to comment.