Răsfoiți Sursa

Merge branch 'master' of github.com:porter-dev/porter into nico/por-577-support-updates-for-source-configs-from

jnfrati 3 ani în urmă
părinte
comite
d3b39c8b13

+ 20 - 0
api/client/environment.go

@@ -22,6 +22,26 @@ func (c *Client) ListEnvironments(
 	return resp, err
 	return resp, err
 }
 }
 
 
+func (c *Client) CreateDeployment(
+	ctx context.Context,
+	projID, gitInstallationID, clusterID uint,
+	gitRepoOwner, gitRepoName string,
+	req *types.CreateDeploymentRequest,
+) (*types.Deployment, error) {
+	resp := &types.Deployment{}
+
+	err := c.postRequest(
+		fmt.Sprintf(
+			"/projects/%d/gitrepos/%d/%s/%s/clusters/%d/deployment",
+			projID, gitInstallationID, gitRepoOwner, gitRepoName, clusterID,
+		),
+		req,
+		resp,
+	)
+
+	return resp, err
+}
+
 func (c *Client) GetDeployment(
 func (c *Client) GetDeployment(
 	ctx context.Context,
 	ctx context.Context,
 	projID, clusterID, envID uint,
 	projID, clusterID, envID uint,

+ 2 - 0
api/server/handlers/environment/list_deployments_by_cluster.go

@@ -221,6 +221,8 @@ func updateDeploymentWithGithubWorkflowRunStatus(
 				deployment.Status = types.DeploymentStatusFailed
 				deployment.Status = types.DeploymentStatusFailed
 			} else if latestWorkflowRun.GetConclusion() == "timed_out" {
 			} else if latestWorkflowRun.GetConclusion() == "timed_out" {
 				deployment.Status = types.DeploymentStatusTimedOut
 				deployment.Status = types.DeploymentStatusTimedOut
+			} else if latestWorkflowRun.GetConclusion() == "success" {
+				deployment.Status = types.DeploymentStatusCreated
 			}
 			}
 		}
 		}
 	}
 	}

+ 6 - 0
api/server/handlers/environment/update_deployment_status.go

@@ -63,6 +63,12 @@ func (c *UpdateDeploymentStatusHandler) ServeHTTP(w http.ResponseWriter, r *http
 		return
 		return
 	}
 	}
 
 
+	if depl.Status == types.DeploymentStatusInactive && request.Status != string(types.DeploymentStatusCreating) {
+		// a deployment from "inactive" state can only transition to "creating"
+		c.WriteResult(w, r, depl.ToDeploymentType())
+		return
+	}
+
 	depl.Status = types.DeploymentStatus(request.Status)
 	depl.Status = types.DeploymentStatus(request.Status)
 
 
 	// create the deployment
 	// create the deployment

+ 11 - 29
api/server/handlers/webhook/github_incoming.go

