Explorar o código

branch selection for gha

Alexander Belanger %!s(int64=5) %!d(string=hai) anos
pai
achega
d734e2aef4

+ 4 - 3
dashboard/src/components/repo-selector/ActionConfEditor.tsx

@@ -31,6 +31,7 @@ type StateType = {
 const defaultActionConfig: ActionConfigType = {
   git_repo: "",
   image_repo_uri: "",
+  branch: "",
   git_repo_id: 0,
 };
 
@@ -42,6 +43,7 @@ export default class ActionConfEditor extends Component<PropsType, StateType> {
 
   renderExpanded = () => {
     let { actionConfig, branch, setActionConfig, setBranch } = this.props;
+    console.log("BRANCH IS", branch)
 
     if (!actionConfig.git_repo) {
       return (
@@ -53,8 +55,7 @@ export default class ActionConfEditor extends Component<PropsType, StateType> {
           />
         </ExpandedWrapper>
       );
-    } else if (!this.props.dockerfilePath && !this.props.folderPath) {
-      /* else if (!branch) {
+    } else if (!branch) {
       return (
         <>
           <ExpandedWrapperAlt>
@@ -70,7 +71,7 @@ export default class ActionConfEditor extends Component<PropsType, StateType> {
           </BackButton>
         </>
       );
-    } */
+    } else if (!this.props.dockerfilePath && !this.props.folderPath) {
       return (
         <>
           <ExpandedWrapperAlt>

+ 7 - 0
dashboard/src/components/repo-selector/ActionDetails.tsx

@@ -122,6 +122,13 @@ export default class ActionDetails extends Component<PropsType, StateType> {
           width="100%"
           value={this.props.actionConfig.git_repo}
         />
+        <InputRow
+          disabled={true}
+          label="Branch"
+          type="text"
+          width="100%"
+          value={this.props.branch}
+        />
         {this.props.dockerfilePath ? (
           <InputRow
             disabled={true}

+ 1 - 0
dashboard/src/main/home/integrations/IntegrationRow.tsx

@@ -94,6 +94,7 @@ export default class IntegrationRow extends Component<PropsType, StateType> {
                   {
                     git_repo: "",
                     image_repo_uri: "",
+                    branch: "",
                     git_repo_id: 0,
                     dockerfile_path: "",
                   } as ActionConfigType

+ 2 - 0
dashboard/src/main/home/launch/expanded-template/LaunchTemplate.tsx

@@ -60,6 +60,7 @@ type StateType = {
 const defaultActionConfig: ActionConfigType = {
   git_repo: "",
   image_repo_uri: "",
+  branch: "",
   git_repo_id: 0,
 };
 
@@ -103,6 +104,7 @@ class LaunchTemplate extends Component<PropsType, StateType> {
         "<token>",
         {
           git_repo: actionConfig.git_repo,
+          git_branch: this.state.branch,
           registry_id: this.state.selectedRegistry.id,
           dockerfile_path: this.state.dockerfilePath,
           folder_path: this.state.folderPath,

+ 1 - 0
dashboard/src/shared/api.tsx

@@ -102,6 +102,7 @@ const createGCR = baseApi<
 const createGHAction = baseApi<
   {
     git_repo: string;
+    git_branch: string;
     registry_id: number;
     image_repo_uri: string;
     dockerfile_path: string;

+ 1 - 0
dashboard/src/shared/types.tsx

@@ -163,6 +163,7 @@ export interface InviteType {
 
 export interface ActionConfigType {
   git_repo: string;
+  branch: string;
   image_repo_uri: string;
   git_repo_id: number;
 }

+ 3 - 0
internal/forms/git_action.go

@@ -9,6 +9,7 @@ import (
 type CreateGitAction struct {
 	ReleaseID      uint              `json:"release_id" form:"required"`
 	GitRepo        string            `json:"git_repo" form:"required"`
+	GitBranch      string            `json:"git_branch"`
 	ImageRepoURI   string            `json:"image_repo_uri" form:"required"`
 	DockerfilePath string            `json:"dockerfile_path"`
 	FolderPath     string            `json:"folder_path"`
@@ -22,6 +23,7 @@ func (ca *CreateGitAction) ToGitActionConfig() (*models.GitActionConfig, error)
 	return &models.GitActionConfig{
 		ReleaseID:      ca.ReleaseID,
 		GitRepo:        ca.GitRepo,
+		GitBranch:      ca.GitBranch,
 		ImageRepoURI:   ca.ImageRepoURI,
 		DockerfilePath: ca.DockerfilePath,
 		FolderPath:     ca.FolderPath,
@@ -31,6 +33,7 @@ func (ca *CreateGitAction) ToGitActionConfig() (*models.GitActionConfig, error)
 
 type CreateGitActionOptional struct {
 	GitRepo        string            `json:"git_repo"`
+	GitBranch      string            `json:"git_branch"`
 	ImageRepoURI   string            `json:"image_repo_uri"`
 	DockerfilePath string            `json:"dockerfile_path"`
 	FolderPath     string            `json:"folder_path"`

+ 8 - 1
internal/integrations/ci/actions/actions.go

@@ -30,6 +30,7 @@ type GithubActions struct {
 	ProjectID    uint
 	ReleaseName  string
 
+	GitBranch      string
 	DockerFilePath string
 	FolderPath     string
 	ImageRepoURL   string
@@ -167,11 +168,17 @@ func (g *GithubActions) GetGithubActionYAML() ([]byte, error) {
 
 	gaSteps = append(gaSteps, deployPorterWebhookStep(g.getWebhookSecretName(), g.ImageRepoURL))
 
+	branch := g.GitBranch
+
+	if branch == "" {
+		branch = g.defaultBranch
+	}
+
 	actionYAML := &GithubActionYAML{
 		On: GithubActionYAMLOnPush{
 			Push: GithubActionYAMLOnPushBranches{
 				Branches: []string{
-					g.defaultBranch,
+					branch,
 				},
 			},
 		},

+ 3 - 0
internal/models/gitrepo.go

@@ -55,6 +55,9 @@ type GitActionConfig struct {
 	// The git repo in ${owner}/${repo} form
 	GitRepo string `json:"git_repo"`
 
+	// The git branch to use
+	GitBranch string `json:"git_branch"`
+
 	// The complete image repository uri to pull from
 	ImageRepoURI string `json:"image_repo_uri"`
 

+ 1 - 0
server/api/deploy_handler.go

@@ -257,6 +257,7 @@ func (app *App) HandleUninstallTemplate(w http.ResponseWriter, r *http.Request)
 				WebhookToken:   release.WebhookToken,
 				ProjectID:      uint(projID),
 				ReleaseName:    name,
+				GitBranch:      gitAction.GitBranch,
 				DockerFilePath: gitAction.DockerfilePath,
 				FolderPath:     gitAction.FolderPath,
 				ImageRepoURL:   gitAction.ImageRepoURI,

+ 3 - 0
server/api/git_action_handler.go

@@ -151,6 +151,8 @@ func (app *App) createGitActionFromForm(
 		return nil
 	}
 
+	fmt.Println("GIT ACTIONB BRANCH IS", gitAction.GitBranch)
+
 	// create the commit in the git repo
 	gaRunner := &actions.GithubActions{
 		GitIntegration: gr,
@@ -161,6 +163,7 @@ func (app *App) createGitActionFromForm(
 		WebhookToken:   release.WebhookToken,
 		ProjectID:      uint(projID),
 		ReleaseName:    name,
+		GitBranch:      gitAction.GitBranch,
 		DockerFilePath: gitAction.DockerfilePath,
 		FolderPath:     gitAction.FolderPath,
 		ImageRepoURL:   gitAction.ImageRepoURI,

+ 3 - 1
server/api/release_handler.go

@@ -593,6 +593,7 @@ func (app *App) HandleUpgradeRelease(w http.ResponseWriter, r *http.Request) {
 				WebhookToken:   release.WebhookToken,
 				ProjectID:      uint(projID),
 				ReleaseName:    name,
+				GitBranch:      gitAction.GitBranch,
 				DockerFilePath: gitAction.DockerfilePath,
 				FolderPath:     gitAction.FolderPath,
 				ImageRepoURL:   gitAction.ImageRepoURI,
@@ -684,7 +685,7 @@ func (app *App) HandleReleaseDeployWebhook(w http.ResponseWriter, r *http.Reques
 		}, w)
 
 		return
-	} 
+	}
 
 	registries, err := app.Repo.Registry.ListRegistriesByProjectID(uint(form.ReleaseForm.Cluster.ProjectID))
 
@@ -843,6 +844,7 @@ func (app *App) HandleRollbackRelease(w http.ResponseWriter, r *http.Request) {
 				WebhookToken:   release.WebhookToken,
 				ProjectID:      uint(projID),
 				ReleaseName:    name,
+				GitBranch:      gitAction.GitBranch,
 				DockerFilePath: gitAction.DockerfilePath,
 				FolderPath:     gitAction.FolderPath,
 				ImageRepoURL:   gitAction.ImageRepoURI,