From c4a7e72dd61171848cb260cbba84406cc9423062 Mon Sep 17 00:00:00 2001 From: Victor Vazquez Date: Tue, 7 Mar 2023 15:17:03 -0800 Subject: [PATCH 1/8] resolve default after looking at azure.yaml --- cli/azd/cmd/pipeline.go | 4 ++- cli/azd/pkg/commands/pipeline/pipeline.go | 39 +++++++++++++++-------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/cli/azd/cmd/pipeline.go b/cli/azd/cmd/pipeline.go index 4b650a8712e..d69626ba5e9 100644 --- a/cli/azd/cmd/pipeline.go +++ b/cli/azd/cmd/pipeline.go @@ -49,7 +49,9 @@ func (pc *pipelineConfigFlags) Bind(local *pflag.FlagSet, global *internal.Globa "The authentication type used between the pipeline provider and Azure for deployment (Only valid for GitHub provider)", ) local.StringVar(&pc.PipelineRoleName, "principal-role", "contributor", "The role to assign to the service principal.") - local.StringVar(&pc.PipelineProvider, "provider", "github", + // default provider is empty because it can be set from azure.yaml. By letting default here be empty, we know that + // there no customer input using --provider + local.StringVar(&pc.PipelineProvider, "provider", "", "The pipeline provider to use (github for Github Actions and azdo for Azure Pipelines).") pc.envFlag.Bind(local, global) pc.global = global diff --git a/cli/azd/pkg/commands/pipeline/pipeline.go b/cli/azd/pkg/commands/pipeline/pipeline.go index 2f53733c0ab..a861a8c601b 100644 --- a/cli/azd/pkg/commands/pipeline/pipeline.go +++ b/cli/azd/pkg/commands/pipeline/pipeline.go @@ -124,6 +124,28 @@ const ( envPersistedKey string = "AZD_PIPELINE_PROVIDER" ) +func resolveProvider(env *environment.Environment, projectPath string) (string, error) { + // 1) if provider is set on azure.yaml, it should override the `lastUsedProvider`, as it can be changed by customer + // at any moment. + prj, err := project.LoadProjectConfig(projectPath) + if err != nil { + return "", fmt.Errorf("finding pipeline provider: %w", err) + } + if prj.Pipeline.Provider != "" { + return prj.Pipeline.Provider, nil + } + + // 2) check if there is a persisted value from a previous run in env + if lastUsedProvider, configExists := env.Values[envPersistedKey]; configExists { + // Setting override value based on last run. This will force detector to use the same + // configuration. + return lastUsedProvider, nil + } + + // 3) No config on azure.yaml or from previous run. Return default -> GitHub + return gitHubLabel, nil +} + // DetectProviders get azd context from the context and pulls the project directory from it. // Depending on the project directory, returns pipeline scm and ci providers based on: // - if .github folder is found and .azdo folder is missing: GitHub scm and ci as provider @@ -167,22 +189,11 @@ func DetectProviders( // we can re-assign it based on a previous run (persisted data) // or based on the azure.yaml if overrideWith == "" { - // check if there is a persisted value from a previous run in env - lastUsedProvider, configExists := env.Values[envPersistedKey] - if configExists { - // Setting override value based on last run. This will force detector to use the same - // configuration. - overrideWith = lastUsedProvider - } - // Figure out what is the expected provider to use for provisioning - prj, err := project.LoadProjectConfig(azdContext.ProjectPath()) + resolved, err := resolveProvider(env, azdContext.ProjectPath()) if err != nil { - return nil, nil, fmt.Errorf("finding pipeline provider: %w", err) + return nil, nil, fmt.Errorf("resolving provider when no provider arg was used: %w", err) } - if prj.Pipeline.Provider != "" { - overrideWith = prj.Pipeline.Provider - } - + overrideWith = resolved } // Check override errors for missing folder From 7d1763456bd234801effe37d18b221b06ccaa7d5 Mon Sep 17 00:00:00 2001 From: Victor Vazquez Date: Tue, 7 Mar 2023 15:23:45 -0800 Subject: [PATCH 2/8] cl --- cli/azd/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/azd/CHANGELOG.md b/cli/azd/CHANGELOG.md index 5c5db0d5801..e74e11bee13 100644 --- a/cli/azd/CHANGELOG.md +++ b/cli/azd/CHANGELOG.md @@ -14,6 +14,7 @@ - [[#1631]](https://github.com/Azure/azure-dev/pull/1631) Fail fast during `azd init` when `git` is not installed. - [[#1559]](https://github.com/Azure/azure-dev/pull/1559) No feedback output during provisioning some templates. +- [[#1683]](https://github.com/Azure/azure-dev/pull/1683) Fix `azd pipeline config` to honor provider from `azure.yaml`. ### Other Changes From 0ae2822f76b7377e2a55b2ff954d18edb956e357 Mon Sep 17 00:00:00 2001 From: Victor Vazquez Date: Tue, 7 Mar 2023 15:56:07 -0800 Subject: [PATCH 3/8] fix tests --- cli/azd/pkg/commands/pipeline/pipeline.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cli/azd/pkg/commands/pipeline/pipeline.go b/cli/azd/pkg/commands/pipeline/pipeline.go index a861a8c601b..a0f3be65d68 100644 --- a/cli/azd/pkg/commands/pipeline/pipeline.go +++ b/cli/azd/pkg/commands/pipeline/pipeline.go @@ -142,8 +142,9 @@ func resolveProvider(env *environment.Environment, projectPath string) (string, return lastUsedProvider, nil } - // 3) No config on azure.yaml or from previous run. Return default -> GitHub - return gitHubLabel, nil + // 3) No config on azure.yaml or from previous run. The provider will be set after + // inspecting the existing project folders. + return "", nil } // DetectProviders get azd context from the context and pulls the project directory from it. From 12c6e6b9a1759ef6b1865eb573fb5e1cb3847e57 Mon Sep 17 00:00:00 2001 From: Victor Vazquez Date: Mon, 20 Mar 2023 18:24:33 -0700 Subject: [PATCH 4/8] remove internal from project package --- cli/azd/pkg/project/{internal => }/project_utils.go | 4 ++-- cli/azd/pkg/project/service_target_appservice.go | 3 +-- cli/azd/pkg/project/service_target_functionapp.go | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) rename cli/azd/pkg/project/{internal => }/project_utils.go (92%) diff --git a/cli/azd/pkg/project/internal/project_utils.go b/cli/azd/pkg/project/project_utils.go similarity index 92% rename from cli/azd/pkg/project/internal/project_utils.go rename to cli/azd/pkg/project/project_utils.go index a2d1a356521..6a83ea02927 100644 --- a/cli/azd/pkg/project/internal/project_utils.go +++ b/cli/azd/pkg/project/project_utils.go @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package internal +package project import ( "fmt" @@ -12,7 +12,7 @@ import ( // CreateDeployableZip creates a zip file of a folder, recursively. // Returns the path to the created zip file or an error if it fails. -func CreateDeployableZip(appName string, path string) (string, error) { +func createDeployableZip(appName string, path string) (string, error) { // TODO: should probably avoid picking up files that weren't meant to be published (ie, local .env files, etc..) zipFile, err := os.CreateTemp("", "azddeploy*.zip") if err != nil { diff --git a/cli/azd/pkg/project/service_target_appservice.go b/cli/azd/pkg/project/service_target_appservice.go index 2b3ac2271b3..d1bde9f03ce 100644 --- a/cli/azd/pkg/project/service_target_appservice.go +++ b/cli/azd/pkg/project/service_target_appservice.go @@ -13,7 +13,6 @@ import ( "github.com/azure/azure-dev/cli/azd/pkg/azure" "github.com/azure/azure-dev/cli/azd/pkg/environment" "github.com/azure/azure-dev/cli/azd/pkg/infra" - "github.com/azure/azure-dev/cli/azd/pkg/project/internal" "github.com/azure/azure-dev/cli/azd/pkg/tools" "github.com/azure/azure-dev/cli/azd/pkg/tools/azcli" ) @@ -54,7 +53,7 @@ func (st *appServiceTarget) Package( return async.RunTaskWithProgress( func(task *async.TaskContextWithProgress[*ServicePackageResult, ServiceProgress]) { task.SetProgress(NewServiceProgress("Compressing deployment artifacts")) - zipFilePath, err := internal.CreateDeployableZip(serviceConfig.Name, buildOutput.BuildOutputPath) + zipFilePath, err := createDeployableZip(serviceConfig.Name, buildOutput.BuildOutputPath) if err != nil { task.SetError(err) return diff --git a/cli/azd/pkg/project/service_target_functionapp.go b/cli/azd/pkg/project/service_target_functionapp.go index 648937f61ac..562841fd110 100644 --- a/cli/azd/pkg/project/service_target_functionapp.go +++ b/cli/azd/pkg/project/service_target_functionapp.go @@ -13,7 +13,6 @@ import ( "github.com/azure/azure-dev/cli/azd/pkg/azure" "github.com/azure/azure-dev/cli/azd/pkg/environment" "github.com/azure/azure-dev/cli/azd/pkg/infra" - "github.com/azure/azure-dev/cli/azd/pkg/project/internal" "github.com/azure/azure-dev/cli/azd/pkg/tools" "github.com/azure/azure-dev/cli/azd/pkg/tools/azcli" ) @@ -55,7 +54,7 @@ func (f *functionAppTarget) Package( return async.RunTaskWithProgress( func(task *async.TaskContextWithProgress[*ServicePackageResult, ServiceProgress]) { task.SetProgress(NewServiceProgress("Compressing deployment artifacts")) - zipFilePath, err := internal.CreateDeployableZip(serviceConfig.Name, buildOutput.BuildOutputPath) + zipFilePath, err := createDeployableZip(serviceConfig.Name, buildOutput.BuildOutputPath) if err != nil { task.SetError(err) return From 8f255f69de6bf27b4fcf62d0072ad832c64c5797 Mon Sep 17 00:00:00 2001 From: Victor Vazquez Date: Mon, 20 Mar 2023 19:42:53 -0700 Subject: [PATCH 5/8] improve exclude files during copying --- cli/azd/.vscode/cspell-azd-dictionary.txt | 1 + cli/azd/pkg/project/framework_service_npm.go | 24 +++++-- .../pkg/project/framework_service_python.go | 72 +++++++++++++------ cli/azd/pkg/project/project_utils.go | 54 ++++++++++++++ go.mod | 2 +- go.sum | 13 ++-- 6 files changed, 132 insertions(+), 34 deletions(-) diff --git a/cli/azd/.vscode/cspell-azd-dictionary.txt b/cli/azd/.vscode/cspell-azd-dictionary.txt index 5cfe87c7b43..123739eb409 100644 --- a/cli/azd/.vscode/cspell-azd-dictionary.txt +++ b/cli/azd/.vscode/cspell-azd-dictionary.txt @@ -85,6 +85,7 @@ pflag preinit pulumi pyapp +pyvenv restoreapp retriable rzip diff --git a/cli/azd/pkg/project/framework_service_npm.go b/cli/azd/pkg/project/framework_service_npm.go index 03e36f91bf6..20be334d76a 100644 --- a/cli/azd/pkg/project/framework_service_npm.go +++ b/cli/azd/pkg/project/framework_service_npm.go @@ -14,7 +14,6 @@ import ( "github.com/azure/azure-dev/cli/azd/pkg/exec" "github.com/azure/azure-dev/cli/azd/pkg/tools" "github.com/azure/azure-dev/cli/azd/pkg/tools/npm" - "github.com/otiai10/copy" ) type npmProject struct { @@ -90,11 +89,15 @@ func (np *npmProject) Build( } task.SetProgress(NewServiceProgress("Copying deployment package")) - if err := copy.Copy( + + if err := buildForZip( publishSource, publishRoot, - skipPatterns( - filepath.Join(publishSource, "node_modules"), filepath.Join(publishSource, ".azure"))); err != nil { + buildForZipOptions{ + excludeConditions: []excludeDirEntryCondition{ + excludeNodeModules, + }, + }); err != nil { task.SetError(fmt.Errorf("publishing for %s: %w", serviceConfig.Name, err)) return } @@ -106,3 +109,16 @@ func (np *npmProject) Build( }, ) } + +const cNodeModulesName = "node_modules" + +func excludeNodeModules(path string, file os.FileInfo) bool { + if !file.IsDir() { + return false + } + + if file.Name() == cNodeModulesName { + return true + } + return false +} diff --git a/cli/azd/pkg/project/framework_service_python.go b/cli/azd/pkg/project/framework_service_python.go index fad8792d343..462e9598c06 100644 --- a/cli/azd/pkg/project/framework_service_python.go +++ b/cli/azd/pkg/project/framework_service_python.go @@ -16,7 +16,6 @@ import ( "github.com/azure/azure-dev/cli/azd/pkg/exec" "github.com/azure/azure-dev/cli/azd/pkg/tools" "github.com/azure/azure-dev/cli/azd/pkg/tools/python" - "github.com/otiai10/copy" ) type pythonProject struct { @@ -107,12 +106,15 @@ func (pp *pythonProject) Build( task.SetProgress(NewServiceProgress("Copying deployment package")) - if err := copy.Copy( + if err := buildForZip( publishSource, publishRoot, - skipPatterns( - filepath.Join(publishSource, "__pycache__"), filepath.Join(publishSource, ".venv"), - filepath.Join(publishSource, ".azure"))); err != nil { + buildForZipOptions{ + excludeConditions: []excludeDirEntryCondition{ + excludeVirtualEnv, + excludePyCache, + }, + }); err != nil { task.SetError(fmt.Errorf("publishing for %s: %w", serviceConfig.Name, err)) return } @@ -125,6 +127,32 @@ func (pp *pythonProject) Build( ) } +const cVenvConfigFileName = "pyvenv.cfg" + +func excludeVirtualEnv(path string, file os.FileInfo) bool { + if !file.IsDir() { + return false + } + + // check if `pyvenv.cfg` is within the folder + if _, err := os.Stat(filepath.Join(path, cVenvConfigFileName)); err == nil { + return true + } + return false +} + +func excludePyCache(path string, file os.FileInfo) bool { + if !file.IsDir() { + return false + } + + folderName := strings.ToLower(file.Name()) + if folderName == "__pycache__" { + return true + } + return false +} + func (pp *pythonProject) getVenvName(serviceConfig *ServiceConfig) string { trimmedPath := strings.TrimSpace(serviceConfig.Path()) if len(trimmedPath) > 0 && trimmedPath[len(trimmedPath)-1] == os.PathSeparator { @@ -136,20 +164,20 @@ func (pp *pythonProject) getVenvName(serviceConfig *ServiceConfig) string { // skipPatterns returns a `copy.Options` which will skip any files // that match a given pattern. Matching is done with `filepath.Match`. -func skipPatterns(patterns ...string) copy.Options { - return copy.Options{ - Skip: func(src string) (bool, error) { - for _, pattern := range patterns { - skip, err := filepath.Match(pattern, src) - switch { - case err != nil: - return false, fmt.Errorf("error matching pattern %s: %w", pattern, err) - case skip: - return true, nil - } - } - - return false, nil - }, - } -} +// func skipPatterns(patterns ...string) copy.Options { +// return copy.Options{ +// Skip: func(src string) (bool, error) { +// for _, pattern := range patterns { +// skip, err := filepath.Match(pattern, src) +// switch { +// case err != nil: +// return false, fmt.Errorf("error matching pattern %s: %w", pattern, err) +// case skip: +// return true, nil +// } +// } + +// return false, nil +// }, +// } +// } diff --git a/cli/azd/pkg/project/project_utils.go b/cli/azd/pkg/project/project_utils.go index 6a83ea02927..27dafa49af8 100644 --- a/cli/azd/pkg/project/project_utils.go +++ b/cli/azd/pkg/project/project_utils.go @@ -6,8 +6,10 @@ package project import ( "fmt" "os" + "strings" "github.com/azure/azure-dev/cli/azd/pkg/rzip" + "github.com/otiai10/copy" ) // CreateDeployableZip creates a zip file of a folder, recursively. @@ -34,3 +36,55 @@ func createDeployableZip(appName string, path string) (string, error) { return zipFile.Name(), nil } + +// excludeDirEntryCondition resolves when a file or directory should be considered or not as part of build, when build is a +// copy-paste source strategy. Return true to exclude the directory entry. +type excludeDirEntryCondition func(path string, file os.FileInfo) bool + +// buildForZipOptions provides a set of options for doing build for zip +type buildForZipOptions struct { + excludeConditions []excludeDirEntryCondition +} + +// buildForZip is use by projects which build strategy is to only copy the source code into a folder which is later +// zipped for packaging. For example Python and Node framework languages. buildForZipOptions provides the specific +// details for each language which should not be ever copied. +func buildForZip(src, dst string, options buildForZipOptions) error { + + // these exclude conditions applies to all projects + options.excludeConditions = append(options.excludeConditions, globalExcludeAzdFile, globalExcludeTestFolder) + + return copy.Copy(src, dst, copy.Options{ + Skip: func(srcInfo os.FileInfo, src, dest string) (bool, error) { + for _, checkExclude := range options.excludeConditions { + if checkExclude(src, srcInfo) { + return true, nil + } + } + return false, nil + }, + }) +} + +func globalExcludeAzdFile(path string, file os.FileInfo) bool { + if file.IsDir() { + return false + } + + if file.Name() == ".azure" { + return true + } + return false +} + +func globalExcludeTestFolder(path string, file os.FileInfo) bool { + if !file.IsDir() { + return false + } + + folderName := strings.ToLower(file.Name()) + if folderName == "test" || folderName == "tests" { + return true + } + return false +} diff --git a/go.mod b/go.mod index 27e1977323d..d239847c633 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( github.com/mattn/go-isatty v0.0.14 github.com/microsoft/ApplicationInsights-Go v0.4.4 github.com/microsoft/azure-devops-go-api/azuredevops v1.0.0-b5 - github.com/otiai10/copy v1.7.0 + github.com/otiai10/copy v1.9.0 github.com/sethvargo/go-retry v0.2.3 github.com/spf13/cobra v1.3.0 github.com/spf13/pflag v1.0.5 diff --git a/go.sum b/go.sum index a048f1b13df..2dcf74bbfe1 100644 --- a/go.sum +++ b/go.sum @@ -138,7 +138,6 @@ github.com/cncf/xds/go v0.0.0-20211130200136-a8f946100490/go.mod h1:eXthEFrGJvWH github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -331,9 +330,8 @@ github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.4 h1:5Myjjh3JY/NaAi4IsUbHADytDyl1VE1Y9PXDlL+P/VQ= github.com/kr/pty v1.1.4/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/lyft/protoc-gen-star v0.5.3/go.mod h1:V0xaHgaf5oCCqmcxYcWiDfTiKsZsRc87/1qhoTACD8w= @@ -383,13 +381,13 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/otiai10/copy v1.7.0 h1:hVoPiN+t+7d2nzzwMiDHPSOogsWAStewq3TwU05+clE= -github.com/otiai10/copy v1.7.0/go.mod h1:rmRl6QPdJj6EiUqXQ/4Nn2lLXoNQjFCQbbNrxgc/t3U= +github.com/otiai10/copy v1.9.0 h1:7KFNiCgZ91Ru4qW4CWPf/7jqtxLagGRmIxWldPP9VY4= +github.com/otiai10/copy v1.9.0/go.mod h1:hsfX19wcn0UWIHUQ3/4fHuehhk2UyArQ9dVFAn3FczI= github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE= github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs= github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo= -github.com/otiai10/mint v1.3.3 h1:7JgpsBaN0uMkyju4tbYHu0mnM55hNKVYLsXmwr15NQI= -github.com/otiai10/mint v1.3.3/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc= +github.com/otiai10/mint v1.4.0 h1:umwcf7gbpEwf7WFzqmWwSv0CzbeMsae2u9ZvpP8j2q4= +github.com/otiai10/mint v1.4.0/go.mod h1:gifjb2MYOoULtKLqUAEILUG/9KONW6f7YsJ6vQLTlFI= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= @@ -684,6 +682,7 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= From b433bcf8e8877cce3233931b4197b76681d246d0 Mon Sep 17 00:00:00 2001 From: Victor Vazquez Date: Mon, 20 Mar 2023 19:47:42 -0700 Subject: [PATCH 6/8] lint --- cli/azd/pkg/project/framework_service_python.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cli/azd/pkg/project/framework_service_python.go b/cli/azd/pkg/project/framework_service_python.go index 462e9598c06..3359aea8c79 100644 --- a/cli/azd/pkg/project/framework_service_python.go +++ b/cli/azd/pkg/project/framework_service_python.go @@ -147,10 +147,7 @@ func excludePyCache(path string, file os.FileInfo) bool { } folderName := strings.ToLower(file.Name()) - if folderName == "__pycache__" { - return true - } - return false + return folderName == "__pycache__" } func (pp *pythonProject) getVenvName(serviceConfig *ServiceConfig) string { From cad2bfe2f237049c4ceaf736f8917a5fa1e02f3b Mon Sep 17 00:00:00 2001 From: Victor Vazquez Date: Wed, 22 Mar 2023 02:32:37 +0000 Subject: [PATCH 7/8] do not exclude tests --- cli/azd/pkg/project/framework_service_npm.go | 9 +------ .../pkg/project/framework_service_python.go | 20 -------------- cli/azd/pkg/project/project_utils.go | 26 +++---------------- 3 files changed, 4 insertions(+), 51 deletions(-) diff --git a/cli/azd/pkg/project/framework_service_npm.go b/cli/azd/pkg/project/framework_service_npm.go index 20be334d76a..7a6902947de 100644 --- a/cli/azd/pkg/project/framework_service_npm.go +++ b/cli/azd/pkg/project/framework_service_npm.go @@ -113,12 +113,5 @@ func (np *npmProject) Build( const cNodeModulesName = "node_modules" func excludeNodeModules(path string, file os.FileInfo) bool { - if !file.IsDir() { - return false - } - - if file.Name() == cNodeModulesName { - return true - } - return false + return !file.IsDir() && file.Name() == cNodeModulesName } diff --git a/cli/azd/pkg/project/framework_service_python.go b/cli/azd/pkg/project/framework_service_python.go index 3359aea8c79..da9bdb1e664 100644 --- a/cli/azd/pkg/project/framework_service_python.go +++ b/cli/azd/pkg/project/framework_service_python.go @@ -158,23 +158,3 @@ func (pp *pythonProject) getVenvName(serviceConfig *ServiceConfig) string { _, projectDir := filepath.Split(trimmedPath) return projectDir + "_env" } - -// skipPatterns returns a `copy.Options` which will skip any files -// that match a given pattern. Matching is done with `filepath.Match`. -// func skipPatterns(patterns ...string) copy.Options { -// return copy.Options{ -// Skip: func(src string) (bool, error) { -// for _, pattern := range patterns { -// skip, err := filepath.Match(pattern, src) -// switch { -// case err != nil: -// return false, fmt.Errorf("error matching pattern %s: %w", pattern, err) -// case skip: -// return true, nil -// } -// } - -// return false, nil -// }, -// } -// } diff --git a/cli/azd/pkg/project/project_utils.go b/cli/azd/pkg/project/project_utils.go index 27dafa49af8..07ebb2edcf6 100644 --- a/cli/azd/pkg/project/project_utils.go +++ b/cli/azd/pkg/project/project_utils.go @@ -6,7 +6,6 @@ package project import ( "fmt" "os" - "strings" "github.com/azure/azure-dev/cli/azd/pkg/rzip" "github.com/otiai10/copy" @@ -52,7 +51,7 @@ type buildForZipOptions struct { func buildForZip(src, dst string, options buildForZipOptions) error { // these exclude conditions applies to all projects - options.excludeConditions = append(options.excludeConditions, globalExcludeAzdFile, globalExcludeTestFolder) + options.excludeConditions = append(options.excludeConditions, globalExcludeAzdFolder) return copy.Copy(src, dst, copy.Options{ Skip: func(srcInfo os.FileInfo, src, dest string) (bool, error) { @@ -66,25 +65,6 @@ func buildForZip(src, dst string, options buildForZipOptions) error { }) } -func globalExcludeAzdFile(path string, file os.FileInfo) bool { - if file.IsDir() { - return false - } - - if file.Name() == ".azure" { - return true - } - return false -} - -func globalExcludeTestFolder(path string, file os.FileInfo) bool { - if !file.IsDir() { - return false - } - - folderName := strings.ToLower(file.Name()) - if folderName == "test" || folderName == "tests" { - return true - } - return false +func globalExcludeAzdFolder(path string, file os.FileInfo) bool { + return file.IsDir() && file.Name() == ".azure" } From b2a230aaadc7b606efc4efe56006fafddadec61c Mon Sep 17 00:00:00 2001 From: Victor Vazquez Date: Wed, 22 Mar 2023 02:39:38 +0000 Subject: [PATCH 8/8] rebase --- cli/azd/internal/repository/initializer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/azd/internal/repository/initializer.go b/cli/azd/internal/repository/initializer.go index e38529d1522..ab595a4a494 100644 --- a/cli/azd/internal/repository/initializer.go +++ b/cli/azd/internal/repository/initializer.go @@ -81,7 +81,7 @@ func (i *Initializer) Initialize( options := copy.Options{} if skipStagingFiles != nil { - options.Skip = func(src string) (bool, error) { + options.Skip = func(fileInfo os.FileInfo, src, dest string) (bool, error) { if _, shouldSkip := skipStagingFiles[src]; shouldSkip { return true, nil }