Skip to content

Commit fc80f78

Browse files
authored
Warn if function conditions are not met (#224)
* Warn if function conditions are not met * Change signature to be more structured
1 parent e76c507 commit fc80f78

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

go/porcelain/deploy.go

+25-3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ type DeployObserver interface {
6262
OnFailedUpload(*FileBundle)
6363
}
6464

65+
type DeployWarner interface {
66+
OnWalkWarning(path, msg string)
67+
}
68+
6569
// DeployOptions holds the option for creating a new deploy
6670
type DeployOptions struct {
6771
SiteID string
@@ -579,12 +583,16 @@ func bundle(functionDir string, observer DeployObserver) (*deployFiles, error) {
579583
return nil, err
580584
}
581585
functions.Add(file.Name, file)
582-
case goFile(filePath, i):
586+
case goFile(filePath, i, observer):
583587
file, err := newFunctionFile(filePath, i, goRuntime, observer)
584588
if err != nil {
585589
return nil, err
586590
}
587591
functions.Add(file.Name, file)
592+
default:
593+
if warner, ok := observer.(DeployWarner); ok {
594+
warner.OnWalkWarning(filePath, "Function is not valid for deployment. Please check that it matches the format for the runtime.")
595+
}
588596
}
589597
}
590598

@@ -653,17 +661,31 @@ func jsFile(i os.FileInfo) bool {
653661
return filepath.Ext(i.Name()) == ".js"
654662
}
655663

656-
func goFile(filePath string, i os.FileInfo) bool {
664+
func goFile(filePath string, i os.FileInfo, observer DeployObserver) bool {
665+
warner, hasWarner := observer.(DeployWarner)
666+
657667
if m := i.Mode(); m&0111 == 0 { // check if it's an executable file
668+
if hasWarner {
669+
warner.OnWalkWarning(filePath, "Go binary does not have executable permissions")
670+
}
658671
return false
659672
}
660673

661674
if _, err := elf.Open(filePath); err != nil { // check if it's a linux executable
675+
if hasWarner {
676+
warner.OnWalkWarning(filePath, "Go binary is not a linux executable")
677+
}
662678
return false
663679
}
664680

665681
v, err := version.ReadExe(filePath)
666-
return err == nil && strings.HasPrefix(v.Release, "go1.")
682+
if err != nil || !strings.HasPrefix(v.Release, "go1.") {
683+
if hasWarner {
684+
warner.OnWalkWarning(filePath, "Unable to detect Go version 1.x")
685+
}
686+
}
687+
688+
return true
667689
}
668690

669691
func ignoreFile(rel string) bool {

0 commit comments

Comments
 (0)