Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): keep the empty value for git clone tag parameter #6649

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions engine/worker/internal/action/builtin_gitclone.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ func RunGitClone(ctx context.Context, wk workerruntime.Runtime, a sdk.Action, se
var err error
gitURL, auth, err = vcsStrategy(ctx, wk, wk.Parameters(), secrets)
if err != nil {
return sdk.Result{}, fmt.Errorf("Could not use VCS Auth Strategy from application: %v", err)
return sdk.Result{}, fmt.Errorf("could not use VCS Auth Strategy from application: %v", err)
}
key = &auth.PrivateKey
}

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

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

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

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

//git.LogFunc = log.InfoWithoutCtx
//Perform the git clone
w.SendLog(ctx, workerruntime.LevelInfo, fmt.Sprintf("cloning repository %s", url))

userLogCommand, err := git.Clone(url, basedir, dir, auth, clone, output)

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

if err != nil {
return sdk.Result{}, fmt.Errorf("Unable to git clone: %s", err)
return sdk.Result{}, fmt.Errorf("unable to git clone: %s", err)
}

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

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

return sdk.Result{Status: sdk.StatusSuccess, NewVariables: vars}, nil
Expand Down Expand Up @@ -277,10 +279,9 @@ func extractInfo(ctx context.Context, w workerruntime.Runtime, basedir, dir stri
Value: info.Branch,
}
res = append(res, gitBranch)

w.SendLog(ctx, workerruntime.LevelInfo, fmt.Sprintf("git.branch: %s", info.Branch))
} else {
w.SendLog(ctx, workerruntime.LevelInfo, fmt.Sprintf("git.branch: [empty]"))
w.SendLog(ctx, workerruntime.LevelInfo, "git.branch: [empty]")
}
} else if branch != "" && branch != "{{.git.branch}}" {
w.SendLog(ctx, workerruntime.LevelInfo, fmt.Sprintf("git.branch: %s", branch))
Expand Down
51 changes: 51 additions & 0 deletions sdk/exportentities/action_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package exportentities

import (
"testing"

"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
)

func TestGitClone(t *testing.T) {
content := `
name: "test"
steps:
- checkout: '{{ .cds.workspace }}'
- gitClone:
commit: HEAD
directory: '/external-packages'
url: 'ssh://external-packages.git'
privateKey: proj-ssh
tag: ''`

var jobAsCode Action

require.NoError(t, yaml.Unmarshal([]byte(content), &jobAsCode))

require.Len(t, jobAsCode.Steps, 2)

job, err := jobAsCode.GetAction()
require.NoError(t, err)

require.Equal(t, "CheckoutApplication", job.Actions[0].Name)
require.Equal(t, "{{ .cds.workspace }}", job.Actions[0].Parameters[0].Value)

require.Equal(t, "GitClone", job.Actions[1].Name)
require.Len(t, job.Actions[1].Parameters, 5)
for _, p := range job.Actions[1].Parameters {
t.Log(p.Name, p.Value)
switch p.Name {
case "commit":
require.Equal(t, "HEAD", p.Value)
case "directory":
require.Equal(t, "/external-packages", p.Value)
case "url":
require.Equal(t, "ssh://external-packages.git", p.Value)
case "privateKey":
require.Equal(t, "proj-ssh", p.Value)
case "tag":
require.Equal(t, "", p.Value)
}
}
}
22 changes: 11 additions & 11 deletions sdk/exportentities/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func NewStep(act sdk.Action) Step {
}
tag := sdk.ParameterFind(act.Parameters, "tag")
if tag != nil && tag.Value != sdk.DefaultGitCloneParameterTagValue {
s.GitClone.Tag = tag.Value
s.GitClone.Tag = &tag.Value
}
case sdk.GitTagAction:
s.GitTag = &StepGitTag{}
Expand Down Expand Up @@ -287,16 +287,16 @@ type StepArtifactUpload struct {

// StepGitClone represents exported git clone step.
type StepGitClone struct {
Branch string `json:"branch,omitempty" yaml:"branch,omitempty"`
Commit string `json:"commit,omitempty" yaml:"commit,omitempty"`
Depth string `json:"depth,omitempty" yaml:"depth,omitempty"`
Directory string `json:"directory,omitempty" yaml:"directory,omitempty"`
Password string `json:"password,omitempty" yaml:"password,omitempty"`
PrivateKey string `json:"privateKey,omitempty" yaml:"privateKey,omitempty"`
SubModules string `json:"submodules,omitempty" yaml:"submodules,omitempty"`
Tag string `json:"tag,omitempty" yaml:"tag,omitempty"`
URL string `json:"url,omitempty" yaml:"url,omitempty" jsonschema:"required"`
User string `json:"user,omitempty" yaml:"user,omitempty"`
Branch string `json:"branch,omitempty" yaml:"branch,omitempty"`
Commit string `json:"commit,omitempty" yaml:"commit,omitempty"`
Depth string `json:"depth,omitempty" yaml:"depth,omitempty"`
Directory string `json:"directory,omitempty" yaml:"directory,omitempty"`
Password string `json:"password,omitempty" yaml:"password,omitempty"`
PrivateKey string `json:"privateKey,omitempty" yaml:"privateKey,omitempty"`
SubModules string `json:"submodules,omitempty" yaml:"submodules,omitempty"`
Tag *string `json:"tag,omitempty" yaml:"tag,omitempty"`
URL string `json:"url,omitempty" yaml:"url,omitempty" jsonschema:"required"`
User string `json:"user,omitempty" yaml:"user,omitempty"`
}

// StepPromote represents exported promote step.
Expand Down