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

feat(api): compute a cds version from a helm chart or a cargo file #7182

Merged
merged 6 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions cli/cdsctl/experimental_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func experimentalWorkflow() *cobra.Command {
experimentalWorkflowRunLogs(),
experimentalWorkflowJob(),
experimentalWorkflowResult(),
experimentalWorkflowVersion(),
})
}

Expand Down
114 changes: 114 additions & 0 deletions cli/cdsctl/experimental_workflow_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package main

import (
"context"
"time"

"github.com/spf13/cobra"

"github.com/ovh/cds/cli"
)

var experimentalWorkflowVersionCmd = cli.Command{
Name: "version",
Short: "CDS Experimental workflow version commands",
Aliases: []string{"versions"},
}

func experimentalWorkflowVersion() *cobra.Command {
return cli.NewCommand(experimentalWorkflowVersionCmd, nil, []*cobra.Command{
cli.NewListCommand(workflowV2VersionListCmd, workflowV2versionListFunc, nil, withAllCommandModifiers()...),
cli.NewGetCommand(workflowV2VersionCmd, workflowV2VersionFunc, nil, withAllCommandModifiers()...),
cli.NewCommand(workflowV2VersionDeleteCmd, workflowV2VersionDeleteFunc, nil, withAllCommandModifiers()...),
})
}

var workflowV2VersionDeleteCmd = cli.Command{
Name: "delete",
Aliases: []string{"remove", "rm"},
Short: "Delete the workflow version",
Example: "cdsctl experimental workflow version delete <project_key> <vcs_identifier> <repository_identifier> <workflow_name> <version>",
Ctx: []cli.Arg{},
Args: []cli.Arg{
{Name: "proj_key"},
{Name: "vcs_identifier"},
{Name: "repository_identifier"},
{Name: "workflow_name"},
{Name: "version"},
},
}

func workflowV2VersionDeleteFunc(v cli.Values) error {
if err := client.WorkflowV2VersionDelete(context.Background(), v.GetString("proj_key"), v.GetString("vcs_identifier"), v.GetString("repository_identifier"), v.GetString("workflow_name"), v.GetString("version")); err != nil {
return err
}
return nil
}

var workflowV2VersionCmd = cli.Command{
Name: "get",
Aliases: []string{"show"},
Short: "Get the workflow version",
Example: "cdsctl experimental workflow version get <project_key> <vcs_identifier> <repository_identifier> <workflow_name> <version>",
Ctx: []cli.Arg{},
Args: []cli.Arg{
{Name: "proj_key"},
{Name: "vcs_identifier"},
{Name: "repository_identifier"},
{Name: "workflow_name"},
{Name: "version"},
},
}

func workflowV2VersionFunc(v cli.Values) (interface{}, error) {
workflowVersion, err := client.WorkflowV2VersionGet(context.Background(), v.GetString("proj_key"), v.GetString("vcs_identifier"), v.GetString("repository_identifier"), v.GetString("workflow_name"), v.GetString("version"))
if err != nil {
return nil, err
}
return workflowVersion, nil
}

var workflowV2VersionListCmd = cli.Command{
Name: "list",
Aliases: []string{"ls"},
Short: "List all version for the given workflow",
Example: "cdsctl experimental workflow version list <project_key> <vcs_identifier> <repository_identifier> <workflow_name>",
Ctx: []cli.Arg{},
Args: []cli.Arg{
{Name: "proj_key"},
{Name: "vcs_identifier"},
{Name: "repository_identifier"},
{Name: "workflow_name"},
},
}

func workflowV2versionListFunc(v cli.Values) (cli.ListResult, error) {
versions, err := client.WorkflowV2VersionList(context.Background(), v.GetString("proj_key"), v.GetString("vcs_identifier"), v.GetString("repository_identifier"), v.GetString("workflow_name"))
if err != nil {
return nil, err
}

type cliVersion struct {
ID string `cli:"id"`
Version string `cli:"version"`
Type string `cli:"type"`
File string `cli:"file"`
RunID string `json:"workflow_run_id" db:"workflow_run_id"`
Username string `json:"username" db:"username"`
Created time.Time `json:"created" db:"created"`
}
cliVersions := make([]cliVersion, 0, len(versions))
for _, v := range versions {
cliVersions = append(cliVersions, cliVersion{
ID: v.ID,
Version: v.Version,
Type: v.Type,
File: v.File,
RunID: v.WorkflowRunID,
Username: v.Username,
Created: v.Created,
})
}

return cli.AsListResult(cliVersions), nil
}
2 changes: 2 additions & 0 deletions engine/api/api_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,8 @@ func (api *API) InitRouter() {
r.Handle("/v2/project/{projectKey}/vcs/{vcsIdentifier}/repository/{repositoryIdentifier}/workermodel", nil, r.GETv2(api.getWorkerModelsV2Handler))
r.Handle("/v2/project/{projectKey}/vcs/{vcsIdentifier}/repository/{repositoryIdentifier}/workermodel/{workerModelName}", nil, r.GETv2(api.getWorkerModelV2Handler))
r.Handle("/v2/project/{projectKey}/vcs/{vcsIdentifier}/repository/{repositoryIdentifier}/workflow/{workflow}/run", nil, r.POSTv2(api.postWorkflowRunV2Handler))
r.Handle("/v2/project/{projectKey}/vcs/{vcsIdentifier}/repository/{repositoryIdentifier}/workflow/{workflow}/version", nil, r.GETv2(api.getWorkflowVersionsHandler))
r.Handle("/v2/project/{projectKey}/vcs/{vcsIdentifier}/repository/{repositoryIdentifier}/workflow/{workflow}/version/{version}", nil, r.GETv2(api.getWorkflowVersionHandler), r.DELETEv2(api.deleteWorkflowVersionHandler))
r.Handle("/v2/project/{projectKey}/run", nil, r.GETv2(api.getWorkflowRunsSearchV2Handler))
r.Handle("/v2/project/{projectKey}/run/filter", nil, r.GETv2(api.getWorkflowRunsFiltersV2Handler))
r.Handle("/v2/project/{projectKey}/run/{workflowRunID}", nil, r.GETv2(api.getWorkflowRunV2Handler), r.DELETEv2(api.deleteWorkflowRunV2Handler))
Expand Down
Loading