From 266f0bc6e735b75ce4ac26926776ea22c8c1533f Mon Sep 17 00:00:00 2001 From: Guiheux Steven Date: Tue, 25 May 2021 16:27:58 +0200 Subject: [PATCH] refactor: rename release action (#5825) --- ...ase.part.md => builtin-releasevcs.part.md} | 0 .../docs/concepts/files/application-syntax.md | 2 +- .../step_by_step_build_tag_release.md | 2 +- engine/sql/api/223_rename_release_action.sql | 8 +++++ .../worker/internal/action/builtin_release.go | 2 +- .../internal/action/builtin_release_test.go | 14 ++++---- engine/worker/internal/builtin.go | 2 +- sdk/action.go | 2 +- sdk/action/action.go | 2 +- sdk/action/{release.go => release-vcs.go} | 8 ++--- sdk/exportentities/step.go | 36 +++++++++---------- 11 files changed, 43 insertions(+), 35 deletions(-) rename docs/actions/{builtin-release.part.md => builtin-releasevcs.part.md} (100%) create mode 100644 engine/sql/api/223_rename_release_action.sql rename sdk/action/{release.go => release-vcs.go} (93%) diff --git a/docs/actions/builtin-release.part.md b/docs/actions/builtin-releasevcs.part.md similarity index 100% rename from docs/actions/builtin-release.part.md rename to docs/actions/builtin-releasevcs.part.md diff --git a/docs/content/docs/concepts/files/application-syntax.md b/docs/content/docs/concepts/files/application-syntax.md index 9c0311e50c..2c7a6ce5ce 100644 --- a/docs/content/docs/concepts/files/application-syntax.md +++ b/docs/content/docs/concepts/files/application-syntax.md @@ -129,7 +129,7 @@ vcs_ssh_key: proj-ssh-key vcs_pgp_key: proj-pgp-key ``` -Now with this setup you will be able to use the actions [CheckoutApplication]({{< relref "../../actions/builtin-checkoutapplication/" >}}) and [Release]({{< relref "../../actions/builtin-release/" >}}) in your pipelines. +Now with this setup you will be able to use the actions [CheckoutApplication]({{< relref "../../actions/builtin-checkoutapplication/" >}}) and [Release]({{< relref "../../actions/builtin-releasevcs/" >}}) in your pipelines. ## Deployment diff --git a/docs/content/docs/tutorials/step_by_step_build_tag_release.md b/docs/content/docs/tutorials/step_by_step_build_tag_release.md index 070ae870ab..ad608d9b1b 100644 --- a/docs/content/docs/tutorials/step_by_step_build_tag_release.md +++ b/docs/content/docs/tutorials/step_by_step_build_tag_release.md @@ -232,7 +232,7 @@ Tag is created on GitHub. ## 9 - Release Action -[Release action]({{< relref "/docs/actions/builtin-release.md" >}}) action is implemented for GitHub only. +[Release action]({{< relref "/docs/actions/builtin-releasevcs.md" >}}) action is implemented for GitHub only. You can use it to create a release from a tag and push some artifacts on it. {{%expand "view screenshots..." %}} diff --git a/engine/sql/api/223_rename_release_action.sql b/engine/sql/api/223_rename_release_action.sql new file mode 100644 index 0000000000..2d64047cc7 --- /dev/null +++ b/engine/sql/api/223_rename_release_action.sql @@ -0,0 +1,8 @@ +-- +migrate Up +UPDATE action SET name = 'ReleaseVCS' WHERE name = 'Release' and type = 'Builtin' + +-- +migrate Down +UPDATE action SET name = 'Release' WHERE name = 'ReleaseVCS' and type = 'Builtin' + + + diff --git a/engine/worker/internal/action/builtin_release.go b/engine/worker/internal/action/builtin_release.go index a7403a99db..bb8316ab01 100644 --- a/engine/worker/internal/action/builtin_release.go +++ b/engine/worker/internal/action/builtin_release.go @@ -13,7 +13,7 @@ import ( "github.com/ovh/cds/sdk" ) -func RunRelease(ctx context.Context, wk workerruntime.Runtime, a sdk.Action, secrets []sdk.Variable) (sdk.Result, error) { +func RunReleaseVCS(ctx context.Context, wk workerruntime.Runtime, a sdk.Action, secrets []sdk.Variable) (sdk.Result, error) { var res sdk.Result res.Status = sdk.StatusFail jobID, err := workerruntime.JobID(ctx) diff --git a/engine/worker/internal/action/builtin_release_test.go b/engine/worker/internal/action/builtin_release_test.go index 09869a2ea7..2c8cfc740c 100644 --- a/engine/worker/internal/action/builtin_release_test.go +++ b/engine/worker/internal/action/builtin_release_test.go @@ -66,7 +66,7 @@ func TestRunRelease(t *testing.T) { Value: "999", }, }...) - res, err := RunRelease(ctx, wk, + res, err := RunReleaseVCS(ctx, wk, sdk.Action{ Parameters: []sdk.Parameter{ { @@ -110,7 +110,7 @@ func TestRunReleaseMissingTag(t *testing.T) { Value: "999", }, }...) - res, err := RunRelease(ctx, wk, + res, err := RunReleaseVCS(ctx, wk, sdk.Action{ Parameters: []sdk.Parameter{ { @@ -150,7 +150,7 @@ func TestRunReleaseMissingTitle(t *testing.T) { Value: "999", }, }...) - res, err := RunRelease(ctx, wk, + res, err := RunReleaseVCS(ctx, wk, sdk.Action{ Parameters: []sdk.Parameter{ { @@ -190,7 +190,7 @@ func TestRunReleaseMissingReleaseNote(t *testing.T) { Value: "999", }, }...) - res, err := RunRelease(ctx, wk, + res, err := RunReleaseVCS(ctx, wk, sdk.Action{ Parameters: []sdk.Parameter{ { @@ -226,7 +226,7 @@ func TestRunReleaseMissingProjectKey(t *testing.T) { Value: "999", }, }...) - res, err := RunRelease(ctx, wk, + res, err := RunReleaseVCS(ctx, wk, sdk.Action{ Parameters: []sdk.Parameter{ { @@ -266,7 +266,7 @@ func TestRunReleaseMissingWorkflowName(t *testing.T) { Value: "999", }, }...) - res, err := RunRelease(ctx, wk, + res, err := RunReleaseVCS(ctx, wk, sdk.Action{ Parameters: []sdk.Parameter{ { @@ -306,7 +306,7 @@ func TestRunReleaseMissingWorkflowRunNumber(t *testing.T) { Value: "workflow Name", }, }...) - res, err := RunRelease(ctx, wk, + res, err := RunReleaseVCS(ctx, wk, sdk.Action{ Parameters: []sdk.Parameter{ { diff --git a/engine/worker/internal/builtin.go b/engine/worker/internal/builtin.go index 7d329a685c..aba0240481 100644 --- a/engine/worker/internal/builtin.go +++ b/engine/worker/internal/builtin.go @@ -20,7 +20,7 @@ func init() { mapBuiltinActions[sdk.JUnitAction] = action.RunParseJunitTestResultAction mapBuiltinActions[sdk.GitCloneAction] = action.RunGitClone mapBuiltinActions[sdk.GitTagAction] = action.RunGitTag - mapBuiltinActions[sdk.ReleaseAction] = action.RunRelease + mapBuiltinActions[sdk.ReleaseVCSAction] = action.RunReleaseVCS mapBuiltinActions[sdk.CheckoutApplicationAction] = action.RunCheckoutApplication mapBuiltinActions[sdk.DeployApplicationAction] = action.RunDeployApplication mapBuiltinActions[sdk.CoverageAction] = action.RunParseCoverageResultAction diff --git a/sdk/action.go b/sdk/action.go index bbcaa28399..ed2059fb8d 100644 --- a/sdk/action.go +++ b/sdk/action.go @@ -21,7 +21,7 @@ const ( CoverageAction = "Coverage" GitCloneAction = "GitClone" GitTagAction = "GitTag" - ReleaseAction = "Release" + ReleaseVCSAction = "ReleaseVCS" CheckoutApplicationAction = "CheckoutApplication" DeployApplicationAction = "DeployApplication" InstallKeyAction = "InstallKey" diff --git a/sdk/action/action.go b/sdk/action/action.go index 325ef9ee26..c8214f4978 100644 --- a/sdk/action/action.go +++ b/sdk/action/action.go @@ -21,7 +21,7 @@ var List = []Manifest{ GitTag, InstallKey, JUnit, - Release, + ReleaseVCS, Script, ServeStaticFiles, } diff --git a/sdk/action/release.go b/sdk/action/release-vcs.go similarity index 93% rename from sdk/action/release.go rename to sdk/action/release-vcs.go index 6f7cd44730..c782478961 100644 --- a/sdk/action/release.go +++ b/sdk/action/release-vcs.go @@ -5,10 +5,10 @@ import ( "github.com/ovh/cds/sdk/exportentities" ) -// Release action definition. -var Release = Manifest{ +// ReleaseVCS action definition. +var ReleaseVCS = Manifest{ Action: sdk.Action{ - Name: sdk.ReleaseAction, + Name: sdk.ReleaseVCSAction, Description: "This action creates a release on the git repository linked to the application, if repository manager implements it.", Parameters: []sdk.Parameter{ { @@ -68,7 +68,7 @@ var Release = Manifest{ }, }, { - Release: &exportentities.StepRelease{ + ReleaseVCS: &exportentities.StepReleaseVCS{ Artifacts: "{{.cds.workspace}}/myFile", Title: "{{.cds.build.tag}}", ReleaseNote: "My release {{.cds.build.tag}}", diff --git a/sdk/exportentities/step.go b/sdk/exportentities/step.go index e5032f133c..5e2450e7a3 100644 --- a/sdk/exportentities/step.go +++ b/sdk/exportentities/step.go @@ -167,23 +167,23 @@ func newStep(act sdk.Action) Step { if prefix != nil { s.GitTag.Prefix = prefix.Value } - case sdk.ReleaseAction: - s.Release = &StepRelease{} + case sdk.ReleaseVCSAction: + s.ReleaseVCS = &StepReleaseVCS{} artifacts := sdk.ParameterFind(act.Parameters, "artifacts") if artifacts != nil { - s.Release.Artifacts = artifacts.Value + s.ReleaseVCS.Artifacts = artifacts.Value } releaseNote := sdk.ParameterFind(act.Parameters, "releaseNote") if releaseNote != nil { - s.Release.ReleaseNote = releaseNote.Value + s.ReleaseVCS.ReleaseNote = releaseNote.Value } tag := sdk.ParameterFind(act.Parameters, "tag") if tag != nil { - s.Release.Tag = tag.Value + s.ReleaseVCS.Tag = tag.Value } title := sdk.ParameterFind(act.Parameters, "title") if title != nil { - s.Release.Title = title.Value + s.ReleaseVCS.Title = title.Value } case sdk.JUnitAction: var step StepJUnitReport @@ -289,8 +289,8 @@ type StepGitClone struct { User string `json:"user,omitempty" yaml:"user,omitempty"` } -// StepRelease represents exported release step. -type StepRelease struct { +// StepReleaseVCS represents exported release step. +type StepReleaseVCS struct { Artifacts string `json:"artifacts,omitempty" yaml:"artifacts,omitempty"` ReleaseNote string `json:"releaseNote,omitempty" yaml:"releaseNote,omitempty"` Tag string `json:"tag,omitempty" yaml:"tag,omitempty" jsonschema:"required"` @@ -335,7 +335,7 @@ type Step struct { ServeStaticFiles *StepServeStaticFiles `json:"serveStaticFiles,omitempty" yaml:"serveStaticFiles,omitempty" jsonschema:"oneof_required=actionServeStaticFiles" jsonschema_description:"Serve static files.\nhttps://ovh.github.io/cds/docs/actions/builtin-serve-static-files"` GitClone *StepGitClone `json:"gitClone,omitempty" yaml:"gitClone,omitempty" jsonschema:"oneof_required=actionGitClone" jsonschema_description:"Clone a git repository.\nhttps://ovh.github.io/cds/docs/actions/builtin-gitclone"` GitTag *StepGitTag `json:"gitTag,omitempty" yaml:"gitTag,omitempty" jsonschema:"oneof_required=actionGitTag" jsonschema_description:"Create a git tag.\nhttps://ovh.github.io/cds/docs/actions/builtin-gittag"` - Release *StepRelease `json:"release,omitempty" yaml:"release,omitempty" jsonschema:"oneof_required=actionRelease" jsonschema_description:"Release an application.\nhttps://ovh.github.io/cds/docs/actions/builtin-release"` + ReleaseVCS *StepReleaseVCS `json:"releaseVCS,omitempty" yaml:"releaseVCS,omitempty" jsonschema:"oneof_required=actionReleaseVCS" jsonschema_description:"Release an application.\nhttps://ovh.github.io/cds/docs/actions/builtin-releasevcs"` JUnitReport *StepJUnitReport `json:"jUnitReport,omitempty" yaml:"jUnitReport,omitempty" jsonschema:"oneof_required=actionJUNit" jsonschema_description:"Parse JUnit report.\nhttps://ovh.github.io/cds/docs/actions/builtin-junit"` Checkout *StepCheckout `json:"checkout,omitempty" yaml:"checkout,omitempty" jsonschema:"oneof_required=actionCheckout" jsonschema_description:"Checkout repository for an application.\nhttps://ovh.github.io/cds/docs/actions/builtin-checkoutapplication"` InstallKey *StepInstallKey `json:"installKey,omitempty" yaml:"installKey,omitempty" jsonschema:"oneof_required=actionInstallKey" jsonschema_description:"Install a key (GPG, SSH) in your current workspace.\nhttps://ovh.github.io/cds/docs/actions/builtin-installkey"` @@ -441,7 +441,7 @@ func (s Step) IsValid() bool { if s.isGitTag() { count++ } - if s.isRelease() { + if s.isReleaseVCS() { count++ } if s.isCheckout() { @@ -483,8 +483,8 @@ func (s Step) toAction() (*sdk.Action, error) { a, err = s.asGitClone() } else if s.isGitTag() { a, err = s.asGitTag() - } else if s.isRelease() { - a, err = s.asRelease() + } else if s.isReleaseVCS() { + a, err = s.asReleaseVCS() } else if s.isCheckout() { a = s.asCheckoutApplication() } else if s.isInstallKey() { @@ -711,16 +711,16 @@ func (s Step) asGitTag() (sdk.Action, error) { return a, nil } -func (s Step) isRelease() bool { return s.Release != nil } +func (s Step) isReleaseVCS() bool { return s.ReleaseVCS != nil } -func (s Step) asRelease() (sdk.Action, error) { +func (s Step) asReleaseVCS() (sdk.Action, error) { var a sdk.Action - m, err := stepToMap(s.Release) + m, err := stepToMap(s.ReleaseVCS) if err != nil { return a, err } a = sdk.Action{ - Name: sdk.ReleaseAction, + Name: sdk.ReleaseVCSAction, Type: sdk.BuiltinAction, Parameters: sdk.ParametersFromMap(m), } @@ -780,7 +780,7 @@ func stepToMap(i interface{}) (map[string]string, error) { func (s Step) String() string { buf := new(bytes.Buffer) - dump := dump.NewEncoder(buf) - _ = dump.Fdump(s) + dp := dump.NewEncoder(buf) + _ = dp.Fdump(s) return buf.String() }