Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create rollout from branch or git commit #7687

Merged
merged 7 commits into from
Oct 7, 2024

Conversation

blidd-google
Copy link
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
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
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
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.

.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')", "")
.option("-c, --commit <commit>", "git commit to deploy (defaults to the latest commit)", "")
.option("-f, --force", "skip confirmation")
Copy link
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

.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')", "")
.option("-c, --commit <commit>", "git commit to deploy (defaults to the latest commit)", "")
Copy link
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
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
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
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
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
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
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
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
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
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
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
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 and others added 2 commits October 7, 2024 17:33
@blidd-google blidd-google merged commit f350d60 into master Oct 7, 2024
40 of 41 checks passed
@0robbin0
Copy link

hello work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants