mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-09-01 15:11:37 +00:00
@@ -42,6 +42,7 @@ type Compiler struct {
|
|||||||
volumes []string
|
volumes []string
|
||||||
networks []string
|
networks []string
|
||||||
env map[string]string
|
env map[string]string
|
||||||
|
cloneEnv map[string]string
|
||||||
base string
|
base string
|
||||||
path string
|
path string
|
||||||
metadata frontend.Metadata
|
metadata frontend.Metadata
|
||||||
@@ -55,6 +56,7 @@ type Compiler struct {
|
|||||||
func New(opts ...Option) *Compiler {
|
func New(opts ...Option) *Compiler {
|
||||||
compiler := &Compiler{
|
compiler := &Compiler{
|
||||||
env: map[string]string{},
|
env: map[string]string{},
|
||||||
|
cloneEnv: map[string]string{},
|
||||||
secrets: map[string]Secret{},
|
secrets: map[string]Secret{},
|
||||||
}
|
}
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@@ -109,15 +111,11 @@ func (c *Compiler) Compile(conf *yaml.Config) *backend.Config {
|
|||||||
if !c.local && len(conf.Clone.Containers) == 0 && !conf.SkipClone {
|
if !c.local && len(conf.Clone.Containers) == 0 && !conf.SkipClone {
|
||||||
container := &yaml.Container{
|
container := &yaml.Container{
|
||||||
Name: "clone",
|
Name: "clone",
|
||||||
Image: "woodpeckerci/plugin-git:latest",
|
// TODO: switch to `:latest` once v1.1.0 got released
|
||||||
|
// https://github.com/woodpecker-ci/plugin-git/issues/3
|
||||||
|
Image: "woodpeckerci/plugin-git:next",
|
||||||
Vargs: map[string]interface{}{"depth": "0"},
|
Vargs: map[string]interface{}{"depth": "0"},
|
||||||
}
|
Environment: c.cloneEnv,
|
||||||
// TODO: migrate to woodpeckerci/plugin-git:latest (multi arch)
|
|
||||||
switch c.metadata.Sys.Arch {
|
|
||||||
case "linux/arm":
|
|
||||||
container.Image = "plugins/git:linux-arm"
|
|
||||||
case "linux/arm64":
|
|
||||||
container.Image = "plugins/git:linux-arm64"
|
|
||||||
}
|
}
|
||||||
name := fmt.Sprintf("%s_clone", c.prefix)
|
name := fmt.Sprintf("%s_clone", c.prefix)
|
||||||
step := c.createProcess(name, container, "clone")
|
step := c.createProcess(name, container, "clone")
|
||||||
@@ -139,6 +137,9 @@ func (c *Compiler) Compile(conf *yaml.Config) *backend.Config {
|
|||||||
|
|
||||||
name := fmt.Sprintf("%s_clone_%d", c.prefix, i)
|
name := fmt.Sprintf("%s_clone_%d", c.prefix, i)
|
||||||
step := c.createProcess(name, container, "clone")
|
step := c.createProcess(name, container, "clone")
|
||||||
|
for k, v := range c.cloneEnv {
|
||||||
|
step.Environment[k] = v
|
||||||
|
}
|
||||||
stage.Steps = append(stage.Steps, step)
|
stage.Steps = append(stage.Steps, step)
|
||||||
|
|
||||||
config.Stages = append(config.Stages, stage)
|
config.Stages = append(config.Stages, stage)
|
||||||
|
@@ -66,13 +66,11 @@ func WithMetadata(metadata frontend.Metadata) Option {
|
|||||||
// WithNetrc configures the compiler with netrc authentication
|
// WithNetrc configures the compiler with netrc authentication
|
||||||
// credentials added by default to every container in the pipeline.
|
// credentials added by default to every container in the pipeline.
|
||||||
func WithNetrc(username, password, machine string) Option {
|
func WithNetrc(username, password, machine string) Option {
|
||||||
return WithEnviron(
|
return func(compiler *Compiler) {
|
||||||
map[string]string{
|
compiler.cloneEnv["CI_NETRC_USERNAME"] = username
|
||||||
"CI_NETRC_USERNAME": username,
|
compiler.cloneEnv["CI_NETRC_PASSWORD"] = password
|
||||||
"CI_NETRC_PASSWORD": password,
|
compiler.cloneEnv["CI_NETRC_MACHINE"] = machine
|
||||||
"CI_NETRC_MACHINE": machine,
|
}
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithWorkspace configures the compiler with the workspace base
|
// WithWorkspace configures the compiler with the workspace base
|
||||||
|
@@ -141,13 +141,13 @@ func TestWithNetrc(t *testing.T) {
|
|||||||
"github.com",
|
"github.com",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
if compiler.env["CI_NETRC_USERNAME"] != "octocat" {
|
if compiler.cloneEnv["CI_NETRC_USERNAME"] != "octocat" {
|
||||||
t.Errorf("WithNetrc should set CI_NETRC_USERNAME")
|
t.Errorf("WithNetrc should set CI_NETRC_USERNAME")
|
||||||
}
|
}
|
||||||
if compiler.env["CI_NETRC_PASSWORD"] != "password" {
|
if compiler.cloneEnv["CI_NETRC_PASSWORD"] != "password" {
|
||||||
t.Errorf("WithNetrc should set CI_NETRC_PASSWORD")
|
t.Errorf("WithNetrc should set CI_NETRC_PASSWORD")
|
||||||
}
|
}
|
||||||
if compiler.env["CI_NETRC_MACHINE"] != "github.com" {
|
if compiler.cloneEnv["CI_NETRC_MACHINE"] != "github.com" {
|
||||||
t.Errorf("WithNetrc should set CI_NETRC_MACHINE")
|
t.Errorf("WithNetrc should set CI_NETRC_MACHINE")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user