Skip to content

Create rollout from branch or git commit#7687

Merged
blidd-google merged 7 commits intomasterfrom
bl-apphosting-rollouts-create
Oct 7, 2024
Merged

Create rollout from branch or git commit#7687
blidd-google merged 7 commits intomasterfrom
bl-apphosting-rollouts-create

Conversation

@blidd-google
Copy link
Copy Markdown
Contributor

@blidd-google blidd-google commented Sep 19, 2024

Create rollouts from the CLI by specifying a backend and a Git branch or commit.

location: string;
backendId: string;
buildInput: DeepOmit<Build, apphosting.BuildOutputOnlyFields | "name">;
isFirstRollout?: boolean;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

consider adding a note on why this field is necessary

.description("create a rollout using a build for an App Hosting backend")
.option("-l, --location <location>", "specify the region of the backend", "us-central1")
.option("-i, --id <rolloutId>", "id of the rollout (defaults to autogenerating a random id)", "")
.option("-b, --git-branch <gitBranch>", "repository branch to deploy (defaults to 'main')", "")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we do -gb and -gc for shorthand?

This will leave -b open for branches

.description("create a rollout using a build for an App Hosting backend")
.option("-l, --location <location>", "specify the region of the backend", "us-central1")
.option("-i, --id <rolloutId>", "id of the rollout (defaults to autogenerating a random id)", "")
.option("-b, --git-branch <gitBranch>", "repository branch to deploy (defaults to 'main')", "")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

let's remove the default comments here.

either add a default value or drop it entirely.

.option("-i, --id <rolloutId>", "id of the rollout (defaults to autogenerating a random id)", "")
.option("-b, --git-branch <gitBranch>", "repository branch to deploy (defaults to 'main')", "")
.option("-c, --commit <commit>", "git commit to deploy (defaults to the latest commit)", "")
.option("-f, --force", "skip confirmation")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe there's a withForce method that you can use here instead of a custom force flag

.option("-l, --location <location>", "specify the region of the backend", "us-central1")
.option("-i, --id <rolloutId>", "id of the rollout (defaults to autogenerating a random id)", "")
.option("-b, --git-branch <gitBranch>", "repository branch to deploy (defaults to 'main')", "")
.option("-c, --commit <commit>", "git commit to deploy (defaults to the latest commit)", "")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

consider adding a note that this is mutually exclusive with -gb

backend.codebase.repository,
);

let target;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

targetCommit?

const branchInfo = await getGitHubBranch(owner, repo, branch, readToken.token);
target = branchInfo.commit;
} else if (commit) {
if (!/^(?:[0-9a-f]{40}|[0-9a-f]{7})$/.test(commit)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

consider pulling this up to a file level const with a proper name to make it clear that this is our commit sha regex

const commitInfo = await getGitHubCommit(owner, repo, commit, readToken.token);
target = commitInfo;
} catch (err: unknown) {
if ((err as FirebaseError).status === 422) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why 422?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

422 HTTP status code returned by GitHub indicates it was unable to find the commit in the repo. I'll add a comment to clarify this

target = branchInfo.commit;
}

logBullet(`You are about to deploy [${target.sha.substring(0, 7)}]: ${target.commit.message}`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

let's make sure we update these as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What should we make sure to update here?

buildInput: {
source: {
codebase: {
commit: target.sha,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is making me realize we need an explicit type for the target declaration

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

target is of type GitHubCommitInfo, which is defined in src/apphosting/githubConnections.ts. Exported the interface and explicitly typed targetCommit: GitHubCommitInfo.

@blidd-google blidd-google requested review from joehan and taeold October 2, 2024 18:32
Copy link
Copy Markdown
Contributor

@tonyjhuang tonyjhuang left a comment

Choose a reason for hiding this comment

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

last few comments

* Create a new App Hosting rollout for a backend.
* Implements core logic for apphosting:rollouts:create command.
*/
export async function doSetup(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is there a better name fo rthis function? createRollout maybe?

const commit = options.gitCommit as string | undefined;
if (branch && commit) {
throw new FirebaseError(
"Cannot specify both a branch and commit to deploy. Please specify either --git-branch or --commit.",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

--git-commit

@blidd-google blidd-google merged commit f350d60 into master Oct 7, 2024
@0robbin0
Copy link
Copy Markdown

hello work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants