Skip to content

Commit

Permalink
Merge branch 'master' into jh-cross-spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
joehan authored Jan 2, 2025
2 parents 6f2efe4 + 774d3f0 commit da9a1a4
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 33 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
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
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
58 changes: 31 additions & 27 deletions src/dataconnect/provisionCloudSql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
getFreeTrialInstanceId,
freeTrialTermsLink,
printFreeTrialUnavailable,
checkFreeTrialInstanceUsed,
isFreeTrialError,
} from "./freeTrial";
import { FirebaseError } from "../error";

Expand Down Expand Up @@ -69,11 +69,6 @@ export async function provisionCloudSql(args: {
if (err.status !== 404) {
throw err;
}
const freeTrialInstanceId = await getFreeTrialInstanceId(projectId);
if (await checkFreeTrialInstanceUsed(projectId)) {
printFreeTrialUnavailable(projectId, configYamlPath, freeTrialInstanceId);
throw new FirebaseError("No-cost Cloud SQL trial has already been used on this project.");
}
const cta = dryRun ? "It will be created on your next deploy" : "Creating it now.";
silent ||
utils.logLabeledBullet(
Expand All @@ -84,27 +79,36 @@ export async function provisionCloudSql(args: {
`\nMonitor the progress at ${cloudSqlAdminClient.instanceConsoleLink(projectId, instanceId)}`,
);
if (!dryRun) {
const newInstance = await promiseWithSpinner(
() =>
cloudSqlAdminClient.createInstance(
projectId,
locationId,
instanceId,
enableGoogleMlIntegration,
waitForCreation,
),
"Creating your instance...",
);
if (newInstance) {
silent || utils.logLabeledBullet("dataconnect", "Instance created");
connectionName = newInstance?.connectionName || "";
} else {
silent ||
utils.logLabeledBullet(
"dataconnect",
"Cloud SQL instance creation started - it should be ready shortly. Database and users will be created on your next deploy.",
);
return connectionName;
try {
const newInstance = await promiseWithSpinner(
() =>
cloudSqlAdminClient.createInstance(
projectId,
locationId,
instanceId,
enableGoogleMlIntegration,
waitForCreation,
),
"Creating your instance...",
);
if (newInstance) {
silent || utils.logLabeledBullet("dataconnect", "Instance created");
connectionName = newInstance?.connectionName || "";
} else {
silent ||
utils.logLabeledBullet(
"dataconnect",
"Cloud SQL instance creation started - it should be ready shortly. Database and users will be created on your next deploy.",
);
return connectionName;
}
} catch (err: any) {
if (await isFreeTrialError(err, projectId)) {
const freeTrialInstanceId = await getFreeTrialInstanceId(projectId);
printFreeTrialUnavailable(projectId, configYamlPath, freeTrialInstanceId);
throw new FirebaseError("No-cost Cloud SQL trial has already been used on this project.");
}
throw err;
}
}
}
Expand Down

0 comments on commit da9a1a4

Please sign in to comment.