Skip to content

Commit

Permalink
ci: add linting for go.mod (again)
Browse files Browse the repository at this point in the history
Looks like this accidentally got removed (by me) during our
modularization refactoring, and we got a weird `go.mod`. So, I'm
bringing it back!

Signed-off-by: Justin Chadwell <[email protected]>
  • Loading branch information
jedevc committed Apr 30, 2024
1 parent 1108c9e commit be9115f
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 27 deletions.
5 changes: 1 addition & 4 deletions ci/docs.go
Expand Up @@ -50,10 +50,7 @@ func (d Docs) Lint(ctx context.Context) error {
})

eg.Go(func() error {
return util.DiffDirectoryF(ctx, generatedSchemaPath, d.Dagger.Source, d.Generate)
})
eg.Go(func() error {
return util.DiffDirectoryF(ctx, generatedCliZenPath, d.Dagger.Source, d.Generate)
return util.DiffDirectoryF(ctx, d.Dagger.Source, d.Generate, generatedSchemaPath, generatedCliZenPath)
})

// Go is already linted by engine:lint
Expand Down
26 changes: 19 additions & 7 deletions ci/engine.go
Expand Up @@ -124,24 +124,36 @@ func (e *Engine) Lint(
// +optional
all bool,
) error {
eg, ctx := errgroup.WithContext(ctx)

pkgs := []string{""}
// pkgs := []string{"", "ci"}

ctr := dag.Container().
From(consts.GolangLintImage).
WithMountedDirectory("/app", util.GoDirectory(e.Dagger.Source))

cmd := []string{"golangci-lint", "run", "-v", "--timeout", "5m"}
if all {
cmd = append(cmd, "--max-issues-per-linter=0", "--max-same-issues=0")
}
for _, pkg := range pkgs {
ctr = ctr.
golangci := dag.Container().
From(consts.GolangLintImage).
WithMountedDirectory("/app", util.GoDirectory(e.Dagger.Source)).
WithWorkdir(path.Join("/app", pkg)).
WithExec(cmd)
eg.Go(func() error {
_, err := golangci.Sync(ctx)
return err
})

eg.Go(func() error {
return util.DiffDirectoryF(ctx, util.GoDirectory(e.Dagger.Source), func(ctx context.Context) (*dagger.Directory, error) {
return util.GoBase(e.Dagger.Source).
WithExec([]string{"go", "mod", "tidy"}).
Directory("."), nil
}, "go.mod", "go.sum")
})
}
_, err := ctr.Sync(ctx)
return err

return eg.Wait()
}

// Publish all engine images to a registry
Expand Down
2 changes: 1 addition & 1 deletion ci/sdk_go.go
Expand Up @@ -30,7 +30,7 @@ func (t GoSDK) Lint(ctx context.Context) error {
return err
})
eg.Go(func() error {
return util.DiffDirectoryF(ctx, "sdk/go", util.GoDirectory(t.Dagger.Source), t.Generate)
return util.DiffDirectoryF(ctx, util.GoDirectory(t.Dagger.Source), t.Generate, "sdk/go")
})
return eg.Wait()
}
Expand Down
2 changes: 1 addition & 1 deletion ci/sdk_php.go
Expand Up @@ -22,7 +22,7 @@ type PHPSDK struct {

// Lint the PHP SDK
func (t PHPSDK) Lint(ctx context.Context) error {
return util.DiffDirectoryF(ctx, filepath.Join(phpSDKPath, phpSDKGeneratedDir), t.Dagger.Source, t.Generate)
return util.DiffDirectoryF(ctx, t.Dagger.Source, t.Generate, filepath.Join(phpSDKPath, phpSDKGeneratedDir))
}

// Test the PHP SDK
Expand Down
2 changes: 1 addition & 1 deletion ci/sdk_python.go
Expand Up @@ -53,7 +53,7 @@ func (t PythonSDK) Lint(ctx context.Context) error {
})

eg.Go(func() error {
return util.DiffDirectoryF(ctx, pythonGeneratedAPIPath, t.Dagger.Source, t.Generate)
return util.DiffDirectoryF(ctx, t.Dagger.Source, t.Generate, pythonGeneratedAPIPath)
})

return eg.Wait()
Expand Down
2 changes: 1 addition & 1 deletion ci/sdk_rust.go
Expand Up @@ -44,7 +44,7 @@ func (r RustSDK) Lint(ctx context.Context) error {
})

