/
clone.go
82 lines (65 loc) · 1.71 KB
/
clone.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// SPDX-License-Identifier: Apache-2.0
package native
import (
"github.com/go-vela/types/constants"
"github.com/go-vela/types/yaml"
)
const (
// default name for clone stage.
cloneStageName = "clone"
// default name for clone step.
cloneStepName = "clone"
)
// CloneStage injects the clone stage process into a yaml configuration.
func (c *client) CloneStage(p *yaml.Build) (*yaml.Build, error) {
// check if the compiler is setup for a local pipeline
if c.local {
// skip injecting the clone process
return p, nil
}
stages := yaml.StageSlice{}
// create new clone stage
clone := &yaml.Stage{
Name: cloneStageName,
Steps: yaml.StepSlice{
&yaml.Step{
Detach: false,
Image: c.CloneImage,
Name: cloneStepName,
Privileged: false,
Pull: constants.PullNotPresent,
},
},
}
// add clone stage as first stage
stages = append(stages, clone)
// add existing stages after clone stage
stages = append(stages, p.Stages...)
// overwrite existing stages
p.Stages = stages
return p, nil
}
// CloneStep injects the clone step process into a yaml configuration.
func (c *client) CloneStep(p *yaml.Build) (*yaml.Build, error) {
// check if the compiler is setup for a local pipeline
if c.local {
// skip injecting the clone process
return p, nil
}
steps := yaml.StepSlice{}
// create new clone step
clone := &yaml.Step{
Detach: false,
Image: c.CloneImage,
Name: cloneStepName,
Privileged: false,
Pull: constants.PullNotPresent,
}
// add clone step as first step
steps = append(steps, clone)
// add existing steps after clone step
steps = append(steps, p.Steps...)
// overwrite existing steps
p.Steps = steps
return p, nil
}