From afbef5bb4a20dba311791807a28057c7175820c0 Mon Sep 17 00:00:00 2001 From: bupd Date: Mon, 10 Feb 2025 07:48:55 +0530 Subject: [PATCH] add mocks check Signed-off-by: bupd --- .dagger/main.go | 23 +++++++++++++++++++++-- .dagger/tests.go | 1 + 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/.dagger/main.go b/.dagger/main.go index 35e4079f856..2aaba278dca 100644 --- a/.dagger/main.go +++ b/.dagger/main.go @@ -274,7 +274,7 @@ func (m *Harbor) registryBuilder(ctx context.Context) *dagger.File { WithEnvVariable("BUILDTAGS", "include_oss include_gcs"). WithEnvVariable("GO111MODULE", "auto"). WithEnvVariable("CGO_ENABLED", "0"). - WithWorkdir("/go/src/github.com/docker"). + WithWorkdir("/go/src/github.com/docker"). WithExec([]string{"git", "clone", "-b", REGISTRY_SRC_TAG, DISTRIBUTION_SRC}). WithWorkdir("distribution"). WithExec([]string{"git", "apply", "/harbor/.dagger/registry/redis.patch"}). @@ -370,7 +370,7 @@ func (m *Harbor) buildBinary(ctx context.Context, platform Platform, pkg Package } func (m *Harbor) buildPortal(ctx context.Context, platform Platform, pkg Package) *dagger.Directory { - fmt.Println("🛠️ Building Harbor Core...") + fmt.Println("🛠️ Building Harbor Portal...") os, arch, err := parsePlatform(string(platform)) if err != nil { log.Fatalf("Error parsing platform: %v", err) @@ -444,3 +444,22 @@ func (m *Harbor) lintAPIs(_ context.Context) *dagger.Directory { return temp } + +// Check for outdated mocks +func (m *Harbor) mocksCheck(_ context.Context) *dagger.Directory { + // script to check if mocks are outdated + script := ` + res=$(git status -s src/ | awk '{ printf("%s\n", $2) }' | egrep .*.go) + if [ -n "$res" ]; then + echo "Mocks of the interface are out of date..." + echo "$res" + exit 1 + fi + ` + + return dag.Container().From("golang:latest"). + WithMountedDirectory("/src", m.Source). + WithWorkdir("/src"). + WithExec([]string{"sh", "-c", script}). + Directory("/src") +} diff --git a/.dagger/tests.go b/.dagger/tests.go index 6676ac49711..33a1d1c9cbe 100644 --- a/.dagger/tests.go +++ b/.dagger/tests.go @@ -24,6 +24,7 @@ func (m *Harbor) Lint(ctx context.Context) (string, error) { func (m *Harbor) lint(ctx context.Context) *dagger.Container { fmt.Println("👀 Running linter.") m.lintAPIs(ctx) + m.mocksCheck(ctx) m.Source = m.genAPIs(ctx) linter := dag.Container(). From("golangci/golangci-lint:"+GOLANGCILINT_VERSION+"-alpine").