From 402938e2164282a383dbea06eafed21f510bafb3 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 25 Jun 2024 12:23:07 +0200 Subject: [PATCH] Exclude mocks from release build (#3831) --- .golangci.yaml | 2 ++ Makefile | 21 +++++++++++---------- pipeline/rpc/mocks/peer.go | 3 +++ pipeline/rpc/peer.go | 2 +- server/forge/forge.go | 2 +- server/forge/mocks/forge.go | 3 +++ server/services/manager.go | 2 +- server/services/mocks/manager.go | 3 +++ server/store/mocks/store.go | 3 +++ server/store/store.go | 2 +- woodpecker-go/woodpecker/interface.go | 2 +- woodpecker-go/woodpecker/mocks/client.go | 3 +++ 12 files changed, 33 insertions(+), 15 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 391282e2c..aaa9d14f0 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -184,3 +184,5 @@ issues: run: timeout: 15m + build-tags: + - test diff --git a/Makefile b/Makefile index bb78f2cc7..b1f7a4f02 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,7 @@ else endif endif +TAGS ?= LDFLAGS := -X go.woodpecker-ci.org/woodpecker/v2/version.Version=${VERSION} STATIC_BUILD ?= true ifeq ($(STATIC_BUILD),true) @@ -162,20 +163,20 @@ lint-ui: ui-dependencies ## Lint UI code (cd web/; pnpm lint --quiet) test-agent: ## Test agent code - go test -race -cover -coverprofile agent-coverage.out -timeout 30s go.woodpecker-ci.org/woodpecker/v2/cmd/agent go.woodpecker-ci.org/woodpecker/v2/agent/... + go test -race -cover -coverprofile agent-coverage.out -timeout 30s -tags 'test $(TAGS)' go.woodpecker-ci.org/woodpecker/v2/cmd/agent go.woodpecker-ci.org/woodpecker/v2/agent/... test-server: ## Test server code - go test -race -cover -coverprofile server-coverage.out -timeout 30s go.woodpecker-ci.org/woodpecker/v2/cmd/server $(shell go list go.woodpecker-ci.org/woodpecker/v2/server/... | grep -v '/store') + go test -race -cover -coverprofile server-coverage.out -timeout 30s -tags 'test $(TAGS)' go.woodpecker-ci.org/woodpecker/v2/cmd/server $(shell go list go.woodpecker-ci.org/woodpecker/v2/server/... | grep -v '/store') test-cli: ## Test cli code - go test -race -cover -coverprofile cli-coverage.out -timeout 30s go.woodpecker-ci.org/woodpecker/v2/cmd/cli go.woodpecker-ci.org/woodpecker/v2/cli/... + go test -race -cover -coverprofile cli-coverage.out -timeout 30s -tags 'test $(TAGS)' go.woodpecker-ci.org/woodpecker/v2/cmd/cli go.woodpecker-ci.org/woodpecker/v2/cli/... test-server-datastore: ## Test server datastore - go test -timeout 120s -run TestMigrate go.woodpecker-ci.org/woodpecker/v2/server/store/... - go test -race -timeout 30s -skip TestMigrate go.woodpecker-ci.org/woodpecker/v2/server/store/... + go test -timeout 120s -tags 'test $(TAGS)' -run TestMigrate go.woodpecker-ci.org/woodpecker/v2/server/store/... + go test -race -timeout 30s -tags 'test $(TAGS)' -skip TestMigrate go.woodpecker-ci.org/woodpecker/v2/server/store/... test-server-datastore-coverage: ## Test server datastore with coverage report - go test -race -cover -coverprofile datastore-coverage.out -timeout 180s go.woodpecker-ci.org/woodpecker/v2/server/store/... + go test -race -cover -coverprofile datastore-coverage.out -timeout 180s -tags 'test $(TAGS)' go.woodpecker-ci.org/woodpecker/v2/server/store/... test-ui: ui-dependencies ## Test UI code (cd web/; pnpm run lint) @@ -184,7 +185,7 @@ test-ui: ui-dependencies ## Test UI code (cd web/; pnpm run test) test-lib: ## Test lib code - go test -race -cover -coverprofile coverage.out -timeout 30s $(shell go list ./... | grep -v '/cmd\|/agent\|/cli\|/server') + go test -race -cover -coverprofile coverage.out -timeout 30s -tags 'test $(TAGS)' $(shell go list ./... | grep -v '/cmd\|/agent\|/cli\|/server') .PHONY: test test: test-agent test-server test-server-datastore test-cli test-lib ## Run all tests @@ -195,13 +196,13 @@ build-ui: ## Build UI (cd web/; pnpm install --frozen-lockfile; pnpm build) build-server: build-ui generate-swagger ## Build server - CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags '${LDFLAGS}' -o ${DIST_DIR}/woodpecker-server${BIN_SUFFIX} go.woodpecker-ci.org/woodpecker/v2/cmd/server + CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -tags '$(TAGS)' -ldflags '${LDFLAGS}' -o ${DIST_DIR}/woodpecker-server${BIN_SUFFIX} go.woodpecker-ci.org/woodpecker/v2/cmd/server build-agent: ## Build agent - CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags '${LDFLAGS}' -o ${DIST_DIR}/woodpecker-agent${BIN_SUFFIX} go.woodpecker-ci.org/woodpecker/v2/cmd/agent + CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -tags '$(TAGS)' -ldflags '${LDFLAGS}' -o ${DIST_DIR}/woodpecker-agent${BIN_SUFFIX} go.woodpecker-ci.org/woodpecker/v2/cmd/agent build-cli: ## Build cli - CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags '${LDFLAGS}' -o ${DIST_DIR}/woodpecker-cli${BIN_SUFFIX} go.woodpecker-ci.org/woodpecker/v2/cmd/cli + CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -tags '$(TAGS)' -ldflags '${LDFLAGS}' -o ${DIST_DIR}/woodpecker-cli${BIN_SUFFIX} go.woodpecker-ci.org/woodpecker/v2/cmd/cli build-tarball: ## Build tar archive mkdir -p ${DIST_DIR} && tar chzvf ${DIST_DIR}/woodpecker-src.tar.gz \ diff --git a/pipeline/rpc/mocks/peer.go b/pipeline/rpc/mocks/peer.go index 3409ca35d..3279e2b3a 100644 --- a/pipeline/rpc/mocks/peer.go +++ b/pipeline/rpc/mocks/peer.go @@ -1,5 +1,8 @@ // Code generated by mockery. DO NOT EDIT. +//go:build test +// +build test + package mocks import ( diff --git a/pipeline/rpc/peer.go b/pipeline/rpc/peer.go index 8025080b5..d8d82a163 100644 --- a/pipeline/rpc/peer.go +++ b/pipeline/rpc/peer.go @@ -50,7 +50,7 @@ type ( } ) -//go:generate mockery --name Peer --output mocks --case underscore +//go:generate mockery --name Peer --output mocks --case underscore --note "+build test" // Peer defines a peer-to-peer connection. type Peer interface { diff --git a/server/forge/forge.go b/server/forge/forge.go index bb5db187d..4169e60d0 100644 --- a/server/forge/forge.go +++ b/server/forge/forge.go @@ -15,7 +15,7 @@ package forge -//go:generate mockery --name Forge --output mocks --case underscore +//go:generate mockery --name Forge --output mocks --case underscore --note "+build test" import ( "context" diff --git a/server/forge/mocks/forge.go b/server/forge/mocks/forge.go index a926ca16a..3deb6b960 100644 --- a/server/forge/mocks/forge.go +++ b/server/forge/mocks/forge.go @@ -1,5 +1,8 @@ // Code generated by mockery. DO NOT EDIT. +//go:build test +// +build test + package mocks import ( diff --git a/server/services/manager.go b/server/services/manager.go index 079222a02..5526937f8 100644 --- a/server/services/manager.go +++ b/server/services/manager.go @@ -30,7 +30,7 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/server/store" ) -//go:generate mockery --name Manager --output mocks --case underscore +//go:generate mockery --name Manager --output mocks --case underscore --note "+build test" const forgeCacheTTL = 10 * time.Minute diff --git a/server/services/mocks/manager.go b/server/services/mocks/manager.go index 1d64c2af3..b71d8ea4d 100644 --- a/server/services/mocks/manager.go +++ b/server/services/mocks/manager.go @@ -1,5 +1,8 @@ // Code generated by mockery. DO NOT EDIT. +//go:build test +// +build test + package mocks import ( diff --git a/server/store/mocks/store.go b/server/store/mocks/store.go index ee1a825d0..bfafcc6d4 100644 --- a/server/store/mocks/store.go +++ b/server/store/mocks/store.go @@ -1,5 +1,8 @@ // Code generated by mockery. DO NOT EDIT. +//go:build test +// +build test + package mocks import ( diff --git a/server/store/store.go b/server/store/store.go index 2a007e487..ecf33ad64 100644 --- a/server/store/store.go +++ b/server/store/store.go @@ -14,7 +14,7 @@ package store -//go:generate mockery --name Store --output mocks --case underscore +//go:generate mockery --name Store --output mocks --case underscore --note "+build test" import ( "go.woodpecker-ci.org/woodpecker/v2/server/model" diff --git a/woodpecker-go/woodpecker/interface.go b/woodpecker-go/woodpecker/interface.go index 6adc29d18..0d54af18f 100644 --- a/woodpecker-go/woodpecker/interface.go +++ b/woodpecker-go/woodpecker/interface.go @@ -18,7 +18,7 @@ import ( "net/http" ) -//go:generate mockery --name Client --output mocks --case underscore +//go:generate mockery --name Client --output mocks --case underscore --note "+build test" // Client is used to communicate with a Woodpecker server. type Client interface { diff --git a/woodpecker-go/woodpecker/mocks/client.go b/woodpecker-go/woodpecker/mocks/client.go index 7f9571c56..fcbd7f957 100644 --- a/woodpecker-go/woodpecker/mocks/client.go +++ b/woodpecker-go/woodpecker/mocks/client.go @@ -1,5 +1,8 @@ // Code generated by mockery. DO NOT EDIT. +//go:build test +// +build test + package mocks import (