Skip to content

Commit

Permalink
Warn if function conditions are not met (#224)
Browse files Browse the repository at this point in the history
* Warn if function conditions are not met

* Change signature to be more structured
  • Loading branch information
mraerino authored Apr 15, 2020
1 parent e76c507 commit fc80f78
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions go/porcelain/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ type DeployObserver interface {
OnFailedUpload(*FileBundle)
}

type DeployWarner interface {
OnWalkWarning(path, msg string)
}

// DeployOptions holds the option for creating a new deploy
type DeployOptions struct {
SiteID string
Expand Down Expand Up @@ -579,12 +583,16 @@ 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(filePath, "Function is not valid for deployment. Please check that it matches the format for the runtime.")
}
}
}

Expand Down Expand Up @@ -653,17 +661,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(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(filePath, "Go binary is not a linux executable")
}
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(filePath, "Unable to detect Go version 1.x")
}
}

return true
}

func ignoreFile(rel string) bool {
Expand Down

0 comments on commit fc80f78

Please sign in to comment.