eg.Go(func() error {
return util.DiffDirectoryF(ctx, "sdk/rust", r.Dagger.Source, r.Generate)
return util.DiffDirectoryF(ctx, r.Dagger.Source, r.Generate, "sdk/rust")
})

return eg.Wait()
Expand Down
2 changes: 1 addition & 1 deletion ci/sdk_typescript.go
Expand Up @@ -62,7 +62,7 @@ func (t TypescriptSDK) Lint(ctx context.Context) error {
})

eg.Go(func() error {
return util.DiffDirectoryF(ctx, typescriptGeneratedAPIPath, t.Dagger.Source, t.Generate)
return util.DiffDirectoryF(ctx, t.Dagger.Source, t.Generate, typescriptGeneratedAPIPath)
})

return eg.Wait()
Expand Down
22 changes: 14 additions & 8 deletions ci/util/diff.go
Expand Up @@ -7,21 +7,27 @@ import (
"github.com/dagger/dagger/ci/internal/dagger"
)

func DiffDirectory(ctx context.Context, path string, original *dagger.Directory, modified *dagger.Directory) error {
_, err := dag.Container().
func DiffDirectory(ctx context.Context, original *dagger.Directory, modified *dagger.Directory, paths ...string) error {
ctr := dag.Container().
From("alpine").
WithMountedDirectory("/mnt/original", original).
WithMountedDirectory("/mnt/modified", modified).
WithWorkdir("/mnt").
WithExec([]string{"diff", "-r", filepath.Join("original", path), filepath.Join("modified", path)}).
Sync(ctx)
return err
WithWorkdir("/mnt")
for _, path := range paths {
_, err := ctr.
WithExec([]string{"diff", "-r", filepath.Join("original", path), filepath.Join("modified", path)}).
Sync(ctx)
if err != nil {
return err
}
}
return nil
}

func DiffDirectoryF(ctx context.Context, path string, original *dagger.Directory, modifiedF func(context.Context) (*dagger.Directory, error)) error {
func DiffDirectoryF(ctx context.Context, original *dagger.Directory, modifiedF func(context.Context) (*dagger.Directory, error), paths ...string) error {
modified, err := modifiedF(ctx)
if err != nil {
return err
}
return DiffDirectory(ctx, path, original, modified)
return DiffDirectory(ctx, original, modified, paths...)
}
6 changes: 3 additions & 3 deletions go.mod
Expand Up @@ -20,6 +20,7 @@ require (
github.com/containerd/containerd v1.7.15-0.20240329193453-0dcf21c1528a
github.com/containerd/continuity v0.4.3
github.com/containerd/fuse-overlayfs-snapshotter v1.0.8
github.com/containerd/go-runc v1.1.0
github.com/containerd/stargz-snapshotter v0.15.1
github.com/containernetworking/cni v1.1.2
github.com/coreos/go-systemd/v22 v22.5.0
Expand Down Expand Up @@ -50,6 +51,7 @@ require (
github.com/moby/locker v1.0.1
github.com/moby/patternmatcher v0.6.0
github.com/moby/sys/mount v0.3.3
github.com/moby/sys/signal v0.7.0
github.com/muesli/reflow v0.3.0
github.com/muesli/termenv v0.15.2
github.com/opencontainers/go-digest v1.0.0
Expand Down Expand Up @@ -77,6 +79,7 @@ require (
github.com/vito/midterm v0.1.5-0.20240307214207-d0271a7ca452
github.com/vito/progrock v0.10.2-0.20240221152222-63c8df30db8d
github.com/zeebo/xxh3 v1.0.2
go.etcd.io/bbolt v1.3.9
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0
go.opentelemetry.io/otel v1.24.0
Expand Down Expand Up @@ -147,7 +150,6 @@ require (
github.com/containerd/cgroups v1.1.0 // indirect
github.com/containerd/fifo v1.1.0 // indirect
github.com/containerd/go-cni v1.1.9 // indirect
github.com/containerd/go-runc v1.1.0 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/nydus-snapshotter v0.13.7 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.15.1 // indirect
Expand Down Expand Up @@ -206,7 +208,6 @@ require (
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/sys/mountinfo v0.7.1 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/signal v0.7.0 // indirect
github.com/moby/sys/user v0.1.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
Expand Down Expand Up @@ -240,7 +241,6 @@ require (
github.com/vishvananda/netns v0.0.4 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/zmb3/spotify/v2 v2.3.1 // indirect
go.etcd.io/bbolt v1.3.9 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.46.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.42.0 // indirect
Expand Down

0 comments on commit be9115f

Please sign in to comment.