Skip to content

Commit

Permalink
Fixes lint setup to skip embedded tinygo examples (#138)
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <adrian@tetrate.io>
  • Loading branch information
codefromthecrypt authored Mar 26, 2021
1 parent 4f89255 commit 26b60a1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
10 changes: 1 addition & 9 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@ run:
# timeout for analysis, e.g. 30s, 5m, default is 1m
deadline: 5m

# which dirs to skip: they won't be analyzed;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but next dirs are always skipped independently
# from this option's value:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs:
- pkg/binary/envoytest
- vendor$

# If invoked with -mod=readonly, the go command is disallowed from the implicit
# automatic updating of go.mod described above. Instead, it fails when any changes
# to go.mod are needed. This setting is most useful to check that go.mod does
Expand Down Expand Up @@ -141,6 +132,7 @@ issues:
- errcheck
- dupl
- gosec
- lll

# Exclude lll issues for long lines with go:generate
- linters:
Expand Down
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ lint: generate $(GOLANGCI_LINT) $(SHFMT) $(LICENSER) .golangci.yml ## Run the l
@echo "--- lint ---"
@$(SHFMT) -d .
@$(LICENSER) verify -r .
@$(GOLANGCI_LINT) run $(LINT_OPTS) --config .golangci.yml
# We skip tinygo templates which will fail lint. Since skip-dirs does not apply to go modules, we externally filter.
# See https://github.com/golangci/golangci-lint/issues/301#issuecomment-441311986 for explanation.
@go list -f "{{.Dir}}" ./... | grep -v "/tinygo/" | xargs $(GOLANGCI_LINT) run $(LINT_OPTS) --config .golangci.yml

# The goimports tool does not arrange imports in 3 blocks if there are already more than three blocks.
# To avoid that, before running it, we collapse all imports in one block, then run the formatter.
Expand Down Expand Up @@ -231,6 +233,7 @@ check: ## CI blocks merge until this passes. If this fails, run "make check" lo
fi

.PHONY: clean
clean: ## Clean all binaries
clean: $(GOLANGCI_LINT) ## Clean all binaries
@echo "--- $@ ---"
go clean -testcache
@go clean -testcache
@$(GOLANGCI_LINT) cache clean
11 changes: 9 additions & 2 deletions pkg/binary/envoytest/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"time"

"github.com/mholt/archiver"
"github.com/tetratelabs/log"

"github.com/tetratelabs/getenvoy/pkg/binary"
"github.com/tetratelabs/getenvoy/pkg/binary/envoy"
Expand Down Expand Up @@ -55,7 +56,11 @@ func Run(ctx context.Context, r binary.Runner, bootstrap string) error {
if bootstrap != "" {
args = append(args, "-c", bootstrap)
}
go r.Run(key, args)
go func() {
if err := r.Run(key, args); err != nil {
log.Errorf("unable to run key %s: %v", key, err)
}
}()
r.WaitWithContext(ctx, binary.StatusReady)
return ctx.Err()
}
Expand All @@ -65,7 +70,9 @@ func Run(ctx context.Context, r binary.Runner, bootstrap string) error {
func Kill(ctx context.Context, r binary.Runner) error {
r.SendSignal(syscall.SIGINT)
r.WaitWithContext(ctx, binary.StatusTerminated)
archiver.Unarchive(r.DebugStore()+".tar.gz", filepath.Dir(r.DebugStore()))
if err := archiver.Unarchive(r.DebugStore()+".tar.gz", filepath.Dir(r.DebugStore())); err != nil {
return fmt.Errorf("error killing runner: %w", err)
}
return ctx.Err()
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/extension/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ func (s *scaffolder) walk(sourceDirName, destinationDirName string) (errs error)
}

func (s *scaffolder) visit(sourceDirName, destinationDirName string, sourceFileInfo os.FileInfo) (errs error) {
relOutputFileName := filepath.Join(destinationDirName, sourceFileInfo.Name())
baseOutputFileName := sourceFileInfo.Name()
// We rename go.mod to go.mod_ to workaround https://github.com/golang/go/issues/45197
if baseOutputFileName == "go.mod_" {
baseOutputFileName = "go.mod"
}
relOutputFileName := filepath.Join(destinationDirName, baseOutputFileName)
outputFileName := filepath.Join(s.opts.OutputDir, relOutputFileName)
if err := osutil.EnsureDirExists(filepath.Dir(outputFileName)); err != nil {
return err
Expand Down
9 changes: 6 additions & 3 deletions pkg/extension/workspace/toolchain/builtin/toolchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var (
)

// NewToolchain returns a builtin toolchain with a given configuration.
func NewToolchain(name string, cfg *config.ToolchainConfig, workspace model.Workspace) *builtin {
func NewToolchain(name string, cfg *config.ToolchainConfig, workspace model.Workspace) *builtin { //nolint
return &builtin{name: name, cfg: cfg, workspace: workspace}
}

Expand All @@ -63,6 +63,7 @@ func (t *builtin) Build(context types.BuildContext) error {
if err != nil {
return err
}
// #nosec -> the current design is an argument builder, not arg literals
cmd := exec.Command("docker", args.Add(commandBuild).Add("--output-file", t.cfg.GetBuildOutputWasmFile())...)
return executil.Run(cmd, context.IO)
}
Expand All @@ -72,6 +73,7 @@ func (t *builtin) Test(context types.TestContext) error {
if err != nil {
return err
}
// #nosec -> the current design is an argument builder, not arg literals
cmd := exec.Command("docker", args.Add(commandTest)...)
return executil.Run(cmd, context.IO)
}
Expand All @@ -81,18 +83,19 @@ func (t *builtin) Clean(context types.CleanContext) error {
if err != nil {
return err
}
// #nosec -> the current design is an argument builder, not arg literals
cmd := exec.Command("docker", args.Add(commandClean)...)
return executil.Run(cmd, context.IO)
}

func (t *builtin) dockerCliArgs(container *config.ContainerConfig) (executil.Args, error) {
user, err := GetCurrentUser()
u, err := GetCurrentUser()
if err != nil {
return nil, err
}
return executil.Args{
"run",
"-u", fmt.Sprintf("%s:%s", user.Uid, user.Gid), // to get proper ownership on files created by the container
"-u", fmt.Sprintf("%s:%s", u.Uid, u.Gid), // to get proper ownership on files created by the container
"--rm",
"-t", // to get interactive/colored output out of container
"-v", fmt.Sprintf("%s:%s", t.workspace.GetDir().GetRootDir(), "/source"),
Expand Down

0 comments on commit 26b60a1

Please sign in to comment.