Skip to content

Commit

Permalink
feat(action/gitTag): advanced parameter prefix (#3301)
Browse files Browse the repository at this point in the history
  • Loading branch information
yesnault authored and fsamin committed Sep 12, 2018
1 parent 4742ccb commit a0db2f1
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/content/workflows/pipelines/actions/builtin/gittag.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This action creates a tag. You can use a pgp key to sign it.
* tagMessage - optional - Message for the tag
* path - optional - path to your git repository
* signKey - optional - pgp key to sign the tag
* Advanced parameter: prefix - add a prefix in tag name created

## Example of usage

Expand Down
7 changes: 7 additions & 0 deletions engine/api/action/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ Semver used if fully compatible with https://semver.org/
Value: "{{.cds.workspace}}",
Type: sdk.StringParameter,
})
gittag.Parameter(sdk.Parameter{
Name: "prefix",
Description: "Prefix for tag name",
Value: "",
Type: sdk.StringParameter,
Advanced: true,
})
gittag.Requirement("git", sdk.BinaryRequirement, "git")
gittag.Requirement("gpg", sdk.BinaryRequirement, "gpg")

Expand Down
8 changes: 8 additions & 0 deletions engine/sql/127_git_tag.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- +migrate Up

INSERT into action_parameter (action_id, name, description, type, value, advanced) values((select id from action where name = 'GitTag' and type = 'Builtin'), 'prefix', 'Prefix for tag name', 'string', '', true);

-- +migrate Down

DELETE from action_parameter where name = 'prefix' and action_id = (select id from action where name = 'GitTag' and type = 'Builtin');

8 changes: 7 additions & 1 deletion engine/worker/builtin_gitclone.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func extractInfo(w *currentWorker, dir string, params *[]sdk.Parameter, tag, bra
}
sendLog(fmt.Sprintf("git.describe: %s", info.GitDescribe))

smver, errT := semver.Make(info.GitDescribe)
smver, errT := semver.ParseTolerant(info.GitDescribe)
if errT != nil {
sendLog(fmt.Sprintf("!! WARNING !! git describe %s is not semver compatible, we can't create cds.semver variable", info.GitDescribe))
} else {
Expand Down Expand Up @@ -318,6 +318,12 @@ func extractInfo(w *currentWorker, dir string, params *[]sdk.Parameter, tag, bra
cdsVersion.Value,
)
}

// if git.describe contains a prefix 'v', we keep it
if strings.HasPrefix(info.GitDescribe, "v") {
cdsSemver = fmt.Sprintf("v%s", cdsSemver)
}

} else {
// default value if there is no tag on repository
cdsSemver = fmt.Sprintf("0.0.1+cds.%s", cdsVersion.Value)
Expand Down
7 changes: 6 additions & 1 deletion engine/worker/builtin_gittag.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func runGitTag(w *currentWorker) BuiltInAction {
tagLevel := sdk.ParameterFind(&a.Parameters, "tagLevel")
tagMessage := sdk.ParameterFind(&a.Parameters, "tagMessage")
path := sdk.ParameterFind(&a.Parameters, "path")
prefix := sdk.ParameterFind(&a.Parameters, "prefix")

tagLevelValid := true
if tagLevel == nil || tagLevel.Value == "" {
Expand Down Expand Up @@ -64,7 +65,7 @@ func runGitTag(w *currentWorker) BuiltInAction {
return res
}

smver, errT := semver.Make(cdsSemver.Value)
smver, errT := semver.ParseTolerant(cdsSemver.Value)
if errT != nil {
res := sdk.Result{
Status: sdk.StatusFail.String(),
Expand Down Expand Up @@ -142,6 +143,10 @@ func runGitTag(w *currentWorker) BuiltInAction {
Username: userTag,
}

if prefix != nil && prefix.Value != "" {
tagOpts.Name = fmt.Sprintf("%s%s", prefix.Value, tagOpts.Name)
}

if auth.SignKey.ID != "" {
tagOpts.SignKey = auth.SignKey.Private
tagOpts.SignID = auth.SignKey.ID
Expand Down
7 changes: 5 additions & 2 deletions sdk/exportentities/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ func newSteps(a sdk.Action) []Step {
if tagPrerelease != nil && tagPrerelease.Value != "" {
gitTagArgs["tagPrerelease"] = tagPrerelease.Value
}
prefix := sdk.ParameterFind(&act.Parameters, "prefix")
if prefix != nil && prefix.Value != "" {
gitTagArgs["prefix"] = prefix.Value
}
s["gitTag"] = gitTagArgs
case sdk.ReleaseAction:
releaseArgs := map[string]string{}
Expand Down Expand Up @@ -635,9 +639,8 @@ func (s Step) Name() (string, error) {
if stepAttr, ok := s["name"]; ok {
if stepName, okName := stepAttr.(string); okName {
return stepName, nil
} else {
return "", fmt.Errorf("Malformatted Step : name must be a string")
}
return "", fmt.Errorf("Malformatted Step : name must be a string")
}
return "", nil
}
Expand Down

0 comments on commit a0db2f1

Please sign in to comment.