-
Notifications
You must be signed in to change notification settings - Fork 202
Switch to branch deployments in one-click deployments #2647
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
Open
atharvadeosthale
wants to merge
12
commits into
main
Choose a base branch
from
one-click-updates
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0f3aaba
add branch deployments to one-click deployments
atharvadeosthale d5436e1
fix region mismatch
atharvadeosthale 2bb3f66
add branch search param, with branch validation, fallback to default …
atharvadeosthale 5aae015
fetch branch from url if provided
atharvadeosthale f5b6f99
add env values support
atharvadeosthale 20ca407
added quick mode to skip wizard
atharvadeosthale 2d3699c
add plan checks
atharvadeosthale 6c22ff3
address some comments
atharvadeosthale 449ec78
Merge branch 'main' into one-click-updates
atharvadeosthale ef1a4c9
coderabbit comment
atharvadeosthale 7bc21f2
extract branch selection logic to a helper
atharvadeosthale 6e2724b
fetch all branches for repo
atharvadeosthale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ | |
| import { regionalConsoleVariables } from '$routes/(console)/project-[region]-[project]/store'; | ||
| import { iconPath } from '$lib/stores/app'; | ||
| import type { PageData } from './$types'; | ||
| import { getLatestTag } from '$lib/helpers/github'; | ||
| import { getDefaultBranch, getBranches } from '$lib/helpers/github'; | ||
| import { writable } from 'svelte/store'; | ||
| import Link from '$lib/elements/link.svelte'; | ||
|
|
||
|
|
@@ -42,8 +42,9 @@ | |
| let selectedScopes = $state<string[]>([]); | ||
| let rootDir = $state(data.repository?.rootDirectory); | ||
| let variables = $state<Array<{ key: string; value: string; secret: boolean }>>([]); | ||
|
|
||
| let latestTag = $state(null); | ||
| let branches = $state<string[]>([]); | ||
| let selectedBranch = $state<string>(''); | ||
| let loadingBranches = $state(false); | ||
|
|
||
| const specificationOptions = $derived( | ||
| data.specificationsList?.specifications?.map((size) => ({ | ||
|
|
@@ -63,7 +64,7 @@ | |
| })) || [] | ||
| ); | ||
|
|
||
| onMount(() => { | ||
| onMount(async () => { | ||
| const runtimeParam = data.runtime || page.url.searchParams.get('runtime') || 'node-18.0'; | ||
| runtime = runtimeParam as Runtime; | ||
|
|
||
|
|
@@ -80,19 +81,61 @@ | |
| variables = data.envKeys.map((key) => ({ key, value: '', secret: false })); | ||
| } | ||
|
|
||
| getLatestTag(data.repository.owner, data.repository.name).then( | ||
| (tagName) => (latestTag = tagName) | ||
| ); | ||
| // Load branches and set default branch | ||
| if (data.repository?.owner && data.repository?.name) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is coupling us very hard to GitHub, this logic has to be part of Utopia/VCS if its not already there, which is also very likely. |
||
| loadingBranches = true; | ||
| try { | ||
| const [branchList, defaultBranch] = await Promise.all([ | ||
| getBranches(data.repository.owner, data.repository.name), | ||
| getDefaultBranch(data.repository.owner, data.repository.name) | ||
| ]); | ||
|
|
||
| if (branchList && branchList.length > 0) { | ||
| branches = branchList; | ||
| // Pre-select default branch, or first branch if default not found | ||
| selectedBranch = | ||
| defaultBranch && branchList.includes(defaultBranch) | ||
| ? defaultBranch | ||
| : branchList[0]; | ||
| } else { | ||
| // Branch list is empty or null | ||
| addNotification({ | ||
| type: 'error', | ||
| message: | ||
| 'Failed to load branches from repository. Please check the repository URL or try again.' | ||
| }); | ||
| } | ||
| } catch (error) { | ||
| console.error('Failed to load branches:', error); | ||
atharvadeosthale marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| addNotification({ | ||
| type: 'error', | ||
| message: | ||
| 'Failed to load branches from repository. Please check the repository URL or try again.' | ||
| }); | ||
| } finally { | ||
| loadingBranches = false; | ||
| } | ||
| } else { | ||
| // Repository info is missing | ||
| addNotification({ | ||
| type: 'error', | ||
| message: 'Repository information is missing. Please check the repository URL.' | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| async function create() { | ||
| if (!selectedBranch || branches.length === 0) { | ||
| addNotification({ | ||
| type: 'error', | ||
| message: 'Please wait for branches to load or check the repository URL.' | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| $isSubmitting = true; | ||
|
|
||
| try { | ||
| if (!latestTag) { | ||
| latestTag = await getLatestTag(data.repository.owner, data.repository.name); | ||
| } | ||
|
|
||
| // Create function with configuration | ||
| const func = await sdk | ||
| .forProject(page.params.region, page.params.project) | ||
|
|
@@ -126,16 +169,16 @@ | |
|
|
||
| await Promise.all(promises); | ||
|
|
||
| // Create deployment from GitHub repository using the latest tag | ||
| // Create deployment from GitHub repository using the selected branch | ||
| await sdk | ||
| .forProject(page.params.region, page.params.project) | ||
| .functions.createTemplateDeployment({ | ||
| functionId: func.$id, | ||
| repository: data.repository.name, | ||
| owner: data.repository.owner, | ||
| rootDirectory: rootDir || '.', | ||
| type: Type.Tag, | ||
| reference: latestTag ?? '1.0.0', | ||
| type: Type.Branch, | ||
| reference: selectedBranch, | ||
| activate: true | ||
| }); | ||
|
|
||
|
|
@@ -220,6 +263,22 @@ | |
| </Layout.Stack> | ||
| </Fieldset> | ||
|
|
||
| <Fieldset legend="Git configuration"> | ||
| <Layout.Stack gap="m"> | ||
| <Input.Select | ||
| id="branch" | ||
| label="Branch" | ||
| required | ||
| placeholder={loadingBranches ? 'Loading branches...' : 'Select branch'} | ||
| bind:value={selectedBranch} | ||
| disabled={loadingBranches} | ||
| options={branches.map((branch) => ({ | ||
| value: branch, | ||
| label: branch | ||
| }))} /> | ||
| </Layout.Stack> | ||
| </Fieldset> | ||
|
|
||
| <Fieldset legend="Build configuration"> | ||
| <Layout.Stack gap="m"> | ||
| <Input.Text | ||
|
|
@@ -276,7 +335,12 @@ | |
| fullWidthMobile | ||
| submissionLoader | ||
| forceShowLoader={$isSubmitting} | ||
| disabled={!name || !runtime || !specification || $isSubmitting}> | ||
| disabled={!name || | ||
| !runtime || | ||
| !specification || | ||
| !selectedBranch || | ||
| branches.length === 0 || | ||
| $isSubmitting}> | ||
| Deploy function | ||
| </Button> | ||
| </Layout.Stack> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.