Skip to content

Commit

Permalink
support missing porter.yaml (#3592)
Browse files Browse the repository at this point in the history
Co-authored-by: David Townley <[email protected]>
  • Loading branch information
d-g-town and David Townley authored Sep 20, 2023
1 parent 5057b95 commit 6fca050
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion cli/cmd/v2/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,22 @@ func Apply(ctx context.Context, cliConf config.CLIConfig, client api.Client, por
return errors.New("deployment target id is empty")
}

if len(porterYamlPath) != 0 {
porterYamlExists := len(porterYamlPath) != 0

if porterYamlExists {
_, err = os.Stat(filepath.Clean(porterYamlPath))
if err != nil {
if !os.IsNotExist(err) {
return fmt.Errorf("error checking if porter yaml exists at path %s: %w", porterYamlPath, err)
}
// If a path was specified but the file does not exist, we will not immediately error out.
// This supports users migrated from v1 who use a workflow file that always specifies a porter yaml path
// in the apply command.
porterYamlExists = false
}
}

if porterYamlExists {
porterYaml, err := os.ReadFile(filepath.Clean(porterYamlPath))
if err != nil {
return fmt.Errorf("could not read porter yaml file: %w", err)
Expand Down Expand Up @@ -87,6 +102,10 @@ func Apply(ctx context.Context, cliConf config.CLIConfig, client api.Client, por
color.New(color.FgGreen).Printf("Successfully parsed Porter YAML: applying app \"%s\"\n", appName) // nolint:errcheck,gosec
}

if appName == "" {
return errors.New("App name is empty. Please provide a Porter YAML file specifying the name of the app or set the PORTER_APP_NAME environment variable.")
}

var commitSHA string
if os.Getenv("PORTER_COMMIT_SHA") != "" {
commitSHA = os.Getenv("PORTER_COMMIT_SHA")
Expand Down

0 comments on commit 6fca050

Please sign in to comment.