From ecd87087a24a5a746bc9bfa0b76382dad6ac2b86 Mon Sep 17 00:00:00 2001 From: Marcus Weiner Date: Tue, 14 Apr 2020 13:24:22 +0200 Subject: [PATCH 1/2] Warn if function conditions are not met --- go/porcelain/deploy.go | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/go/porcelain/deploy.go b/go/porcelain/deploy.go index 9aa743a5..cb7cd152 100644 --- a/go/porcelain/deploy.go +++ b/go/porcelain/deploy.go @@ -62,6 +62,10 @@ type DeployObserver interface { OnFailedUpload(*FileBundle) } +type DeployWarner interface { + OnWalkWarning(string) +} + // DeployOptions holds the option for creating a new deploy type DeployOptions struct { SiteID string @@ -579,12 +583,18 @@ func bundle(functionDir string, observer DeployObserver) (*deployFiles, error) { return nil, err } functions.Add(file.Name, file) - case goFile(filePath, i): + case goFile(filePath, i, observer): file, err := newFunctionFile(filePath, i, goRuntime, observer) if err != nil { return nil, err } functions.Add(file.Name, file) + default: + if warner, ok := observer.(DeployWarner); ok { + warner.OnWalkWarning( + fmt.Sprintf("Function \"%s\" is not valid for deployment. Please check that it matches the format for the runtime.", filePath), + ) + } } } @@ -653,17 +663,31 @@ func jsFile(i os.FileInfo) bool { return filepath.Ext(i.Name()) == ".js" } -func goFile(filePath string, i os.FileInfo) bool { +func goFile(filePath string, i os.FileInfo, observer DeployObserver) bool { + warner, hasWarner := observer.(DeployWarner) + if m := i.Mode(); m&0111 == 0 { // check if it's an executable file + if hasWarner { + warner.OnWalkWarning(fmt.Sprintf("%s: Go binary does not have executable permissions", filePath)) + } return false } if _, err := elf.Open(filePath); err != nil { // check if it's a linux executable + if hasWarner { + warner.OnWalkWarning(fmt.Sprintf("%s: Go binary is not a linux executable", filePath)) + } return false } v, err := version.ReadExe(filePath) - return err == nil && strings.HasPrefix(v.Release, "go1.") + if err != nil || !strings.HasPrefix(v.Release, "go1.") { + if hasWarner { + warner.OnWalkWarning(fmt.Sprintf("%s: Unable to detect Go version 1.x", filePath)) + } + } + + return true } func ignoreFile(rel string) bool { From 337aa0772f7980b464c7de70902cc1351a4d1e0a Mon Sep 17 00:00:00 2001 From: Marcus Weiner Date: Tue, 14 Apr 2020 13:35:33 +0200 Subject: [PATCH 2/2] Change signature to be more structured --- go/porcelain/deploy.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/go/porcelain/deploy.go b/go/porcelain/deploy.go index cb7cd152..1409b87e 100644 --- a/go/porcelain/deploy.go +++ b/go/porcelain/deploy.go @@ -63,7 +63,7 @@ type DeployObserver interface { } type DeployWarner interface { - OnWalkWarning(string) + OnWalkWarning(path, msg string) } // DeployOptions holds the option for creating a new deploy @@ -591,9 +591,7 @@ func bundle(functionDir string, observer DeployObserver) (*deployFiles, error) { functions.Add(file.Name, file) default: if warner, ok := observer.(DeployWarner); ok { - warner.OnWalkWarning( - fmt.Sprintf("Function \"%s\" is not valid for deployment. Please check that it matches the format for the runtime.", filePath), - ) + warner.OnWalkWarning(filePath, "Function is not valid for deployment. Please check that it matches the format for the runtime.") } } } @@ -668,14 +666,14 @@ func goFile(filePath string, i os.FileInfo, observer DeployObserver) bool { if m := i.Mode(); m&0111 == 0 { // check if it's an executable file if hasWarner { - warner.OnWalkWarning(fmt.Sprintf("%s: Go binary does not have executable permissions", filePath)) + warner.OnWalkWarning(filePath, "Go binary does not have executable permissions") } return false } if _, err := elf.Open(filePath); err != nil { // check if it's a linux executable if hasWarner { - warner.OnWalkWarning(fmt.Sprintf("%s: Go binary is not a linux executable", filePath)) + warner.OnWalkWarning(filePath, "Go binary is not a linux executable") } return false } @@ -683,7 +681,7 @@ func goFile(filePath string, i os.FileInfo, observer DeployObserver) bool { v, err := version.ReadExe(filePath) if err != nil || !strings.HasPrefix(v.Release, "go1.") { if hasWarner { - warner.OnWalkWarning(fmt.Sprintf("%s: Unable to detect Go version 1.x", filePath)) + warner.OnWalkWarning(filePath, "Unable to detect Go version 1.x") } }