diff --git a/cli/exec/dummy.go b/cli/exec/dummy.go new file mode 100644 index 000000000..edb544598 --- /dev/null +++ b/cli/exec/dummy.go @@ -0,0 +1,24 @@ +// Copyright 2024 Woodpecker Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:build test +// +build test + +package exec + +import "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/dummy" + +func init() { //nolint:gochecknoinits + backends = append(backends, dummy.New()) +} diff --git a/cli/exec/exec.go b/cli/exec/exec.go index b299cb58b..76e4da538 100644 --- a/cli/exec/exec.go +++ b/cli/exec/exec.go @@ -33,7 +33,6 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/pipeline" "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend" "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/docker" - "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/dummy" "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/kubernetes" "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/local" backend_types "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/types" @@ -54,6 +53,12 @@ var Command = &cli.Command{ Flags: utils.MergeSlices(flags, docker.Flags, kubernetes.Flags, local.Flags), } +var backends = []backend_types.Backend{ + kubernetes.New(), + docker.New(), + local.New(), +} + func run(c *cli.Context) error { return common.RunPipelineFunc(c, execFile, execDir) } @@ -231,12 +236,6 @@ func execWithAxis(c *cli.Context, file, repoPath string, axis matrix.Axis) error } backendCtx := context.WithValue(c.Context, backend_types.CliContext, c) - backends := []backend_types.Backend{ - kubernetes.New(), - docker.New(), - local.New(), - dummy.New(), - } backendEngine, err := backend.FindBackend(backendCtx, backends, c.String("backend-engine")) if err != nil { return err diff --git a/cmd/agent/dummy.go b/cmd/agent/dummy.go new file mode 100644 index 000000000..398b50f10 --- /dev/null +++ b/cmd/agent/dummy.go @@ -0,0 +1,24 @@ +// Copyright 2024 Woodpecker Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:build test +// +build test + +package main + +import "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/dummy" + +func init() { //nolint:gochecknoinits + backends = append(backends, dummy.New()) +} diff --git a/cmd/agent/main.go b/cmd/agent/main.go index 8c4aa3f14..cb18939f4 100644 --- a/cmd/agent/main.go +++ b/cmd/agent/main.go @@ -17,17 +17,17 @@ package main import ( "go.woodpecker-ci.org/woodpecker/v2/cmd/agent/core" "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/docker" - "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/dummy" "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/kubernetes" "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/local" backendTypes "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/types" ) -func main() { - core.RunAgent([]backendTypes.Backend{ - kubernetes.New(), - docker.New(), - local.New(), - dummy.New(), - }) +var backends = []backendTypes.Backend{ + kubernetes.New(), + docker.New(), + local.New(), +} + +func main() { + core.RunAgent(backends) } diff --git a/pipeline/backend/dummy/dummy_noop.go b/pipeline/backend/dummy/dummy_noop.go deleted file mode 100644 index 5a5a23cbb..000000000 --- a/pipeline/backend/dummy/dummy_noop.go +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2024 Woodpecker Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build !test -// +build !test - -package dummy - -import ( - "context" - "errors" - "io" - - "github.com/urfave/cli/v2" - - "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/types" -) - -type noop struct{} - -var ErrOnCompileExcluded = errors.New("the dummy backend engine was excluded on compile time") - -// New returns a dummy backend. -func New() types.Backend { - return &noop{} -} - -func (e *noop) Name() string { - return "dummy" -} - -func (e *noop) IsAvailable(context.Context) bool { - return false -} - -func (e *noop) Flags() []cli.Flag { - return nil -} - -// Load new client for Docker Backend using environment variables. -func (e *noop) Load(context.Context) (*types.BackendInfo, error) { - return nil, ErrOnCompileExcluded -} - -func (e *noop) SetupWorkflow(context.Context, *types.Config, string) error { - return ErrOnCompileExcluded -} - -func (e *noop) StartStep(context.Context, *types.Step, string) error { - return ErrOnCompileExcluded -} - -func (e *noop) WaitStep(context.Context, *types.Step, string) (*types.State, error) { - return nil, ErrOnCompileExcluded -} - -func (e *noop) TailStep(context.Context, *types.Step, string) (io.ReadCloser, error) { - return nil, ErrOnCompileExcluded -} - -func (e *noop) DestroyStep(context.Context, *types.Step, string) error { - return ErrOnCompileExcluded -} - -func (e *noop) DestroyWorkflow(context.Context, *types.Config, string) error { - return ErrOnCompileExcluded -} diff --git a/pipeline/backend/dummy/dummy_test.go b/pipeline/backend/dummy/dummy_test.go index faa1abbc8..f0c3d8586 100644 --- a/pipeline/backend/dummy/dummy_test.go +++ b/pipeline/backend/dummy/dummy_test.go @@ -12,9 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build test -// +build test - package dummy_test import (