diff --git a/go/porcelain/deploy.go b/go/porcelain/deploy.go index afe165b9..1bcee477 100644 --- a/go/porcelain/deploy.go +++ b/go/porcelain/deploy.go @@ -95,6 +95,7 @@ type DeployOptions struct { files *deployFiles functions *deployFiles functionSchedules []*models.FunctionSchedule + functionsConfig map[string]models.FunctionConfig } type uploadError struct { @@ -225,7 +226,7 @@ func (n *Netlify) DoDeploy(ctx context.Context, options *DeployOptions, deploy * options.files = files - functions, schedules, err := bundle(ctx, options.FunctionsDir, options.Observer) + functions, schedules, functionsConfig, err := bundle(ctx, options.FunctionsDir, options.Observer) if err != nil { if options.Observer != nil { options.Observer.OnFailedWalk() @@ -234,6 +235,7 @@ func (n *Netlify) DoDeploy(ctx context.Context, options *DeployOptions, deploy * } options.functions = functions options.functionSchedules = schedules + options.functionsConfig = functionsConfig deployFiles := &models.DeployFiles{ Files: options.files.Sums, @@ -255,11 +257,16 @@ func (n *Netlify) DoDeploy(ctx context.Context, options *DeployOptions, deploy * deployFiles.FunctionSchedules = schedules } + if options.functionsConfig != nil { + deployFiles.FunctionsConfig = options.functionsConfig + } + l := context.GetLogger(ctx) l.WithFields(logrus.Fields{ "site_id": options.SiteID, "deploy_files": len(options.files.Sums), "scheduled_functions": len(schedules), + "functions_config": functionsConfig, }).Debug("Starting to deploy files") authInfo := context.GetAuthInfo(ctx) @@ -649,9 +656,9 @@ func addEdgeFunctionsToDeployFiles(dir string, files *deployFiles, observer Depl }) } -func bundle(ctx context.Context, functionDir string, observer DeployObserver) (*deployFiles, []*models.FunctionSchedule, error) { +func bundle(ctx context.Context, functionDir string, observer DeployObserver) (*deployFiles, []*models.FunctionSchedule, map[string]models.FunctionConfig, error) { if functionDir == "" { - return nil, nil, nil + return nil, nil, nil, nil } manifestFile, err := os.Open(filepath.Join(functionDir, "manifest.json")) @@ -668,7 +675,7 @@ func bundle(ctx context.Context, functionDir string, observer DeployObserver) (* info, err := ioutil.ReadDir(functionDir) if err != nil { - return nil, nil, err + return nil, nil, nil, err } for _, i := range info { @@ -678,23 +685,23 @@ func bundle(ctx context.Context, functionDir string, observer DeployObserver) (* case zipFile(i): runtime, err := readZipRuntime(filePath) if err != nil { - return nil, nil, err + return nil, nil, nil, err } file, err := newFunctionFile(filePath, i, runtime, observer) if err != nil { - return nil, nil, err + return nil, nil, nil, err } functions.Add(file.Name, file) case jsFile(i): file, err := newFunctionFile(filePath, i, jsRuntime, observer) if err != nil { - return nil, nil, err + return nil, nil, nil, err } functions.Add(file.Name, file) case goFile(filePath, i, observer): file, err := newFunctionFile(filePath, i, goRuntime, observer) if err != nil { - return nil, nil, err + return nil, nil, nil, err } functions.Add(file.Name, file) default: @@ -704,14 +711,14 @@ func bundle(ctx context.Context, functionDir string, observer DeployObserver) (* } } - return functions, nil, nil + return functions, nil, nil, nil } -func bundleFromManifest(ctx context.Context, manifestFile *os.File, observer DeployObserver) (*deployFiles, []*models.FunctionSchedule, error) { +func bundleFromManifest(ctx context.Context, manifestFile *os.File, observer DeployObserver) (*deployFiles, []*models.FunctionSchedule, map[string]models.FunctionConfig, error) { manifestBytes, err := ioutil.ReadAll(manifestFile) if err != nil { - return nil, nil, err + return nil, nil, nil, err } logger := context.GetLogger(ctx) @@ -722,23 +729,24 @@ func bundleFromManifest(ctx context.Context, manifestFile *os.File, observer Dep err = json.Unmarshal(manifestBytes, &manifest) if err != nil { - return nil, nil, fmt.Errorf("malformed functions manifest file: %w", err) + return nil, nil, nil, fmt.Errorf("malformed functions manifest file: %w", err) } schedules := make([]*models.FunctionSchedule, 0, len(manifest.Functions)) functions := newDeployFiles() + functionsConfig := make(map[string]models.FunctionConfig) for _, function := range manifest.Functions { fileInfo, err := os.Stat(function.Path) if err != nil { - return nil, nil, fmt.Errorf("manifest file specifies a function path that cannot be found: %s", function.Path) + return nil, nil, nil, fmt.Errorf("manifest file specifies a function path that cannot be found: %s", function.Path) } file, err := newFunctionFile(function.Path, fileInfo, function.Runtime, observer) if err != nil { - return nil, nil, err + return nil, nil, nil, err } if function.Schedule != "" { @@ -748,10 +756,16 @@ func bundleFromManifest(ctx context.Context, manifestFile *os.File, observer Dep }) } + if function.DisplayName != "" { + functionsConfig[file.Name] = models.FunctionConfig{ + DisplayName: function.DisplayName, + } + } + functions.Add(file.Name, file) } - return functions, schedules, nil + return functions, schedules, functionsConfig, nil } func readZipRuntime(filePath string) (string, error) { diff --git a/go/porcelain/deploy_test.go b/go/porcelain/deploy_test.go index 65265b84..510da74d 100644 --- a/go/porcelain/deploy_test.go +++ b/go/porcelain/deploy_test.go @@ -306,7 +306,7 @@ func TestUploadFunctions_RetryCountHeader(t *testing.T) { defer os.RemoveAll(dir) require.NoError(t, ioutil.WriteFile(filepath.Join(functionsPath, "foo.js"), []byte("module.exports = () => {}"), 0644)) - files, _, err := bundle(ctx, functionsPath, mockObserver{}) + files, _, _, err := bundle(ctx, functionsPath, mockObserver{}) require.NoError(t, err) d := &models.Deploy{} for _, bundle := range files.Files { @@ -317,11 +317,12 @@ func TestUploadFunctions_RetryCountHeader(t *testing.T) { } func TestBundle(t *testing.T) { - functions, schedules, err := bundle(gocontext.Background(), "../internal/data", mockObserver{}) + functions, schedules, functionsConfig, err := bundle(gocontext.Background(), "../internal/data", mockObserver{}) assert.Nil(t, err) assert.Equal(t, 3, len(functions.Files)) assert.Empty(t, schedules) + assert.Nil(t, functionsConfig) jsFunction := functions.Files["hello-js-function-test"] pyFunction := functions.Files["hello-py-function-test"] @@ -344,6 +345,7 @@ func TestBundleWithManifest(t *testing.T) { "path": "%s", "runtime": "a-runtime", "mainFile": "/some/path/hello-js-function-test.js", + "displayName": "Hello Javascript Function", "name": "hello-js-function-test", "schedule": "* * * * *" }, @@ -352,7 +354,7 @@ func TestBundleWithManifest(t *testing.T) { "runtime": "some-other-runtime", "mainFile": "/some/path/hello-py-function-test", "name": "hello-py-function-test" - } + } ], "version": 1 }`, jsFunctionPath, pyFunctionPath) @@ -361,8 +363,7 @@ func TestBundleWithManifest(t *testing.T) { defer os.Remove(manifestPath) assert.Nil(t, err) - functions, schedules, err := bundle(gocontext.Background(), "../internal/data", mockObserver{}) - + functions, schedules, functionsConfig, err := bundle(gocontext.Background(), "../internal/data", mockObserver{}) assert.Nil(t, err) assert.Equal(t, 1, len(schedules)) @@ -372,6 +373,9 @@ func TestBundleWithManifest(t *testing.T) { assert.Equal(t, 2, len(functions.Files)) assert.Equal(t, "a-runtime", functions.Files["hello-js-function-test"].Runtime) assert.Equal(t, "some-other-runtime", functions.Files["hello-py-function-test"].Runtime) + + assert.Equal(t, 1, len(functionsConfig)) + assert.Equal(t, "Hello Javascript Function", functionsConfig["hello-js-function-test"].DisplayName) } func TestReadZipRuntime(t *testing.T) { diff --git a/go/porcelain/functions_manifest.go b/go/porcelain/functions_manifest.go index d492ee3d..d8384e23 100644 --- a/go/porcelain/functions_manifest.go +++ b/go/porcelain/functions_manifest.go @@ -12,4 +12,5 @@ type functionsManifestEntry struct { Path string `json:"path"` Runtime string `json:"runtime"` Schedule string `json:"schedule"` + DisplayName string `json:"displayName"` }