diff --git a/cli/cdsctl/workflow_run_result.go b/cli/cdsctl/workflow_run_result.go index 7d9d216778..7a54437009 100644 --- a/cli/cdsctl/workflow_run_result.go +++ b/cli/cdsctl/workflow_run_result.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "os" + "os/exec" "regexp" "github.com/spf13/cobra" @@ -81,6 +82,9 @@ func workflowRunResultGet(v cli.Values) error { var fileName string var perm uint32 var md5 string + var artifactManagerPath string + var artifactManagerRepo string + switch r.Type { case sdk.WorkflowRunResultTypeArtifact: art, err := r.GetArtifact() @@ -100,6 +104,16 @@ func workflowRunResultGet(v cli.Values) error { fileName = cov.Name perm = cov.Perm md5 = cov.MD5 + case sdk.WorkflowRunResultTypeArtifactManager: + art, err := r.GetArtifactManager() + if err != nil { + return err + } + fileName = art.Name + perm = art.Perm + md5 = art.MD5 + artifactManagerPath = art.Path + artifactManagerRepo = art.RepoName default: return cli.NewError("cannot get result of type %s", r.Type) } @@ -124,7 +138,27 @@ func workflowRunResultGet(v cli.Values) error { } } - if toDownload { + if !toDownload { + fmt.Printf("File %s already downloaded, checksum OK\n", f.Name()) + return nil + } + + if artifactManagerPath != "" && artifactManagerRepo != "" { + _, err := exec.LookPath("jfrog") + if err != nil { + fmt.Printf("# File is available on repository %s: %s\n", artifactManagerRepo, artifactManagerPath) + fmt.Printf("# to download the file use the following command\n") + fmt.Printf("jfrog rt download %s %q", artifactManagerRepo, artifactManagerPath) + return err + } + cmd := exec.Command("jfrog", "rt", "download", "--flat", artifactManagerRepo+"/"+artifactManagerPath) + output, err := cmd.CombinedOutput() + fmt.Println(string(output)) + if err != nil { + return err + } + return nil + } else { var err error f, err = os.OpenFile(fileName, os.O_RDWR|os.O_CREATE|os.O_TRUNC, os.FileMode(perm)) if err != nil { @@ -139,11 +173,8 @@ func workflowRunResultGet(v cli.Values) error { return cli.NewError("unable to close file %s: %v", fileName, err) } } - if toDownload { - fmt.Printf("File %s created, checksum OK\n", f.Name()) - } else { - fmt.Printf("File %s already downloaded, checksum OK\n", f.Name()) - } + + fmt.Printf("File %s created, checksum OK\n", f.Name()) } return nil } @@ -224,13 +255,19 @@ func toCLIRunResult(results []sdk.WorkflowRunResult) ([]RunResultCli, error) { return nil, err } name = artiResult.Name + artiType = "file" case sdk.WorkflowRunResultTypeArtifactManager: artiResult, err := r.GetArtifactManager() if err != nil { return nil, err } name = artiResult.Name - artiType = artiResult.RepoType + if artiResult.FileType != "" { + artiType = artiResult.FileType + } else { + artiType = artiResult.RepoType + } + } cliresults = append(cliresults, RunResultCli{ diff --git a/engine/api/artifact.go b/engine/api/artifact.go index 61523f7b49..7e01da83ff 100644 --- a/engine/api/artifact.go +++ b/engine/api/artifact.go @@ -10,6 +10,8 @@ import ( "github.com/ovh/cds/sdk" ) +// DEPRECATED +// TODO: remove this code after CDN would be mandatory func (api *API) getArtifactsStoreHandler() service.Handler { return func(ctx context.Context, w http.ResponseWriter, r *http.Request) error { vars := mux.Vars(r) diff --git a/engine/api/objectstore/objectstore.go b/engine/api/objectstore/objectstore.go index 4a5eb9cb86..56cd18ab1a 100644 --- a/engine/api/objectstore/objectstore.go +++ b/engine/api/objectstore/objectstore.go @@ -21,7 +21,7 @@ type Driver interface { GetProjectIntegration() sdk.ProjectIntegration Status(ctx context.Context) sdk.MonitoringStatusLine Store(o Object, data io.ReadCloser) (string, error) - ServeStaticFiles(o Object, entrypoint string, data io.ReadCloser) (string, error) + ServeStaticFiles(o Object, entrypoint string, data io.ReadCloser) (string, error) // DEPRECATED Fetch(ctx context.Context, o Object) (io.ReadCloser, error) Delete(ctx context.Context, o Object) error DeleteContainer(ctx context.Context, containerPath string) error diff --git a/engine/api/workflow/dao_node_run.go b/engine/api/workflow/dao_node_run.go index 75bb990106..7496732710 100644 --- a/engine/api/workflow/dao_node_run.go +++ b/engine/api/workflow/dao_node_run.go @@ -92,6 +92,7 @@ func LoadNodeRun(db gorp.SqlExecutor, projectkey, workflowname string, noderunID } r.Artifacts = arts } + // DEPRECATED if loadOpts.WithStaticFiles { staticFiles, errS := loadStaticFilesByNodeRunID(db, r.ID) if errS != nil { diff --git a/engine/api/workflow/dao_run.go b/engine/api/workflow/dao_run.go index c7d4f0583b..95fb6aed6d 100644 --- a/engine/api/workflow/dao_run.go +++ b/engine/api/workflow/dao_run.go @@ -48,7 +48,7 @@ workflow_run.header type LoadRunOptions struct { WithCoverage bool WithArtifacts bool - WithStaticFiles bool + WithStaticFiles bool //DEPRECATED WithTests bool WithLightTests bool WithVulnerabilities bool @@ -981,6 +981,7 @@ func syncNodeRuns(db gorp.SqlExecutor, wr *sdk.WorkflowRun, loadOpts LoadRunOpti wnr.Artifacts = arts } + // DEPRECATED if loadOpts.WithStaticFiles { staticFiles, errS := loadStaticFilesByNodeRunID(db, wnr.ID) if errS != nil { diff --git a/engine/api/workflow/dao_staticfiles.go b/engine/api/workflow/dao_staticfiles.go index e5230af0b3..2e732a0d38 100644 --- a/engine/api/workflow/dao_staticfiles.go +++ b/engine/api/workflow/dao_staticfiles.go @@ -9,6 +9,7 @@ import ( "github.com/ovh/cds/sdk" ) +// DEPRECATED func loadStaticFilesByNodeRunID(db gorp.SqlExecutor, nodeRunID int64) ([]sdk.StaticFiles, error) { var dbstaticFiles []dbStaticFiles if _, err := db.Select(&dbstaticFiles, `SELECT @@ -32,6 +33,7 @@ func loadStaticFilesByNodeRunID(db gorp.SqlExecutor, nodeRunID int64) ([]sdk.Sta return staticFiles, nil } +// DEPRECATED // InsertStaticFiles insert in table workflow_artifacts func InsertStaticFiles(db gorp.SqlExecutor, sf *sdk.StaticFiles) error { sf.Created = time.Now() diff --git a/engine/api/workflow/workflow_run_results.go b/engine/api/workflow/workflow_run_results.go index 6a5493e4f9..383fca470c 100644 --- a/engine/api/workflow/workflow_run_results.go +++ b/engine/api/workflow/workflow_run_results.go @@ -216,6 +216,9 @@ func verifyAddResultArtifactManager(ctx context.Context, db gorp.SqlExecutor, st artResult.Size = fileInfo.Size artResult.MD5 = fileInfo.Md5 artResult.RepoType = fileInfo.Type + if artResult.FileType == "" { + artResult.FileType = artResult.RepoType + } if err := artResult.IsValid(); err != nil { return "", err diff --git a/engine/api/workflow_queue_storage.go b/engine/api/workflow_queue_storage.go index 2bebc6bbe3..2330691ead 100644 --- a/engine/api/workflow_queue_storage.go +++ b/engine/api/workflow_queue_storage.go @@ -18,6 +18,7 @@ import ( "github.com/ovh/cds/sdk" ) +// DEPRECATED func (api *API) postWorkflowJobStaticFilesHandler() service.Handler { return func(ctx context.Context, w http.ResponseWriter, r *http.Request) error { if isWorker := isWorker(ctx); !isWorker { @@ -121,6 +122,8 @@ func (api *API) postWorkflowJobStaticFilesHandler() service.Handler { } } +// DEPRECATED +// TODO: remove this code after CDN would be mandatory func (api *API) postWorkflowJobArtifactHandler() service.Handler { return func(ctx context.Context, w http.ResponseWriter, r *http.Request) error { if isWorker := isWorker(ctx); !isWorker { @@ -251,6 +254,8 @@ func (api *API) postWorkflowJobArtifactHandler() service.Handler { } } +// DEPRECATED +// TODO: remove this code after CDN would be mandatory func (api *API) postWorkflowJobArtifactWithTempURLCallbackHandler() service.Handler { return func(ctx context.Context, w http.ResponseWriter, r *http.Request) error { if isWorker := isWorker(ctx); !isWorker { @@ -307,6 +312,8 @@ func (api *API) postWorkflowJobArtifactWithTempURLCallbackHandler() service.Hand } } +// DEPRECATED +// TODO: remove this code after CDN would be mandatory func (api *API) postWorkflowJobArtifacWithTempURLHandler() service.Handler { return func(ctx context.Context, w http.ResponseWriter, r *http.Request) error { if isWorker := isWorker(ctx); !isWorker { diff --git a/engine/worker/cmd_run_result.go b/engine/worker/cmd_run_result.go index 22a082e99e..77c1d91531 100644 --- a/engine/worker/cmd_run_result.go +++ b/engine/worker/cmd_run_result.go @@ -96,19 +96,24 @@ Example: func addArtifactManagerRunResultCmd() func(cmd *cobra.Command, args []string) { return func(cmd *cobra.Command, args []string) { - if len(args) != 3 { - sdk.Exit("missing arguments. Cmd: worker run-result add artifact-manager ") + if len(args) != 3 && len(args) != 4 { + sdk.Exit("missing arguments. Cmd: worker run-result add artifact-manager [file-type]") } fileName := args[0] repositoryName := args[1] filePath := args[2] + var fileType string + if len(args) == 4 { + fileType = args[3] + } payload := sdk.WorkflowRunResultArtifactManager{ Name: fileName, Perm: 0, Path: filePath, RepoName: repositoryName, + FileType: fileType, } data, _ := json.Marshal(payload) diff --git a/engine/worker/internal/action/builtin_artifact_upload.go b/engine/worker/internal/action/builtin_artifact_upload.go index 60cb8e8be6..d5f13edebe 100644 --- a/engine/worker/internal/action/builtin_artifact_upload.go +++ b/engine/worker/internal/action/builtin_artifact_upload.go @@ -49,7 +49,17 @@ func RunArtifactUpload(ctx context.Context, wk workerruntime.Runtime, a sdk.Acti artifactPath = filepath.Join(abs, artifactPath) } - tag := sdk.ParameterFind(a.Parameters, "tag") + tagParam := sdk.ParameterFind(a.Parameters, "tag") + var tag string + if tagParam != nil { + tag = tagParam.Value + } + + fileTypeParam := sdk.ParameterFind(a.Parameters, "type") + var fileType string + if fileTypeParam != nil { + fileType = fileTypeParam.Value + } // Global all files matching filePath filesPath, err := afero.Glob(afero.NewOsFs(), artifactPath) @@ -91,18 +101,18 @@ func RunArtifactUpload(ctx context.Context, wk workerruntime.Runtime, a sdk.Acti // 2. Integration artifact manager on workflow // 3. CDN activated or not if integrationName != sdk.DefaultStorageIntegrationName { - if err := uploadArtifactByApiCall(path, wk, ctx, projectKey, integrationName, jobID, tag); err != nil { + if err := uploadArtifactByApiCall(path, wk, ctx, projectKey, integrationName, jobID, tag, fileType); err != nil { chanError <- sdk.WrapError(err, "Error while uploading artifact by api call %s", path) wgErrors.Add(1) } return } else if pluginArtifactManagement != nil { - if err := uploadArtifactByIntegrationPlugin(path, ctx, wk, pluginArtifactManagement); err != nil { + if err := uploadArtifactByIntegrationPlugin(path, ctx, wk, pluginArtifactManagement, fileType); err != nil { chanError <- sdk.WrapError(err, "Error while uploading artifact by plugin %s", path) wgErrors.Add(1) } } else if !cdnArtifactEnabled { - if err := uploadArtifactByApiCall(path, wk, ctx, projectKey, integrationName, jobID, tag); err != nil { + if err := uploadArtifactByApiCall(path, wk, ctx, projectKey, integrationName, jobID, tag, fileType); err != nil { chanError <- sdk.WrapError(err, "Error while uploading artifact by api call %s", path) wgErrors.Add(1) } @@ -133,7 +143,7 @@ func RunArtifactUpload(ctx context.Context, wk workerruntime.Runtime, a sdk.Acti return res, nil } -func uploadArtifactByIntegrationPlugin(path string, ctx context.Context, wk workerruntime.Runtime, artiManager *sdk.GRPCPlugin) error { +func uploadArtifactByIntegrationPlugin(path string, ctx context.Context, wk workerruntime.Runtime, artiManager *sdk.GRPCPlugin, fileType string) error { _, fileName := filepath.Split(path) // Check run result @@ -205,6 +215,8 @@ func uploadArtifactByIntegrationPlugin(path string, ctx context.Context, wk work return fmt.Errorf("error uploading artifact: %v", err) } + res.Outputs[sdk.ArtifactUploadPluginOutputFileType] = fileType + if strings.ToUpper(res.Status) != strings.ToUpper(sdk.StatusSuccess) { return fmt.Errorf("plugin execution failed %s: %s", res.Status, res.Details) } @@ -237,11 +249,8 @@ func uploadArtifactIntoCDN(path string, ctx context.Context, wk workerruntime.Ru return nil } -func uploadArtifactByApiCall(path string, wk workerruntime.Runtime, ctx context.Context, projectKey string, integrationName string, jobID int64, tag *sdk.Parameter) error { - if tag == nil { - return sdk.NewError(sdk.ErrWorkerErrorCommand, fmt.Errorf("tag variable is empty. aborting")) - } - throughTempURL, duration, err := wk.Client().QueueArtifactUpload(ctx, projectKey, integrationName, jobID, tag.Value, path) +func uploadArtifactByApiCall(path string, wk workerruntime.Runtime, ctx context.Context, projectKey string, integrationName string, jobID int64, tag, fileType string) error { + throughTempURL, duration, err := wk.Client().QueueArtifactUpload(ctx, projectKey, integrationName, jobID, tag, path, fileType) if err != nil { return err } @@ -282,6 +291,7 @@ func addWorkflowRunResult(ctx context.Context, wk workerruntime.Runtime, filePat Perm: uint32(perm), RepoName: uploadResult.Outputs[sdk.ArtifactUploadPluginOutputPathRepoName], Path: uploadResult.Outputs[sdk.ArtifactUploadPluginOutputPathFilePath], + FileType: uploadResult.Outputs[sdk.ArtifactUploadPluginOutputFileType], } bts, err := json.Marshal(data) diff --git a/engine/worker/internal/action/builtin_coverage.go b/engine/worker/internal/action/builtin_coverage.go index 4c168c7b8d..59c8af3426 100644 --- a/engine/worker/internal/action/builtin_coverage.go +++ b/engine/worker/internal/action/builtin_coverage.go @@ -84,7 +84,7 @@ func RunParseCoverageResultAction(ctx context.Context, wk workerruntime.Runtime, pluginArtifactManagement := wk.GetPlugin(sdk.GRPCPluginUploadArtifact) if pluginArtifactManagement != nil { - if err := uploadArtifactByIntegrationPlugin(fpath, ctx, wk, pluginArtifactManagement); err != nil { + if err := uploadArtifactByIntegrationPlugin(fpath, ctx, wk, pluginArtifactManagement, sdk.ArtifactFileTypeCoverage); err != nil { return res, fmt.Errorf("coverage parser: unable to upload in artifact manager: %v", err) } } else { diff --git a/sdk/artifact.go b/sdk/artifact.go index 43059897cc..ef2cb9e06f 100644 --- a/sdk/artifact.go +++ b/sdk/artifact.go @@ -15,11 +15,14 @@ const ( ArtifactUploadPluginOutputPathMD5 = "md5" ArtifactUploadPluginOutputPerm = "perm" ArtifactUploadPluginOutputSize = "size" + ArtifactUploadPluginOutputFileType = "file_type" ArtifactDownloadPluginInputDestinationPath = "cds.integration.artifact_manager.download.destination.path" ArtifactDownloadPluginInputFilePath = "cds.integration.artifact_manager.download.file.path" ArtifactDownloadPluginInputMd5 = "cds.integration.artifact_manager.download.file.md5" ArtifactDownloadPluginInputPerm = "cds.integration.artifact_manager.download.file.perm" + + ArtifactFileTypeCoverage = "coverage" ) // ArtifactsStore represents diff --git a/sdk/cdsclient/client_queue.go b/sdk/cdsclient/client_queue.go index d85f4f8125..8d28f151cd 100644 --- a/sdk/cdsclient/client_queue.go +++ b/sdk/cdsclient/client_queue.go @@ -264,19 +264,21 @@ func (c *client) QueueSendStepResult(ctx context.Context, id int64, res sdk.Step return err } -func (c *client) QueueArtifactUpload(ctx context.Context, projectKey, integrationName string, nodeJobRunID int64, tag, filePath string) (bool, time.Duration, error) { +func (c *client) QueueArtifactUpload(ctx context.Context, projectKey, integrationName string, nodeJobRunID int64, tag, filePath, fileType string) (bool, time.Duration, error) { t0 := time.Now() store := new(sdk.ArtifactsStore) uri := fmt.Sprintf("/project/%s/storage/%s", projectKey, integrationName) _, _ = c.GetJSON(ctx, uri, store) if store.TemporaryURLSupported { - err := c.queueIndirectArtifactUpload(ctx, projectKey, integrationName, nodeJobRunID, tag, filePath) + err := c.queueIndirectArtifactUpload(ctx, projectKey, integrationName, nodeJobRunID, tag, filePath, fileType) return true, time.Since(t0), err } - err := c.queueDirectArtifactUpload(projectKey, integrationName, nodeJobRunID, tag, filePath) + err := c.queueDirectArtifactUpload(projectKey, integrationName, nodeJobRunID, tag, filePath, fileType) return false, time.Since(t0), err } +// DEPRECATED +// TODO: remove this code after CDN would be mandatory func (c *client) queueIndirectArtifactTempURL(ctx context.Context, projectKey, integrationName string, art *sdk.WorkflowNodeRunArtifact) error { var retryURL = 10 var globalURLErr error @@ -297,6 +299,8 @@ func (c *client) queueIndirectArtifactTempURL(ctx context.Context, projectKey, i return globalURLErr } +// DEPRECATED +// TODO: remove this code after CDN would be mandatory func (c *client) queueIndirectArtifactTempURLPost(url string, content []byte) error { //Post the file to the temporary URL var retry = 10 @@ -335,7 +339,9 @@ func (c *client) queueIndirectArtifactTempURLPost(url string, content []byte) er return globalErr } -func (c *client) queueIndirectArtifactUpload(ctx context.Context, projectKey, integrationName string, nodeJobRunID int64, tag, filePath string) error { +// DEPRECATED +// TODO: remove this code after CDN would be mandatory +func (c *client) queueIndirectArtifactUpload(ctx context.Context, projectKey, integrationName string, nodeJobRunID int64, tag, filePath, fileType string) error { f, errop := os.Open(filePath) if errop != nil { return errop @@ -416,7 +422,9 @@ func (c *client) queueIndirectArtifactUpload(ctx context.Context, projectKey, in return callbackErr } -func (c *client) queueDirectArtifactUpload(projectKey, integrationName string, nodeJobRunID int64, tag, filePath string) error { +// DEPRECATED +// TODO: remove this code after CDN would be mandatory +func (c *client) queueDirectArtifactUpload(projectKey, integrationName string, nodeJobRunID int64, tag, filePath, fileType string) error { f, errop := os.Open(filePath) if errop != nil { return errop @@ -506,7 +514,8 @@ func (c *client) QueueJobSetVersion(ctx context.Context, jobID int64, version sd } // STATIC FILES ----- - +// DEPRECATED +// TODO: remove this code after CDN would be mandatory func (c *client) QueueStaticFilesUpload(ctx context.Context, projectKey, integrationName string, nodeJobRunID int64, name, entrypoint, staticKey string, tarContent io.Reader) (string, bool, time.Duration, error) { t0 := time.Now() staticFile := sdk.StaticFiles{ @@ -527,6 +536,8 @@ func (c *client) QueueStaticFilesUpload(ctx context.Context, projectKey, integra return publicURL, false, time.Since(t0), err } +// DEPRECATED +// TODO: remove this code after CDN would be mandatory func (c *client) queueDirectStaticFilesUpload(projectKey, integrationName string, staticFile *sdk.StaticFiles, tarContent io.Reader) (string, error) { body := &bytes.Buffer{} writer := multipart.NewWriter(body) diff --git a/sdk/cdsclient/interface.go b/sdk/cdsclient/interface.go index fc50766d11..0bf6ee3404 100644 --- a/sdk/cdsclient/interface.go +++ b/sdk/cdsclient/interface.go @@ -267,7 +267,7 @@ type QueueClient interface { QueueSendVulnerability(ctx context.Context, id int64, report sdk.VulnerabilityWorkerReport) error QueueSendStepResult(ctx context.Context, id int64, res sdk.StepStatus) error QueueSendResult(ctx context.Context, id int64, res sdk.Result) error - QueueArtifactUpload(ctx context.Context, projectKey, integrationName string, nodeJobRunID int64, tag, filePath string) (bool, time.Duration, error) + QueueArtifactUpload(ctx context.Context, projectKey, integrationName string, nodeJobRunID int64, tag, filePath, fileType string) (bool, time.Duration, error) QueueStaticFilesUpload(ctx context.Context, projectKey, integrationName string, nodeJobRunID int64, name, entrypoint, staticKey string, tarContent io.Reader) (string, bool, time.Duration, error) QueueJobTag(ctx context.Context, jobID int64, tags []sdk.WorkflowRunTag) error QueueJobSetVersion(ctx context.Context, jobID int64, version sdk.WorkflowRunVersion) error diff --git a/sdk/cdsclient/mock_cdsclient/interface_mock.go b/sdk/cdsclient/mock_cdsclient/interface_mock.go index 26a4aba41a..3c5eae36e6 100644 --- a/sdk/cdsclient/mock_cdsclient/interface_mock.go +++ b/sdk/cdsclient/mock_cdsclient/interface_mock.go @@ -3093,9 +3093,9 @@ func (m *MockQueueClient) EXPECT() *MockQueueClientMockRecorder { } // QueueArtifactUpload mocks base method. -func (m *MockQueueClient) QueueArtifactUpload(ctx context.Context, projectKey, integrationName string, nodeJobRunID int64, tag, filePath string) (bool, time.Duration, error) { +func (m *MockQueueClient) QueueArtifactUpload(ctx context.Context, projectKey, integrationName string, nodeJobRunID int64, tag, filePath, fileType string) (bool, time.Duration, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "QueueArtifactUpload", ctx, projectKey, integrationName, nodeJobRunID, tag, filePath) + ret := m.ctrl.Call(m, "QueueArtifactUpload", ctx, projectKey, integrationName, nodeJobRunID, tag, filePath, fileType) ret0, _ := ret[0].(bool) ret1, _ := ret[1].(time.Duration) ret2, _ := ret[2].(error) @@ -3103,9 +3103,9 @@ func (m *MockQueueClient) QueueArtifactUpload(ctx context.Context, projectKey, i } // QueueArtifactUpload indicates an expected call of QueueArtifactUpload. -func (mr *MockQueueClientMockRecorder) QueueArtifactUpload(ctx, projectKey, integrationName, nodeJobRunID, tag, filePath interface{}) *gomock.Call { +func (mr *MockQueueClientMockRecorder) QueueArtifactUpload(ctx, projectKey, integrationName, nodeJobRunID, tag, filePath, fileType interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueueArtifactUpload", reflect.TypeOf((*MockQueueClient)(nil).QueueArtifactUpload), ctx, projectKey, integrationName, nodeJobRunID, tag, filePath) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueueArtifactUpload", reflect.TypeOf((*MockQueueClient)(nil).QueueArtifactUpload), ctx, projectKey, integrationName, nodeJobRunID, tag, filePath, fileType) } // QueueCountWorkflowNodeJobRun mocks base method. @@ -7123,9 +7123,9 @@ func (mr *MockInterfaceMockRecorder) PutJSON(ctx, path, in, out interface{}, mod } // QueueArtifactUpload mocks base method. -func (m *MockInterface) QueueArtifactUpload(ctx context.Context, projectKey, integrationName string, nodeJobRunID int64, tag, filePath string) (bool, time.Duration, error) { +func (m *MockInterface) QueueArtifactUpload(ctx context.Context, projectKey, integrationName string, nodeJobRunID int64, tag, filePath, fileType string) (bool, time.Duration, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "QueueArtifactUpload", ctx, projectKey, integrationName, nodeJobRunID, tag, filePath) + ret := m.ctrl.Call(m, "QueueArtifactUpload", ctx, projectKey, integrationName, nodeJobRunID, tag, filePath, fileType) ret0, _ := ret[0].(bool) ret1, _ := ret[1].(time.Duration) ret2, _ := ret[2].(error) @@ -7133,9 +7133,9 @@ func (m *MockInterface) QueueArtifactUpload(ctx context.Context, projectKey, int } // QueueArtifactUpload indicates an expected call of QueueArtifactUpload. -func (mr *MockInterfaceMockRecorder) QueueArtifactUpload(ctx, projectKey, integrationName, nodeJobRunID, tag, filePath interface{}) *gomock.Call { +func (mr *MockInterfaceMockRecorder) QueueArtifactUpload(ctx, projectKey, integrationName, nodeJobRunID, tag, filePath, fileType interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueueArtifactUpload", reflect.TypeOf((*MockInterface)(nil).QueueArtifactUpload), ctx, projectKey, integrationName, nodeJobRunID, tag, filePath) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueueArtifactUpload", reflect.TypeOf((*MockInterface)(nil).QueueArtifactUpload), ctx, projectKey, integrationName, nodeJobRunID, tag, filePath, fileType) } // QueueCountWorkflowNodeJobRun mocks base method. @@ -9223,9 +9223,9 @@ func (mr *MockWorkerInterfaceMockRecorder) ProjectIntegrationWorkerHookGet(proje } // QueueArtifactUpload mocks base method. -func (m *MockWorkerInterface) QueueArtifactUpload(ctx context.Context, projectKey, integrationName string, nodeJobRunID int64, tag, filePath string) (bool, time.Duration, error) { +func (m *MockWorkerInterface) QueueArtifactUpload(ctx context.Context, projectKey, integrationName string, nodeJobRunID int64, tag, filePath, fileType string) (bool, time.Duration, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "QueueArtifactUpload", ctx, projectKey, integrationName, nodeJobRunID, tag, filePath) + ret := m.ctrl.Call(m, "QueueArtifactUpload", ctx, projectKey, integrationName, nodeJobRunID, tag, filePath, fileType) ret0, _ := ret[0].(bool) ret1, _ := ret[1].(time.Duration) ret2, _ := ret[2].(error) @@ -9233,9 +9233,9 @@ func (m *MockWorkerInterface) QueueArtifactUpload(ctx context.Context, projectKe } // QueueArtifactUpload indicates an expected call of QueueArtifactUpload. -func (mr *MockWorkerInterfaceMockRecorder) QueueArtifactUpload(ctx, projectKey, integrationName, nodeJobRunID, tag, filePath interface{}) *gomock.Call { +func (mr *MockWorkerInterfaceMockRecorder) QueueArtifactUpload(ctx, projectKey, integrationName, nodeJobRunID, tag, filePath, fileType interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueueArtifactUpload", reflect.TypeOf((*MockWorkerInterface)(nil).QueueArtifactUpload), ctx, projectKey, integrationName, nodeJobRunID, tag, filePath) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueueArtifactUpload", reflect.TypeOf((*MockWorkerInterface)(nil).QueueArtifactUpload), ctx, projectKey, integrationName, nodeJobRunID, tag, filePath, fileType) } // QueueCountWorkflowNodeJobRun mocks base method. diff --git a/sdk/static_files.go b/sdk/static_files.go index e300b6dd3a..18b234631b 100644 --- a/sdk/static_files.go +++ b/sdk/static_files.go @@ -7,6 +7,7 @@ import ( "time" ) +// DEPRECATED // StaticFiles define a files needed to be save for serving static files type StaticFiles struct { ID int64 `json:"id" db:"id" cli:"id"` diff --git a/sdk/workflow_run_result.go b/sdk/workflow_run_result.go index a085c01263..b159e2f5bc 100644 --- a/sdk/workflow_run_result.go +++ b/sdk/workflow_run_result.go @@ -31,6 +31,7 @@ func (r *WorkflowRunResult) GetArtifact() (WorkflowRunResultArtifact, error) { if err := JSONUnmarshal(r.DataRaw, &data); err != nil { return data, WithStack(err) } + return data, nil } @@ -47,6 +48,9 @@ func (r *WorkflowRunResult) GetArtifactManager() (WorkflowRunResultArtifactManag if err := JSONUnmarshal(r.DataRaw, &data); err != nil { return data, WithStack(err) } + if data.FileType == "" { + data.FileType = data.RepoType + } return data, nil } @@ -74,6 +78,7 @@ type WorkflowRunResultArtifactManager struct { Perm uint32 `json:"perm"` RepoName string `json:"repository_name"` RepoType string `json:"repository_type"` + FileType string `json:"file_type"` } func (a *WorkflowRunResultArtifactManager) IsValid() error { @@ -113,6 +118,7 @@ type WorkflowRunResultArtifact struct { MD5 string `json:"md5"` CDNRefHash string `json:"cdn_hash"` Perm uint32 `json:"perm"` + FileType string `json:"file_type"` } func (a *WorkflowRunResultArtifact) IsValid() error { diff --git a/ui/src/app/model/workflow.run.model.ts b/ui/src/app/model/workflow.run.model.ts index 836a372281..859cc7f708 100644 --- a/ui/src/app/model/workflow.run.model.ts +++ b/ui/src/app/model/workflow.run.model.ts @@ -153,6 +153,7 @@ export class UIArtifact { human_size: string; link: string; type: string; + file_type: string; } @@ -170,6 +171,7 @@ export class WorkflowRunResultArtifactManager { path: string; repository_name: string; repository_type: string; + file_type: string; } export class WorkflowRunResultStaticFile { diff --git a/ui/src/app/service/workflow/workflow.helper.ts b/ui/src/app/service/workflow/workflow.helper.ts index c7a73bd7b7..8318060a83 100644 --- a/ui/src/app/service/workflow/workflow.helper.ts +++ b/ui/src/app/service/workflow/workflow.helper.ts @@ -23,7 +23,8 @@ export class WorkflowHelper { uiArtifact.name = data.name; uiArtifact.size = data.size; uiArtifact.human_size = this.getHumainFileSize(data.size); - uiArtifact.type = 'file'; + uiArtifact.type = r.type == 'artifact' ? 'file': r.type; + uiArtifact.file_type = uiArtifact.type; return uiArtifact; case 'artifact-manager': let dataAM = r.data; @@ -34,6 +35,7 @@ export class WorkflowHelper { uiArtifactAM.size = dataAM.size; uiArtifactAM.human_size = this.getHumainFileSize(dataAM.size); uiArtifactAM.type = dataAM.repository_type; + uiArtifactAM.file_type = dataAM.file_type ? dataAM.file_type : dataAM.repository_type; return uiArtifactAM; case 'static-file': let dataSF = r.data; diff --git a/ui/src/app/views/workflow/run/node/artifact/artifact.list.component.ts b/ui/src/app/views/workflow/run/node/artifact/artifact.list.component.ts index 4a1af2a086..87a90767eb 100644 --- a/ui/src/app/views/workflow/run/node/artifact/artifact.list.component.ts +++ b/ui/src/app/views/workflow/run/node/artifact/artifact.list.component.ts @@ -57,7 +57,7 @@ export class WorkflowRunArtifactListComponent implements OnInit, OnDestroy { }, >{ name: 'Type of artifact', - selector: (a: UIArtifact) => a.type + selector: (a: UIArtifact) => a.file_type }, >{ type: ColumnType.TEXT_COPY, @@ -112,6 +112,7 @@ export class WorkflowRunArtifactListComponent implements OnInit, OnDestroy { uiArt.md5 = a.md5sum; uiArt.type = 'file'; uiArt.link = `./cdsapi/workflow/artifact/${a.download_hash}`; + uiArt.file_type = uiArt.type; return uiArt; }); this.uiArtifacts.push(...uiArtifacts);