@@ -7,7 +7,6 @@ import (
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
 	"sync"
 	"sync"
-	"time"
 
 
 	"github.com/bradleyfalzon/ghinstallation/v2"
 	"github.com/bradleyfalzon/ghinstallation/v2"
 	"github.com/google/go-github/v41/github"
 	"github.com/google/go-github/v41/github"
@@ -190,57 +189,40 @@ func (c *GithubIncomingWebhookHandler) processPullRequestEvent(event *github.Pul
 			// check for already running workflows we should be cancelling
 			// check for already running workflows we should be cancelling
 			var wg sync.WaitGroup
 			var wg sync.WaitGroup
 			statuses := []string{"in_progress", "queued", "requested", "waiting"}
 			statuses := []string{"in_progress", "queued", "requested", "waiting"}
+			chanErr := fmt.Errorf("")
 
 
 			wg.Add(len(statuses))
 			wg.Add(len(statuses))
 
 
-			errChan := make(chan error)
-
 			for _, status := range statuses {
 			for _, status := range statuses {
 				go func(status string) {
 				go func(status string) {
 					defer wg.Done()
 					defer wg.Done()
 
 
-					reqCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
-					defer cancel()
-
 					runs, _, err := client.Actions.ListWorkflowRunsByFileName(
 					runs, _, err := client.Actions.ListWorkflowRunsByFileName(
-						reqCtx, owner, repo, fmt.Sprintf("porter_%s_env.yml", env.Name),
+						context.Background(), owner, repo, fmt.Sprintf("porter_%s_env.yml", env.Name),
 						&github.ListWorkflowRunsOptions{
 						&github.ListWorkflowRunsOptions{
 							Branch: event.GetPullRequest().GetHead().GetRef(),
 							Branch: event.GetPullRequest().GetHead().GetRef(),
 							Status: status,
 							Status: status,
 						},
 						},
 					)
 					)
 
 
-					if err == nil && runs.GetTotalCount() > 0 {
-						wg.Add(runs.GetTotalCount())
-
+					if err == nil {
 						for _, run := range runs.WorkflowRuns {
 						for _, run := range runs.WorkflowRuns {
-							go func(id int64, url string) {
-								defer wg.Done()
-
-								reqCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
-								defer cancel()
+							resp, err := client.Actions.CancelWorkflowRunByID(context.Background(), owner, repo, run.GetID())
 
 
-								_, err := client.Actions.CancelWorkflowRunByID(reqCtx, owner, repo, id)
-
-								if err != nil {
-									errChan <- fmt.Errorf("error cancelling %s: %w", url, err)
-								}
-							}(run.GetID(), run.GetHTMLURL())
+							if err != nil && resp.StatusCode != http.StatusAccepted {
+								// the go library we are using returns a 202 Accepted status as an error
+								// in this case, we should rule this out as an error
+								chanErr = fmt.Errorf("%s: error cancelling %s: %w", chanErr.Error(), run.GetHTMLURL(), err)
+							}
 						}
 						}
-					} else if err != nil {
-						errChan <- fmt.Errorf("error listing workflows for status %s: %w", status, err)
+					} else {
+						chanErr = fmt.Errorf("%s: error listing workflows for status %s: %w", chanErr.Error(), status, err)
 					}
 					}
 				}(status)
 				}(status)
 			}
 			}
 
 
 			wg.Wait()
 			wg.Wait()
 
 
-			chanErr := fmt.Errorf("")
-
-			for err := range errChan {
-				chanErr = fmt.Errorf("%s: %w", chanErr.Error(), err)
-			}
-
 			err = c.deleteDeployment(r, depl, env, client)
 			err = c.deleteDeployment(r, depl, env, client)
 
 
 			if err != nil {
 			if err != nil {

+ 23 - 1
cli/cmd/apply.go

@@ -743,7 +743,29 @@ func (t *DeploymentHook) PreApply() error {
 		},
 		},
 	)
 	)
 
 
-	if err == nil {
+	if err != nil && strings.Contains(err.Error(), "not found") {
+		// in this case, create the deployment
+		_, err = t.client.CreateDeployment(
+			context.Background(),
+			t.projectID, t.gitInstallationID, t.clusterID,
+			t.repoOwner, t.repoName,
+			&types.CreateDeploymentRequest{
+				Namespace:     t.namespace,
+				PullRequestID: t.prID,
+				CreateGHDeploymentRequest: &types.CreateGHDeploymentRequest{
+					ActionID: t.actionID,
+				},
+				GitHubMetadata: &types.GitHubMetadata{
+					PRName:       t.prName,
+					RepoName:     t.repoName,
+					RepoOwner:    t.repoOwner,
+					CommitSHA:    t.commitSHA,
+					PRBranchFrom: t.branchFrom,
+					PRBranchInto: t.branchInto,
+				},
+			},
+		)
+	} else if err == nil {
 		_, err = t.client.UpdateDeployment(
 		_, err = t.client.UpdateDeployment(
 			context.Background(),
 			context.Background(),
 			t.projectID, t.gitInstallationID, t.clusterID,
 			t.projectID, t.gitInstallationID, t.clusterID,

+ 51 - 16
cli/cmd/list.go

@@ -10,8 +10,11 @@ import (
 	api "github.com/porter-dev/porter/api/client"
 	api "github.com/porter-dev/porter/api/client"
 	"github.com/porter-dev/porter/api/types"
 	"github.com/porter-dev/porter/api/types"
 	"github.com/spf13/cobra"
 	"github.com/spf13/cobra"
+	"helm.sh/helm/v3/pkg/release"
 )
 )
 
 
+var allNamespaces bool
+
 // listCmd represents the "porter list" base command and "porter list all" subcommand
 // listCmd represents the "porter list" base command and "porter list all" subcommand
 var listCmd = &cobra.Command{
 var listCmd = &cobra.Command{
 	Use:   "list",
 	Use:   "list",
@@ -76,6 +79,13 @@ func init() {
 		"the namespace of the release",
 		"the namespace of the release",
 	)
 	)
 
 
+	listCmd.PersistentFlags().BoolVar(
+		&allNamespaces,
+		"all-namespaces",
+		false,
+		"list resources for all namespaces",
+	)
+
 	listCmd.AddCommand(listAppsCmd)
 	listCmd.AddCommand(listAppsCmd)
 	listCmd.AddCommand(listJobsCmd)
 	listCmd.AddCommand(listJobsCmd)
 	listCmd.AddCommand(listAddonsCmd)
 	listCmd.AddCommand(listAddonsCmd)
@@ -124,24 +134,49 @@ func listAddons(_ *types.GetAuthenticatedUserResponse, client *api.Client, args
 }
 }
 
 
 func writeReleases(client *api.Client, kind string) error {
 func writeReleases(client *api.Client, kind string) error {
-	releases, err := client.ListReleases(context.Background(), cliConf.Project, cliConf.Cluster, namespace, &types.ListReleasesRequest{
-		ReleaseListFilter: &types.ReleaseListFilter{
-			Limit: 50,
-			Skip:  0,
-			StatusFilter: []string{
-				"deployed",
-				"uninstalled",
-				"pending",
-				"pending-install",
-				"pending-upgrade",
-				"pending-rollback",
-				"failed",
+	var namespaces []string
+	var releases []*release.Release
+
+	if allNamespaces {
+		resp, err := client.GetK8sNamespaces(context.Background(), cliConf.Project, cliConf.Cluster)
+
+		if err != nil {
+			return err
+		}
+
+		namespaceResp := *resp
+
+		for _, ns := range namespaceResp {
+			namespaces = append(namespaces, ns.Name)
+		}
+	} else {
+		namespaces = append(namespaces, namespace)
+	}
+
+	for _, ns := range namespaces {
+		resp, err := client.ListReleases(context.Background(), cliConf.Project, cliConf.Cluster, ns,
+			&types.ListReleasesRequest{
+				ReleaseListFilter: &types.ReleaseListFilter{
+					Limit: 50,
+					Skip:  0,
+					StatusFilter: []string{
+						"deployed",
+						"uninstalled",
+						"pending",
+						"pending-install",
+						"pending-upgrade",
+						"pending-rollback",
+						"failed",
+					},
+				},
 			},
 			},
-		},
-	})
+		)
 
 
-	if err != nil {
-		return err
+		if err != nil {
+			return err
+		}
+
+		releases = append(releases, resp...)
 	}
 	}
 
 
 	w := new(tabwriter.Writer)
 	w := new(tabwriter.Writer)

+ 39 - 2
dashboard/src/components/repo-selector/RepoList.tsx

@@ -19,6 +19,42 @@ type Props = {
   filteredRepos?: string[];
   filteredRepos?: string[];
 };
 };
 
 
+type Provider =
+  | {
+      provider: "github";
+      name: string;
+      installation_id: number;
+    }
+  | {
+      provider: "gitlab";
+      instance_url: string;
+      integration_id: number;
+    };
+
+// Sort provider by name if it's github or instance url if it's gitlab
+const sortProviders = (providers: Provider[]) => {
+  const githubProviders = providers.filter(
+    (provider) => provider.provider === "github"
+  );
+
+  const gitlabProviders = providers.filter(
+    (provider) => provider.provider === "gitlab"
+  );
+
+  const githubSortedProviders = githubProviders.sort((a, b) => {
+    if (a.provider === "github" && b.provider === "github") {
+      return a.name.localeCompare(b.name);
+    }
+  });
+
+  const gitlabSortedProviders = gitlabProviders.sort((a, b) => {
+    if (a.provider === "gitlab" && b.provider === "gitlab") {
+      return a.instance_url.localeCompare(b.instance_url);
+    }
+  });
+  return [...gitlabSortedProviders, ...githubSortedProviders];
+};
+
 const RepoList: React.FC<Props> = ({
 const RepoList: React.FC<Props> = ({
   actionConfig,
   actionConfig,
   setActionConfig,
   setActionConfig,
@@ -51,8 +87,9 @@ const RepoList: React.FC<Props> = ({
           return;
           return;
         }
         }
 
 
-        setProviders(data);
-        setCurrentProvider(data[0]);
+        const sortedProviders = sortProviders(data);
+        setProviders(sortedProviders);
+        setCurrentProvider(sortedProviders[0]);
       })
       })
       .catch((err) => {
       .catch((err) => {
         setHasProviders(false);
         setHasProviders(false);

+ 34 - 62
dashboard/src/main/home/sidebar/Sidebar.tsx

@@ -103,6 +103,34 @@ class Sidebar extends Component<PropsType, StateType> {
     }
     }
   };
   };
 
 
+  /**
+   * Helper function that will keep the query params before redirect the user to a new page
+   *
+   * @param location
+   * @param path Path to redirect to
+   * @returns React router `to` object
+   */
+  withQueryParams = (location: any, path: string) => {
+    let { currentCluster, currentProject } = this.context;
+    let params = this.props.match.params as any;
+    let pathNamespace = params.namespace;
+    let search = `?cluster=${currentCluster.name}&project_id=${currentProject.id}`;
+
+    if (!pathNamespace) {
+      pathNamespace = getQueryParam(this.props, "namespace");
+    }
+
+    if (pathNamespace) {
+      search = search.concat(`&namespace=${pathNamespace}`);
+    }
+
+    return {
+      ...location,
+      pathname: path,
+      search,
+    };
+  };
+
   renderClusterContent = () => {
   renderClusterContent = () => {
     let { currentCluster, currentProject } = this.context;
     let { currentCluster, currentProject } = this.context;
 
 
@@ -110,74 +138,16 @@ class Sidebar extends Component<PropsType, StateType> {
       return (
       return (
         <>
         <>
           <NavButton
           <NavButton
-            to={(location) => {
-              let params = this.props.match.params as any;
-              let pathNamespace = params.namespace;
-              let search = `?cluster=${currentCluster.name}&project_id=${currentProject.id}`;
-
-              if (!pathNamespace) {
-                pathNamespace = getQueryParam(this.props, "namespace");
-              }
-
-              if (pathNamespace) {
-                search = search.concat(`&namespace=${pathNamespace}`);
-              }
-
-              return {
-                ...location,
-                pathname: "/applications",
-                search,
-              };
-            }}
+            to={(location) => this.withQueryParams(location, "/applications")}
           >
           >
             <Img src={monoweb} />
             <Img src={monoweb} />
             Applications
             Applications
           </NavButton>
           </NavButton>
-          <NavButton
-            to={() => {
-              let params = this.props.match.params as any;
-              let pathNamespace = params.namespace;
-              let search = `?cluster=${currentCluster.name}&project_id=${currentProject.id}`;
-
-              if (!pathNamespace) {
-                pathNamespace = getQueryParam(this.props, "namespace");
-              }
-
-              if (pathNamespace) {
-                search = search.concat(`&namespace=${pathNamespace}`);
-              }
-
-              return {
-                ...location,
-                pathname: "/jobs",
-                search,
-              };
-            }}
-          >
+          <NavButton to={() => this.withQueryParams(location, "/jobs")}>
             <Img src={monojob} />
             <Img src={monojob} />
             Jobs
             Jobs
           </NavButton>
           </NavButton>
-          <NavButton
-            to={() => {
-              let params = this.props.match.params as any;
-              let pathNamespace = params.namespace;
-              let search = `?cluster=${currentCluster.name}&project_id=${currentProject.id}`;
-
-              if (!pathNamespace) {
-                pathNamespace = getQueryParam(this.props, "namespace");
-              }
-
-              if (pathNamespace) {
-                search = search.concat(`&namespace=${pathNamespace}`);
-              }
-
-              return {
-                ...location,
-                pathname: "/env-groups",
-                search,
-              };
-            }}
-          >
+          <NavButton to={() => this.withQueryParams(location, "/env-groups")}>
             <Img src={sliders} />
             <Img src={sliders} />
             Env Groups
             Env Groups
           </NavButton>
           </NavButton>
@@ -224,7 +194,9 @@ class Sidebar extends Component<PropsType, StateType> {
             </NavButton>
             </NavButton>
           )}
           )}
           {currentProject?.stacks_enabled ? (
           {currentProject?.stacks_enabled ? (
-            <NavButton to="/stacks">
+            <NavButton
+              to={(location) => this.withQueryParams(location, "/stacks")}
+            >
               <Icon className="material-icons-outlined">lan</Icon>
               <Icon className="material-icons-outlined">lan</Icon>
               Stacks
               Stacks
             </NavButton>
             </NavButton>

+ 3 - 2
internal/integrations/ci/actions/actions.go

@@ -235,8 +235,9 @@ type GithubActionYAMLOnPush struct {
 }
 }
 
 
 type GithubActionYAMLJob struct {
 type GithubActionYAMLJob struct {
-	RunsOn string                 `yaml:"runs-on,omitempty"`
-	Steps  []GithubActionYAMLStep `yaml:"steps,omitempty"`
+	RunsOn      string                 `yaml:"runs-on,omitempty"`
+	Steps       []GithubActionYAMLStep `yaml:"steps,omitempty"`
+	Concurrency map[string]string      `yaml:"concurrency,omitempty"`
 }
 }
 
 
 type GithubActionYAML struct {
 type GithubActionYAML struct {

+ 6 - 131
internal/integrations/ci/actions/preview.go

@@ -73,12 +73,6 @@ func SetupEnv(opts *EnvOpts) error {
 		return err
 		return err
 	}
 	}
 
 
-	deleteWorkflowYAML, err := getPreviewDeleteActionYAML(opts)
-
-	if err != nil {
-		return err
-	}
-
 	githubBranch, _, err := opts.Client.Repositories.GetBranch(
 	githubBranch, _, err := opts.Client.Repositories.GetBranch(
 		context.Background(), opts.GitRepoOwner, opts.GitRepoName, defaultBranch, true,
 		context.Background(), opts.GitRepoOwner, opts.GitRepoName, defaultBranch, true,
 	)
 	)
@@ -95,8 +89,8 @@ func SetupEnv(opts *EnvOpts) error {
 				"Unable to create PR to merge workflow files into protected branch: %s.\n"+
 				"Unable to create PR to merge workflow files into protected branch: %s.\n"+
 					"To enable Porter Preview Environment deployments, please create Github workflow "+
 					"To enable Porter Preview Environment deployments, please create Github workflow "+
 					"files in this branch with the following contents:\n"+
 					"files in this branch with the following contents:\n"+
-					"--------\n%s--------\n--------\n%s--------\nERROR: %w",
-				defaultBranch, string(applyWorkflowYAML), string(deleteWorkflowYAML), ErrCreatePRForProtectedBranch,
+					"--------\n%s--------\nERROR: %w",
+				defaultBranch, string(applyWorkflowYAML), ErrCreatePRForProtectedBranch,
 			)
 			)
 		}
 		}
 
 
@@ -112,25 +106,8 @@ func SetupEnv(opts *EnvOpts) error {
 				"Unable to create PR to merge workflow files into protected branch: %s.\n"+
 				"Unable to create PR to merge workflow files into protected branch: %s.\n"+
 					"To enable Porter Preview Environment deployments, please create Github workflow "+
 					"To enable Porter Preview Environment deployments, please create Github workflow "+
 					"files in this branch with the following contents:\n"+
 					"files in this branch with the following contents:\n"+
-					"--------\n%s--------\n--------\n%s--------\nERROR: %w",
-				defaultBranch, string(applyWorkflowYAML), string(deleteWorkflowYAML), ErrCreatePRForProtectedBranch,
-			)
-		}
-
-		_, err = commitWorkflowFile(
-			opts.Client,
-			fmt.Sprintf("porter_%s_delete_env.yml", strings.ToLower(opts.EnvironmentName)),
-			deleteWorkflowYAML, opts.GitRepoOwner,
-			opts.GitRepoName, "porter-preview", false,
-		)
-
-		if err != nil {
-			return fmt.Errorf(
-				"Unable to create PR to merge workflow files into protected branch: %s.\n"+
-					"To enable Porter Preview Environment deployments, please create a Github workflow "+
-					"file in this branch with the following contents:\n"+
 					"--------\n%s--------\nERROR: %w",
 					"--------\n%s--------\nERROR: %w",
-				defaultBranch, string(deleteWorkflowYAML), ErrCreatePRForProtectedBranch,
+				defaultBranch, string(applyWorkflowYAML), ErrCreatePRForProtectedBranch,
 			)
 			)
 		}
 		}
 
 
@@ -160,75 +137,6 @@ func SetupEnv(opts *EnvOpts) error {
 		false,
 		false,
 	)
 	)
 
 
-	if err != nil {
-		if strings.Contains(err.Error(), "409 Could not create file") {
-			// possibly a write-protected branch
-			err = createNewBranch(opts.Client, opts.GitRepoOwner, opts.GitRepoName, defaultBranch, "porter-preview")
-
-			if err != nil {
-				return fmt.Errorf("write-protected branch %s. Error creating porter-preview branch: %w", defaultBranch, err)
-			}
-
-			_, err = commitWorkflowFile(
-				opts.Client,
-				fmt.Sprintf("porter_%s_env.yml", strings.ToLower(opts.EnvironmentName)),
-				applyWorkflowYAML,
-				opts.GitRepoOwner,
-				opts.GitRepoName,
-				"porter-preview",
-				false,
-			)
-
-			if err != nil {
-				return fmt.Errorf("write-protected branch %s. Error committing to porter-preview branch: %w", defaultBranch, err)
-			}
-
-			_, err = commitWorkflowFile(
-				opts.Client,
-				fmt.Sprintf("porter_%s_delete_env.yml", strings.ToLower(opts.EnvironmentName)),
-				deleteWorkflowYAML,
-				opts.GitRepoOwner,
-				opts.GitRepoName,
-				"porter-preview",
-				false,
-			)
-
-			if err != nil {
-				return fmt.Errorf("write-protected branch %s. Error committing to porter-preview branch: %w", defaultBranch, err)
-			}
-
-			pr, _, err := opts.Client.PullRequests.Create(
-				context.Background(), opts.GitRepoOwner, opts.GitRepoName, &github.NewPullRequest{
-					Title: github.String("Merge Porter preview environment Github Actions workflow files"),
-					Base:  github.String(defaultBranch),
-					Head:  github.String("porter-preview"),
-				},
-			)
-
-			if err != nil {
-				return err
-			}
-
-			return fmt.Errorf("write-protected branch %s. Please merge %s to enable preview environment for your repository", defaultBranch, pr.GetURL())
-		}
-
-		return err
-	}
-
-	_, err = commitWorkflowFile(
-		opts.Client,
-		fmt.Sprintf("porter_%s_delete_env.yml", strings.ToLower(opts.EnvironmentName)),
-		deleteWorkflowYAML,
-		opts.GitRepoOwner,
-		opts.GitRepoName,
-		defaultBranch,
-		false,
-	)
-
-	if err != nil {
-		return err
-	}
-
 	return err
 	return err
 }
 }
 
 
@@ -349,43 +257,10 @@ func getPreviewApplyActionYAML(opts *EnvOpts) ([]byte, error) {
 		Jobs: map[string]GithubActionYAMLJob{
 		Jobs: map[string]GithubActionYAMLJob{
 			"porter-preview": {
 			"porter-preview": {
 				RunsOn: "ubuntu-latest",
 				RunsOn: "ubuntu-latest",
-				Steps:  gaSteps,
-			},
-		},
-	}
-
-	return yaml.Marshal(actionYAML)
-}
-
-func getPreviewDeleteActionYAML(opts *EnvOpts) ([]byte, error) {
-	gaSteps := []GithubActionYAMLStep{
-		getDeletePreviewEnvStep(
-			opts.ServerURL,
-			getPorterTokenSecretName(opts.ProjectID),
-			opts.ProjectID,
-			opts.ClusterID,
-			opts.GitRepoName,
-			"v0.2.0",
-		),
-	}
-
-	actionYAML := GithubActionYAML{
-		On: map[string]interface{}{
-			"workflow_dispatch": map[string]interface{}{
-				"inputs": map[string]interface{}{
-					"deployment_id": map[string]interface{}{
-						"description": "Deployment ID",
-						"type":        "number",
-						"required":    true,
-					},
+				Concurrency: map[string]string{
+					"group": "${{ github.workflow }}-${{ github.event.inputs.pr_number }}",
 				},
 				},
-			},
-		},
-		Name: "Porter Preview Environment",
-		Jobs: map[string]GithubActionYAMLJob{
-			"porter-delete-preview": {
-				RunsOn: "ubuntu-latest",
-				Steps:  gaSteps,
+				Steps: gaSteps,
 			},
 			},
 		},
 		},
 	}
 	}

+ 0 - 16
internal/integrations/ci/actions/steps.go

@@ -7,7 +7,6 @@ import (
 
 
 const updateAppActionName = "porter-dev/porter-update-action"
 const updateAppActionName = "porter-dev/porter-update-action"
 const createPreviewActionName = "porter-dev/porter-preview-action"
 const createPreviewActionName = "porter-dev/porter-preview-action"
-const deletePreviewActionName = "porter-dev/porter-delete-preview-action"
 
 
 func getCheckoutCodeStep() GithubActionYAMLStep {
 func getCheckoutCodeStep() GithubActionYAMLStep {
 	return GithubActionYAMLStep{
 	return GithubActionYAMLStep{
@@ -68,18 +67,3 @@ func getCreatePreviewEnvStep(
 		Timeout: 30,
 		Timeout: 30,
 	}
 	}
 }
 }
-
-func getDeletePreviewEnvStep(serverURL, porterTokenSecretName string, projectID, clusterID uint, repoName, actionVersion string) GithubActionYAMLStep {
-	return GithubActionYAMLStep{
-		Name: "Delete Porter preview env",
-		Uses: fmt.Sprintf("%s@%s", deletePreviewActionName, actionVersion),
-		With: map[string]string{
-			"cluster":       fmt.Sprintf("%d", clusterID),
-			"host":          serverURL,
-			"project":       fmt.Sprintf("%d", projectID),
-			"token":         fmt.Sprintf("${{ secrets.%s }}", porterTokenSecretName),
-			"deployment_id": "${{ github.event.inputs.deployment_id }}",
-		},
-		Timeout: 30,
-	}
-}

+ 8 - 9
internal/repository/gorm/environment.go

@@ -29,9 +29,8 @@ func (repo *EnvironmentRepository) CreateEnvironment(env *models.Environment) (*
 func (repo *EnvironmentRepository) ReadEnvironment(projectID, clusterID, gitInstallationID uint, gitRepoOwner, gitRepoName string) (*models.Environment, error) {
 func (repo *EnvironmentRepository) ReadEnvironment(projectID, clusterID, gitInstallationID uint, gitRepoOwner, gitRepoName string) (*models.Environment, error) {
 	env := &models.Environment{}
 	env := &models.Environment{}
 	if err := repo.db.Order("id desc").Where(
 	if err := repo.db.Order("id desc").Where(
-		"project_id = ? AND cluster_id = ? AND git_installation_id = ? AND git_repo_owner = LOWER(?) AND git_repo_name = LOWER(?)",
-		projectID, clusterID, gitInstallationID,
-		strings.ToLower(gitRepoOwner), strings.ToLower(gitRepoName),
+		"project_id = ? AND cluster_id = ? AND git_installation_id = ? AND git_repo_owner iLIKE ? AND git_repo_name iLIKE ?",
+		projectID, clusterID, gitInstallationID, gitRepoOwner, gitRepoName,
 	).First(&env).Error; err != nil {
 	).First(&env).Error; err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
@@ -56,8 +55,8 @@ func (repo *EnvironmentRepository) ReadEnvironmentByOwnerRepoName(
 	gitRepoOwner, gitRepoName string,
 	gitRepoOwner, gitRepoName string,
 ) (*models.Environment, error) {
 ) (*models.Environment, error) {
 	env := &models.Environment{}
 	env := &models.Environment{}
-	if err := repo.db.Order("id desc").Where("project_id = ? AND cluster_id = ? AND git_repo_owner = LOWER(?) AND git_repo_name = LOWER(?)",
-		projectID, clusterID, strings.ToLower(gitRepoOwner), strings.ToLower(gitRepoName),
+	if err := repo.db.Order("id desc").Where("project_id = ? AND cluster_id = ? AND git_repo_owner iLIKE ? AND git_repo_name iLIKE ?",
+		projectID, clusterID, gitRepoOwner, gitRepoName,
 	).First(&env).Error; err != nil {
 	).First(&env).Error; err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
@@ -68,8 +67,8 @@ func (repo *EnvironmentRepository) ReadEnvironmentByWebhookIDOwnerRepoName(
 	webhookID, gitRepoOwner, gitRepoName string,
 	webhookID, gitRepoOwner, gitRepoName string,
 ) (*models.Environment, error) {
 ) (*models.Environment, error) {
 	env := &models.Environment{}
 	env := &models.Environment{}
-	if err := repo.db.Order("id desc").Where("webhook_id = ? AND git_repo_owner = LOWER(?) AND git_repo_name = LOWER(?)",
-		webhookID, strings.ToLower(gitRepoOwner), strings.ToLower(gitRepoName),
+	if err := repo.db.Order("id desc").Where("webhook_id = ? AND git_repo_owner iLIKE ? AND git_repo_name iLIKE ?",
+		webhookID, gitRepoOwner, gitRepoName,
 	).First(&env).Error; err != nil {
 	).First(&env).Error; err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
@@ -149,8 +148,8 @@ func (repo *EnvironmentRepository) ReadDeploymentByGitDetails(
 	depl := &models.Deployment{}
 	depl := &models.Deployment{}
 
 
 	if err := repo.db.Order("id asc").
 	if err := repo.db.Order("id asc").
-		Where("environment_id = ? AND repo_owner = LOWER(?) AND repo_name = LOWER(?) AND pull_request_id = ?",
-			environmentID, strings.ToLower(gitRepoOwner), strings.ToLower(gitRepoName), prNumber).
+		Where("environment_id = ? AND repo_owner iLIKE ? AND repo_name iLIKE ? AND pull_request_id = ?",
+			environmentID, gitRepoOwner, gitRepoName, prNumber).
 		First(&depl).Error; err != nil {
 		First(&depl).Error; err != nil {
 		return nil, err
 		return nil, err
 	}
 	}