add clone options

This commit is contained in:
Carlo Mandelli 2019-08-19 11:20:27 +02:00
parent 0172a0aa7f
commit cd8175c156
2 changed files with 21 additions and 5 deletions

View File

@ -143,6 +143,8 @@ type BaseStep struct {
type CloneStep struct {
BaseStep `json:",inline"`
Depth *int `json:"depth"`
RecurseSubmodules bool `json:"recurse_submodules"`
}
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
// 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
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:
if step.Command == "" {
return errors.Errorf("no command defined for step %d (run) in task %q", i, task.Name)

View File

@ -57,10 +57,9 @@ func stepFromConfigStep(csi interface{}, variables map[string]string) interface{
case *config.CloneStep:
// transform a "clone" step in a "run" step command
rs := &config.RunStep{}
rs.Type = "run"
rs.Name = "Clone repository and checkout code"
rs.Command = `
rs.Command = fmt.Sprintf(`
set -x
mkdir ~/.ssh
@ -96,7 +95,7 @@ Host $AGOLA_GIT_HOST
EOF
)
git clone $AGOLA_REPOSITORY_URL .
git clone %s $AGOLA_REPOSITORY_URL .
git fetch origin $AGOLA_GIT_REF
if [ -n "$AGOLA_GIT_COMMITSHA" ]; then
@ -104,7 +103,7 @@ if [ -n "$AGOLA_GIT_COMMITSHA" ]; then
else
git checkout FETCH_HEAD
fi
`
`, genCloneOptions(cs))
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))
}
}
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, " ")
}