mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-09-13 18:46:57 +00:00
Simplify backend types (#5299)
This commit is contained in:
@@ -16,7 +16,9 @@ package compiler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"maps"
|
||||
"path"
|
||||
"slices"
|
||||
|
||||
backend_types "go.woodpecker-ci.org/woodpecker/v3/pipeline/backend/types"
|
||||
"go.woodpecker-ci.org/woodpecker/v3/pipeline/frontend/metadata"
|
||||
@@ -72,13 +74,7 @@ func (s *Secret) Match(event string) bool {
|
||||
event = "pull_request"
|
||||
}
|
||||
// one match is enough
|
||||
for _, e := range s.Events {
|
||||
if e == event {
|
||||
return true
|
||||
}
|
||||
}
|
||||
// a filter is set but the webhook did not match it
|
||||
return false
|
||||
return slices.Contains(s.Events, event)
|
||||
}
|
||||
|
||||
// Compiler compiles the yaml.
|
||||
@@ -129,14 +125,10 @@ func (c *Compiler) Compile(conf *yaml_types.Workflow) (*backend_types.Config, er
|
||||
}
|
||||
|
||||
// create a default volume
|
||||
config.Volume = &backend_types.Volume{
|
||||
Name: fmt.Sprintf("%s_default", c.prefix),
|
||||
}
|
||||
config.Volume = fmt.Sprintf("%s_default", c.prefix)
|
||||
|
||||
// create a default network
|
||||
config.Network = &backend_types.Network{
|
||||
Name: fmt.Sprintf("%s_default", c.prefix),
|
||||
}
|
||||
config.Network = fmt.Sprintf("%s_default", c.prefix)
|
||||
|
||||
// create secrets for mask
|
||||
for _, sec := range c.secrets {
|
||||
@@ -196,9 +188,7 @@ func (c *Compiler) Compile(conf *yaml_types.Workflow) (*backend_types.Config, er
|
||||
|
||||
// only inject netrc if it's a trusted repo or a trusted plugin
|
||||
if c.securityTrustedPipeline || (container.IsPlugin() && container.IsTrustedCloneImage(c.trustedClonePlugins)) {
|
||||
for k, v := range c.cloneEnv {
|
||||
step.Environment[k] = v
|
||||
}
|
||||
maps.Copy(step.Environment, c.cloneEnv)
|
||||
}
|
||||
|
||||
stage.Steps = append(stage.Steps, step)
|
||||
@@ -253,9 +243,7 @@ func (c *Compiler) Compile(conf *yaml_types.Workflow) (*backend_types.Config, er
|
||||
|
||||
// only inject netrc if it's a trusted repo or a trusted plugin
|
||||
if c.securityTrustedPipeline || (container.IsPlugin() && container.IsTrustedCloneImage(c.trustedClonePlugins)) {
|
||||
for k, v := range c.cloneEnv {
|
||||
step.Environment[k] = v
|
||||
}
|
||||
maps.Copy(step.Environment, c.cloneEnv)
|
||||
}
|
||||
|
||||
steps = append(steps, &dagCompilerStep{
|
||||
|
@@ -81,12 +81,8 @@ func TestCompilerCompile(t *testing.T) {
|
||||
WithWorkspaceFromURL("/test", repoURL),
|
||||
)
|
||||
|
||||
defaultNetwork := &backend_types.Network{
|
||||
Name: "test_default",
|
||||
}
|
||||
defaultVolume := &backend_types.Volume{
|
||||
Name: "test_default",
|
||||
}
|
||||
defaultNetwork := "test_default"
|
||||
defaultVolume := "test_default"
|
||||
|
||||
defaultCloneStage := &backend_types.Stage{
|
||||
Steps: []*backend_types.Step{{
|
||||
@@ -95,7 +91,7 @@ func TestCompilerCompile(t *testing.T) {
|
||||
Image: constant.DefaultClonePlugin,
|
||||
OnSuccess: true,
|
||||
Failure: "fail",
|
||||
Volumes: []string{defaultVolume.Name + ":/woodpecker"},
|
||||
Volumes: []string{defaultVolume + ":/woodpecker"},
|
||||
WorkingDir: "/woodpecker/src/github.com/octocat/hello-world",
|
||||
WorkspaceBase: "/woodpecker",
|
||||
Networks: []backend_types.Conn{{Name: "test_default", Aliases: []string{"clone"}}},
|
||||
@@ -142,7 +138,7 @@ func TestCompilerCompile(t *testing.T) {
|
||||
Image: "dummy_img",
|
||||
OnSuccess: true,
|
||||
Failure: "fail",
|
||||
Volumes: []string{defaultVolume.Name + ":/woodpecker"},
|
||||
Volumes: []string{defaultVolume + ":/woodpecker"},
|
||||
WorkingDir: "/woodpecker/src/github.com/octocat/hello-world",
|
||||
WorkspaceBase: "/woodpecker",
|
||||
Networks: []backend_types.Conn{{Name: "test_default", Aliases: []string{"dummy"}}},
|
||||
@@ -178,7 +174,7 @@ func TestCompilerCompile(t *testing.T) {
|
||||
Commands: []string{"env"},
|
||||
OnSuccess: true,
|
||||
Failure: "fail",
|
||||
Volumes: []string{defaultVolume.Name + ":/test"},
|
||||
Volumes: []string{defaultVolume + ":/test"},
|
||||
WorkingDir: "/test/src/github.com/octocat/hello-world",
|
||||
WorkspaceBase: "/test",
|
||||
Networks: []backend_types.Conn{{Name: "test_default", Aliases: []string{"echo env"}}},
|
||||
@@ -192,7 +188,7 @@ func TestCompilerCompile(t *testing.T) {
|
||||
Commands: []string{"echo 1"},
|
||||
OnSuccess: true,
|
||||
Failure: "fail",
|
||||
Volumes: []string{defaultVolume.Name + ":/test"},
|
||||
Volumes: []string{defaultVolume + ":/test"},
|
||||
WorkingDir: "/test/src/github.com/octocat/hello-world",
|
||||
WorkspaceBase: "/test",
|
||||
Networks: []backend_types.Conn{{Name: "test_default", Aliases: []string{"parallel echo 1"}}},
|
||||
@@ -206,7 +202,7 @@ func TestCompilerCompile(t *testing.T) {
|
||||
Commands: []string{"echo 2"},
|
||||
OnSuccess: true,
|
||||
Failure: "fail",
|
||||
Volumes: []string{defaultVolume.Name + ":/test"},
|
||||
Volumes: []string{defaultVolume + ":/test"},
|
||||
WorkingDir: "/test/src/github.com/octocat/hello-world",
|
||||
WorkspaceBase: "/test",
|
||||
Networks: []backend_types.Conn{{Name: "test_default", Aliases: []string{"parallel echo 2"}}},
|
||||
@@ -243,7 +239,7 @@ func TestCompilerCompile(t *testing.T) {
|
||||
Commands: []string{"env"},
|
||||
OnSuccess: true,
|
||||
Failure: "fail",
|
||||
Volumes: []string{defaultVolume.Name + ":/test"},
|
||||
Volumes: []string{defaultVolume + ":/test"},
|
||||
WorkingDir: "/test/src/github.com/octocat/hello-world",
|
||||
WorkspaceBase: "/test",
|
||||
Networks: []backend_types.Conn{{Name: "test_default", Aliases: []string{"echo env"}}},
|
||||
@@ -255,7 +251,7 @@ func TestCompilerCompile(t *testing.T) {
|
||||
Commands: []string{"echo 2"},
|
||||
OnSuccess: true,
|
||||
Failure: "fail",
|
||||
Volumes: []string{defaultVolume.Name + ":/test"},
|
||||
Volumes: []string{defaultVolume + ":/test"},
|
||||
WorkingDir: "/test/src/github.com/octocat/hello-world",
|
||||
WorkspaceBase: "/test",
|
||||
Networks: []backend_types.Conn{{Name: "test_default", Aliases: []string{"echo 2"}}},
|
||||
@@ -269,7 +265,7 @@ func TestCompilerCompile(t *testing.T) {
|
||||
Commands: []string{"echo 1"},
|
||||
OnSuccess: true,
|
||||
Failure: "fail",
|
||||
Volumes: []string{defaultVolume.Name + ":/test"},
|
||||
Volumes: []string{defaultVolume + ":/test"},
|
||||
WorkingDir: "/test/src/github.com/octocat/hello-world",
|
||||
WorkspaceBase: "/test",
|
||||
Networks: []backend_types.Conn{{Name: "test_default", Aliases: []string{"echo 1"}}},
|
||||
|
Reference in New Issue
Block a user