Merge pull request #120 from camandel/clone_options
config: add clone options
This commit is contained in:
commit
2d6fd96da0
|
@ -142,7 +142,9 @@ type BaseStep struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type CloneStep struct {
|
type CloneStep struct {
|
||||||
BaseStep `json:",inline"`
|
BaseStep `json:",inline"`
|
||||||
|
Depth *int `json:"depth"`
|
||||||
|
RecurseSubmodules bool `json:"recurse_submodules"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RunStep struct {
|
type RunStep struct {
|
||||||
|
@ -793,6 +795,10 @@ func checkConfig(config *Config) error {
|
||||||
// TODO(sgotti) we could use the run step command as step name but when the
|
// TODO(sgotti) we could use the run step command as step name but when the
|
||||||
// command is very long or multi line it doesn't makes sense and will
|
// command is very long or multi line it doesn't makes sense and will
|
||||||
// probably be quite unuseful/confusing from an UI point of view
|
// probably be quite unuseful/confusing from an UI point of view
|
||||||
|
case *CloneStep:
|
||||||
|
if step.Depth != nil && *step.Depth < 1 {
|
||||||
|
return errors.Errorf("depth value must be greater than 0 for clone step in task %q", task.Name)
|
||||||
|
}
|
||||||
case *RunStep:
|
case *RunStep:
|
||||||
if step.Command == "" {
|
if step.Command == "" {
|
||||||
return errors.Errorf("no command defined for step %d (run) in task %q", i, task.Name)
|
return errors.Errorf("no command defined for step %d (run) in task %q", i, task.Name)
|
||||||
|
|
|
@ -57,10 +57,9 @@ func stepFromConfigStep(csi interface{}, variables map[string]string) interface{
|
||||||
case *config.CloneStep:
|
case *config.CloneStep:
|
||||||
// transform a "clone" step in a "run" step command
|
// transform a "clone" step in a "run" step command
|
||||||
rs := &config.RunStep{}
|
rs := &config.RunStep{}
|
||||||
|
|
||||||
rs.Type = "run"
|
rs.Type = "run"
|
||||||
rs.Name = "Clone repository and checkout code"
|
rs.Name = "Clone repository and checkout code"
|
||||||
rs.Command = `
|
rs.Command = fmt.Sprintf(`
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
mkdir ~/.ssh
|
mkdir ~/.ssh
|
||||||
|
@ -96,7 +95,7 @@ Host $AGOLA_GIT_HOST
|
||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
|
|
||||||
git clone $AGOLA_REPOSITORY_URL .
|
git clone %s $AGOLA_REPOSITORY_URL .
|
||||||
git fetch origin $AGOLA_GIT_REF
|
git fetch origin $AGOLA_GIT_REF
|
||||||
|
|
||||||
if [ -n "$AGOLA_GIT_COMMITSHA" ]; then
|
if [ -n "$AGOLA_GIT_COMMITSHA" ]; then
|
||||||
|
@ -104,7 +103,7 @@ if [ -n "$AGOLA_GIT_COMMITSHA" ]; then
|
||||||
else
|
else
|
||||||
git checkout FETCH_HEAD
|
git checkout FETCH_HEAD
|
||||||
fi
|
fi
|
||||||
`
|
`, genCloneOptions(cs))
|
||||||
|
|
||||||
return rs
|
return rs
|
||||||
|
|
||||||
|
@ -444,3 +443,14 @@ func genValue(val config.Value, variables map[string]string) string {
|
||||||
panic(fmt.Errorf("wrong value type: %q", val.Value))
|
panic(fmt.Errorf("wrong value type: %q", val.Value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func genCloneOptions(c *config.CloneStep) string {
|
||||||
|
cloneoptions := []string{}
|
||||||
|
if c.Depth != nil {
|
||||||
|
cloneoptions = append(cloneoptions, fmt.Sprintf("--depth %d", *c.Depth))
|
||||||
|
}
|
||||||
|
if c.RecurseSubmodules {
|
||||||
|
cloneoptions = append(cloneoptions, "--recurse-submodules")
|
||||||
|
}
|
||||||
|
return strings.Join(cloneoptions, " ")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue