diff --git a/internal/config/config.go b/internal/config/config.go index 91f36e4..bf1f000 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -142,7 +142,9 @@ type BaseStep struct { } type CloneStep struct { - BaseStep `json:",inline"` + 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) diff --git a/internal/runconfig/runconfig.go b/internal/runconfig/runconfig.go index b7cf301..2ed18db 100644 --- a/internal/runconfig/runconfig.go +++ b/internal/runconfig/runconfig.go @@ -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, " ") +}