Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: dont fail if there is a .go directory (#1899)
Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Nov 13, 2020
1 parent 707639f commit 40aa04f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/builders/golang/build.go
Expand Up @@ -227,7 +227,7 @@ func checkMain(build config.Build) error {
return ferr
}
if stat.IsDir() {
packs, err := parser.ParseDir(token.NewFileSet(), main, nil, 0)
packs, err := parser.ParseDir(token.NewFileSet(), main, fileFilter, 0)
if err != nil {
return fmt.Errorf("failed to parse dir: %s: %w", main, err)
}
Expand All @@ -250,6 +250,10 @@ func checkMain(build config.Build) error {
return fmt.Errorf("build for %s does not contain a main function", build.Binary)
}

func fileFilter(info os.FileInfo) bool {
return !info.IsDir()
}

func hasMain(file *ast.File) bool {
for _, decl := range file.Decls {
fn, isFn := decl.(*ast.FuncDecl)
Expand Down
27 changes: 27 additions & 0 deletions internal/builders/golang/build_test.go
Expand Up @@ -342,6 +342,33 @@ func TestBuildCodeInSubdir(t *testing.T) {
require.NoError(t, err)
}

func TestBuildWithDotGoDir(t *testing.T) {
folder, back := testlib.Mktmp(t)
defer back()
require.NoError(t, os.Mkdir(filepath.Join(folder, ".go"), 0755))
writeGoodMain(t, folder)
var config = config.Project{
Builds: []config.Build{
{
ID: "foo",
Env: []string{"GO111MODULE=off"},
Binary: "foo",
Targets: []string{runtimeTarget},
GoBinary: "go",
},
},
}
var ctx = context.New(config)
ctx.Git.CurrentTag = "5.6.7"
var build = ctx.Config.Builds[0]
require.NoError(t, Default.Build(ctx, build, api.Options{
Target: runtimeTarget,
Name: build.Binary,
Path: filepath.Join(folder, "dist", runtimeTarget, build.Binary),
Ext: "",
}))
}

func TestBuildFailed(t *testing.T) {
folder, back := testlib.Mktmp(t)
defer back()
Expand Down

1 comment on commit 40aa04f

@vercel
Copy link

@vercel vercel bot commented on 40aa04f Nov 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.