Skip to content

Commit

Permalink
Update use of log to be consistent in framework init.
Browse files Browse the repository at this point in the history
  • Loading branch information
taeold committed Dec 6, 2023
1 parent cbc979a commit affc89d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
24 changes: 9 additions & 15 deletions src/init/features/frameworks/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import * as clc from "colorette";
import * as utils from "../../../utils";
import * as repo from "./repo";
import * as poller from "../../../operation-poller";
import * as gcp from "../../../gcp/frameworks";
import { logBullet, logSuccess } from "../../../utils";
import { frameworksOrigin } from "../../../api";
import { Backend, BackendOutputOnlyFields } from "../../../gcp/frameworks";
import { Repository } from "../../../gcp/cloudbuild";
import { API_VERSION } from "../../../gcp/frameworks";
import { FirebaseError } from "../../../error";
import { logger } from "../../../logger";
import { promptOnce } from "../../../prompt";
import { DEFAULT_REGION, ALLOWED_REGIONS } from "./constants";

Expand All @@ -25,7 +24,7 @@ const frameworksPollerOptions: Omit<poller.OperationPollerOptions, "operationRes
export async function doSetup(setup: any, projectId: string): Promise<void> {
setup.frameworks = {};

utils.logBullet("First we need a few details to create your backend.");
logBullet("First we need a few details to create your backend.");

await promptOnce(
{
Expand All @@ -50,20 +49,16 @@ export async function doSetup(setup: any, projectId: string): Promise<void> {
setup.frameworks
);

utils.logSuccess(`Region set to ${setup.frameworks.region}.`);
logSuccess(`Region set to ${setup.frameworks.region}.\n`);

const backend: Backend | undefined = await getOrCreateBackend(projectId, setup);

if (backend) {
logger.info();
utils.logSuccess(`Successfully created backend:\n ${backend.name}`);
logger.info();
utils.logSuccess(`Your site is being deployed at:\n https://${backend.uri}`);
logger.info();
utils.logSuccess(
`View the rollout status by running:\n firebase backends:get --backend=${backend.name}`
logSuccess(`Successfully created backend:\n ${backend.name}`);
logSuccess(`Your site is being deployed at:\n https://${backend.uri}\n`);
logSuccess(
`View the rollout status by running:\n firebase backends:get --backend=${backend.name}\n`
);
logger.info();
}
}

Expand All @@ -90,7 +85,6 @@ export async function getOrCreateBackend(
} catch (err: unknown) {
if ((err as FirebaseError).status === 404) {
const cloudBuildConnRepo = await repo.linkGitHubRepository(projectId, location);
logger.info();
await promptOnce(
{
name: "branchName",
Expand All @@ -101,7 +95,7 @@ export async function getOrCreateBackend(
setup.frameworks
);
const backendDetails = toBackend(cloudBuildConnRepo);
logger.info(clc.bold(`\n${clc.white("===")} Creating your backend`));
logBullet(clc.bold(`${clc.white("===")} Creating your backend`));
return await createBackend(projectId, location, backendDetails, setup.frameworks.serviceName);
} else {
throw new FirebaseError(
Expand Down Expand Up @@ -132,7 +126,7 @@ async function getExistingBackend(
setup.frameworks
);
if (setup.frameworks.existingBackend) {
logger.info("Using the existing backend.");
logBullet("Using the existing backend.");
return backend;
}
await promptOnce(
Expand Down
8 changes: 4 additions & 4 deletions src/init/features/frameworks/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export async function linkGitHubRepository(
projectId: string,
location: string
): Promise<gcb.Repository> {
logger.info(clc.bold(`\n${clc.yellow("===")} Connect a GitHub repository`));
utils.logBullet(clc.bold(`${clc.yellow("===")} Connect a GitHub repository`));
const existingConns = await listFrameworksConnections(projectId);
if (existingConns.length < 1) {
const grantSuccess = await promptSecretManagerAdminGrant(projectId);
Expand Down Expand Up @@ -165,15 +165,15 @@ async function promptRepositoryUri(
async function promptSecretManagerAdminGrant(projectId: string): Promise<Boolean> {
const projectNumber = await getProjectNumber({ projectId });
const cbsaEmail = gcb.serviceAgentEmail(projectNumber);
logger.info(
utils.logBullet(
"To create a new GitHub connection, Secret Manager Admin role (roles/secretmanager.admin) is required on the Cloud Build Service Agent."
);
const grant = await promptOnce({
type: "confirm",
message: "Grant the required role to the Cloud Build Service Agent?",
});
if (!grant) {
logger.info(
logBullet(

Check failure on line 176 in src/init/features/frameworks/repo.ts

View workflow job for this annotation

GitHub Actions / unit (16)

Cannot find name 'logBullet'.

Check failure on line 176 in src/init/features/frameworks/repo.ts

View workflow job for this annotation

GitHub Actions / unit (18)

Cannot find name 'logBullet'.

Check failure on line 176 in src/init/features/frameworks/repo.ts

View workflow job for this annotation

GitHub Actions / unit (16)

Cannot find name 'logBullet'.

Check failure on line 176 in src/init/features/frameworks/repo.ts

View workflow job for this annotation

GitHub Actions / check-json-schema (18)

Cannot find name 'logBullet'.

Check failure on line 176 in src/init/features/frameworks/repo.ts

View workflow job for this annotation

GitHub Actions / unit (18)

Cannot find name 'logBullet'.

Check failure on line 176 in src/init/features/frameworks/repo.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Cannot find name 'logBullet'.

Check failure on line 176 in src/init/features/frameworks/repo.ts

View workflow job for this annotation

GitHub Actions / check-json-schema (18)

Cannot find name 'logBullet'.
"You, or your project adminstrator, can run the following command to grant the required role manually:\n\n" +
`\tgcloud projects add-iam-policy-binding ${projectId} \\\n` +
`\t --member="serviceAccount:${cbsaEmail} \\\n` +
Expand All @@ -182,7 +182,7 @@ async function promptSecretManagerAdminGrant(projectId: string): Promise<Boolean
return false;
}
await rm.addServiceAccountToRoles(projectId, cbsaEmail, ["roles/secretmanager.admin"], true);
logger.info("Successfully granted the required role to the Cloud Build Service Agent!");
utils.logSuccess("Successfully granted the required role to the Cloud Build Service Agent!");
return true;
}

Expand Down

0 comments on commit affc89d

Please sign in to comment.