Skip to content

Commit ea3de2f

Browse files
authored
fix(api): keep the empty value for git clone tag parameter (#6649)
1 parent 90a72a4 commit ea3de2f

File tree

3 files changed

+70
-18
lines changed

3 files changed

+70
-18
lines changed

engine/worker/internal/action/builtin_gitclone.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ func RunGitClone(ctx context.Context, wk workerruntime.Runtime, a sdk.Action, se
8787
var err error
8888
gitURL, auth, err = vcsStrategy(ctx, wk, wk.Parameters(), secrets)
8989
if err != nil {
90-
return sdk.Result{}, fmt.Errorf("Could not use VCS Auth Strategy from application: %v", err)
90+
return sdk.Result{}, fmt.Errorf("could not use VCS Auth Strategy from application: %v", err)
9191
}
9292
key = &auth.PrivateKey
9393
}
9494

9595
if gitURL == "" {
96-
return sdk.Result{}, fmt.Errorf("Git repository URL is not set. Nothing to perform")
96+
return sdk.Result{}, fmt.Errorf("git repository URL is not set. Nothing to perform")
9797
}
9898

9999
//If url is not http(s), a key must be found
@@ -150,7 +150,7 @@ func RunGitClone(ctx context.Context, wk workerruntime.Runtime, a sdk.Action, se
150150

151151
workdir, err := workerruntime.WorkingDirectory(ctx)
152152
if err != nil {
153-
return sdk.Result{}, fmt.Errorf("Unable to find current working directory: %v", err)
153+
return sdk.Result{}, fmt.Errorf("unable to find current working directory: %v", err)
154154
}
155155

156156
workdirPath := workdir.Name()
@@ -173,6 +173,8 @@ func gitClone(ctx context.Context, w workerruntime.Runtime, params []sdk.Paramet
173173

174174
//git.LogFunc = log.InfoWithoutCtx
175175
//Perform the git clone
176+
w.SendLog(ctx, workerruntime.LevelInfo, fmt.Sprintf("cloning repository %s", url))
177+
176178
userLogCommand, err := git.Clone(url, basedir, dir, auth, clone, output)
177179

178180
w.SendLog(ctx, workerruntime.LevelInfo, userLogCommand)
@@ -186,7 +188,7 @@ func gitClone(ctx context.Context, w workerruntime.Runtime, params []sdk.Paramet
186188
}
187189

188190
if err != nil {
189-
return sdk.Result{}, fmt.Errorf("Unable to git clone: %s", err)
191+
return sdk.Result{}, fmt.Errorf("unable to git clone: %s", err)
190192
}
191193

192194
// extract info only if we git clone the same repo as current application linked to the pipeline
@@ -215,7 +217,7 @@ func gitClone(ctx context.Context, w workerruntime.Runtime, params []sdk.Paramet
215217
}
216218

217219
if errTag != nil {
218-
return sdk.Result{}, sdk.WithStack(fmt.Errorf("Unable to list tag for getting current version: %v", errTag))
220+
return sdk.Result{}, sdk.WithStack(fmt.Errorf("unable to list tag for getting current version: %v", errTag))
219221
}
220222

221223
return sdk.Result{Status: sdk.StatusSuccess, NewVariables: vars}, nil
@@ -277,10 +279,9 @@ func extractInfo(ctx context.Context, w workerruntime.Runtime, basedir, dir stri
277279
Value: info.Branch,
278280
}
279281
res = append(res, gitBranch)
280-
281282
w.SendLog(ctx, workerruntime.LevelInfo, fmt.Sprintf("git.branch: %s", info.Branch))
282283
} else {
283-
w.SendLog(ctx, workerruntime.LevelInfo, fmt.Sprintf("git.branch: [empty]"))
284+
w.SendLog(ctx, workerruntime.LevelInfo, "git.branch: [empty]")
284285
}
285286
} else if branch != "" && branch != "{{.git.branch}}" {
286287
w.SendLog(ctx, workerruntime.LevelInfo, fmt.Sprintf("git.branch: %s", branch))

sdk/exportentities/action_test.go

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package exportentities
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
"gopkg.in/yaml.v2"
8+
)
9+
10+
func TestGitClone(t *testing.T) {
11+
content := `
12+
name: "test"
13+
steps:
14+
- checkout: '{{ .cds.workspace }}'
15+
- gitClone:
16+
commit: HEAD
17+
directory: '/external-packages'
18+
url: 'ssh://external-packages.git'
19+
privateKey: proj-ssh
20+
tag: ''`
21+
22+
var jobAsCode Action
23+
24+
require.NoError(t, yaml.Unmarshal([]byte(content), &jobAsCode))
25+
26+
require.Len(t, jobAsCode.Steps, 2)
27+
28+
job, err := jobAsCode.GetAction()
29+
require.NoError(t, err)
30+
31+
require.Equal(t, "CheckoutApplication", job.Actions[0].Name)
32+
require.Equal(t, "{{ .cds.workspace }}", job.Actions[0].Parameters[0].Value)
33+
34+
require.Equal(t, "GitClone", job.Actions[1].Name)
35+
require.Len(t, job.Actions[1].Parameters, 5)
36+
for _, p := range job.Actions[1].Parameters {
37+
t.Log(p.Name, p.Value)
38+
switch p.Name {
39+
case "commit":
40+
require.Equal(t, "HEAD", p.Value)
41+
case "directory":
42+
require.Equal(t, "/external-packages", p.Value)
43+
case "url":
44+
require.Equal(t, "ssh://external-packages.git", p.Value)
45+
case "privateKey":
46+
require.Equal(t, "proj-ssh", p.Value)
47+
case "tag":
48+
require.Equal(t, "", p.Value)
49+
}
50+
}
51+
}

sdk/exportentities/step.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func NewStep(act sdk.Action) Step {
109109
}
110110
tag := sdk.ParameterFind(act.Parameters, "tag")
111111
if tag != nil && tag.Value != sdk.DefaultGitCloneParameterTagValue {
112-
s.GitClone.Tag = tag.Value
112+
s.GitClone.Tag = &tag.Value
113113
}
114114
case sdk.GitTagAction:
115115
s.GitTag = &StepGitTag{}
@@ -287,16 +287,16 @@ type StepArtifactUpload struct {
287287

288288
// StepGitClone represents exported git clone step.
289289
type StepGitClone struct {
290-
Branch string `json:"branch,omitempty" yaml:"branch,omitempty"`
291-
Commit string `json:"commit,omitempty" yaml:"commit,omitempty"`
292-
Depth string `json:"depth,omitempty" yaml:"depth,omitempty"`
293-
Directory string `json:"directory,omitempty" yaml:"directory,omitempty"`
294-
Password string `json:"password,omitempty" yaml:"password,omitempty"`
295-
PrivateKey string `json:"privateKey,omitempty" yaml:"privateKey,omitempty"`
296-
SubModules string `json:"submodules,omitempty" yaml:"submodules,omitempty"`
297-
Tag string `json:"tag,omitempty" yaml:"tag,omitempty"`
298-
URL string `json:"url,omitempty" yaml:"url,omitempty" jsonschema:"required"`
299-
User string `json:"user,omitempty" yaml:"user,omitempty"`
290+
Branch string `json:"branch,omitempty" yaml:"branch,omitempty"`
291+
Commit string `json:"commit,omitempty" yaml:"commit,omitempty"`
292+
Depth string `json:"depth,omitempty" yaml:"depth,omitempty"`
293+
Directory string `json:"directory,omitempty" yaml:"directory,omitempty"`
294+
Password string `json:"password,omitempty" yaml:"password,omitempty"`
295+
PrivateKey string `json:"privateKey,omitempty" yaml:"privateKey,omitempty"`
296+
SubModules string `json:"submodules,omitempty" yaml:"submodules,omitempty"`
297+
Tag *string `json:"tag,omitempty" yaml:"tag,omitempty"`
298+
URL string `json:"url,omitempty" yaml:"url,omitempty" jsonschema:"required"`
299+
User string `json:"user,omitempty" yaml:"user,omitempty"`
300300
}
301301

302302
// StepPromote represents exported promote step.

0 commit comments

Comments
 (0)