From fdb9b2ea4103c439d46a772cfed1678f4884ee33 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Thu, 15 Jul 2021 12:42:46 -0400 Subject: [PATCH 01/18] adding coverage tools --- eng/pipelines/templates/steps/build-test.yml | 3 + tools/internal/coverage/go.mod | 3 + tools/internal/coverage/main.go | 73 ++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 tools/internal/coverage/go.mod create mode 100644 tools/internal/coverage/main.go diff --git a/eng/pipelines/templates/steps/build-test.yml b/eng/pipelines/templates/steps/build-test.yml index 9d2b6112c9c3..5102bbf85268 100644 --- a/eng/pipelines/templates/steps/build-test.yml +++ b/eng/pipelines/templates/steps/build-test.yml @@ -4,6 +4,7 @@ parameters: Scope: 'sdk/...' Image: '' GoVersion: '' + CoverageGoal: 0.99 steps: @@ -69,6 +70,8 @@ steps: # gocov converts rely on standard input Get-Content ./coverage.json | gocov-xml > ./coverage.xml Get-Content ./coverage.json | gocov-html > ./coverage.html + # use internal tool to fail if coverage is too low + ../../../tools/internal/coverage/main.go --coverage-goal={{parameters.CoverageGoal}} --package-path=. displayName: 'Generate Coverage XML' workingDirectory: '${{parameters.GoWorkspace}}sdk' diff --git a/tools/internal/coverage/go.mod b/tools/internal/coverage/go.mod new file mode 100644 index 000000000000..35c6bac8061d --- /dev/null +++ b/tools/internal/coverage/go.mod @@ -0,0 +1,3 @@ +module github.com/Azure/azure-sdk-for-go/tools/internal/coverage + +go 1.16 diff --git a/tools/internal/coverage/main.go b/tools/internal/coverage/main.go new file mode 100644 index 000000000000..796e998b2ea4 --- /dev/null +++ b/tools/internal/coverage/main.go @@ -0,0 +1,73 @@ +package main + +import ( + "flag" + "fmt" + "io/ioutil" + "log" + "os" + "path/filepath" + "regexp" + "strconv" + "strings" +) + +const ( + coverageXmlFile = "coverage.xml" +) + +func check(e error) { + if e != nil { + log.Fatal(e) + } +} + +func main() { + rootPath, err := filepath.Abs(".") + check(err) + fmt.Println(rootPath) + + coverageGoal := flag.Float64("coverage-goal", 0.80, "The goal coverage. This script will fail if coverage is below.") + packagePath := flag.String("package-path", "", "The path to a package from sdk/...") + + flag.Parse() + + if *packagePath == "" { + fmt.Println("Path was not provided, please provide a path to a package.") + os.Exit(1) + } + + fmt.Printf("Checking coverage for package located at %v\n", rootPath) + fmt.Printf("Failing if the coverage is below %.2f\n", *coverageGoal) + + xmlFilePath := filepath.Join(rootPath, *packagePath, coverageXmlFile) + xmlFile, err := os.Open(xmlFilePath) + check(err) + defer xmlFile.Close() + + byteValue, err := ioutil.ReadAll(xmlFile) + check(err) + + re := regexp.MustCompile(` Date: Thu, 15 Jul 2021 12:49:50 -0400 Subject: [PATCH 02/18] forgot to include 'go run' --- eng/pipelines/templates/steps/build-test.yml | 2 +- tools/internal/coverage/main.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/eng/pipelines/templates/steps/build-test.yml b/eng/pipelines/templates/steps/build-test.yml index 5102bbf85268..f32053831eed 100644 --- a/eng/pipelines/templates/steps/build-test.yml +++ b/eng/pipelines/templates/steps/build-test.yml @@ -71,7 +71,7 @@ steps: Get-Content ./coverage.json | gocov-xml > ./coverage.xml Get-Content ./coverage.json | gocov-html > ./coverage.html # use internal tool to fail if coverage is too low - ../../../tools/internal/coverage/main.go --coverage-goal={{parameters.CoverageGoal}} --package-path=. + go run ../../../tools/internal/coverage/main.go --coverage-goal={{parameters.CoverageGoal}} --package-path=. displayName: 'Generate Coverage XML' workingDirectory: '${{parameters.GoWorkspace}}sdk' diff --git a/tools/internal/coverage/main.go b/tools/internal/coverage/main.go index 796e998b2ea4..706ef00feb4e 100644 --- a/tools/internal/coverage/main.go +++ b/tools/internal/coverage/main.go @@ -40,6 +40,8 @@ func main() { fmt.Printf("Checking coverage for package located at %v\n", rootPath) fmt.Printf("Failing if the coverage is below %.2f\n", *coverageGoal) + // Need to add a step to find all coverage files + xmlFilePath := filepath.Join(rootPath, *packagePath, coverageXmlFile) xmlFile, err := os.Open(xmlFilePath) check(err) From 28457351db3200fc9a85d753437abfd909e4c472 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Thu, 15 Jul 2021 12:57:51 -0400 Subject: [PATCH 03/18] need to find where the script is running from --- eng/pipelines/templates/steps/build-test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eng/pipelines/templates/steps/build-test.yml b/eng/pipelines/templates/steps/build-test.yml index f32053831eed..34cfe86f220a 100644 --- a/eng/pipelines/templates/steps/build-test.yml +++ b/eng/pipelines/templates/steps/build-test.yml @@ -71,7 +71,8 @@ steps: Get-Content ./coverage.json | gocov-xml > ./coverage.xml Get-Content ./coverage.json | gocov-html > ./coverage.html # use internal tool to fail if coverage is too low - go run ../../../tools/internal/coverage/main.go --coverage-goal={{parameters.CoverageGoal}} --package-path=. + Get-Location + go run tools/internal/coverage/main.go --coverage-goal={{parameters.CoverageGoal}} --package-path=. displayName: 'Generate Coverage XML' workingDirectory: '${{parameters.GoWorkspace}}sdk' From 43e8cf6ab39faa4381aca790b94fd97df9899679 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Thu, 15 Jul 2021 13:17:19 -0400 Subject: [PATCH 04/18] fixing script --- eng/pipelines/templates/steps/build-test.yml | 2 +- tools/internal/coverage/main.go | 67 +++++++++++++------- 2 files changed, 46 insertions(+), 23 deletions(-) diff --git a/eng/pipelines/templates/steps/build-test.yml b/eng/pipelines/templates/steps/build-test.yml index 34cfe86f220a..6c1611bd8b71 100644 --- a/eng/pipelines/templates/steps/build-test.yml +++ b/eng/pipelines/templates/steps/build-test.yml @@ -72,7 +72,7 @@ steps: Get-Content ./coverage.json | gocov-html > ./coverage.html # use internal tool to fail if coverage is too low Get-Location - go run tools/internal/coverage/main.go --coverage-goal={{parameters.CoverageGoal}} --package-path=. + go run ../tools/internal/coverage/main.go --coverage-goal={{parameters.CoverageGoal}} --package-path=. displayName: 'Generate Coverage XML' workingDirectory: '${{parameters.GoWorkspace}}sdk' diff --git a/tools/internal/coverage/main.go b/tools/internal/coverage/main.go index 706ef00feb4e..374802ee4ca4 100644 --- a/tools/internal/coverage/main.go +++ b/tools/internal/coverage/main.go @@ -22,10 +22,30 @@ func check(e error) { } } +var coverageFiles []string + +func filterFiles(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + if strings.Contains(path, "coverage.xml") { + coverageFiles = append(coverageFiles, path) + } + return nil +} + +func FindCoverageFiles(p string) { + err := filepath.Walk(".", filterFiles) + check(err) +} + func main() { + coverageFiles = make([]string, 0) rootPath, err := filepath.Abs(".") check(err) fmt.Println(rootPath) + FindCoverageFiles(rootPath) + fmt.Println(coverageFiles) coverageGoal := flag.Float64("coverage-goal", 0.80, "The goal coverage. This script will fail if coverage is below.") packagePath := flag.String("package-path", "", "The path to a package from sdk/...") @@ -42,34 +62,37 @@ func main() { // Need to add a step to find all coverage files - xmlFilePath := filepath.Join(rootPath, *packagePath, coverageXmlFile) - xmlFile, err := os.Open(xmlFilePath) - check(err) - defer xmlFile.Close() + // xmlFilePath := filepath.Join(rootPath, *packagePath, coverageXmlFile) + for _, coverageFiles := range coverageFiles { + xmlFile, err := os.Open(coverageFiles) + check(err) + defer xmlFile.Close() - byteValue, err := ioutil.ReadAll(xmlFile) - check(err) + byteValue, err := ioutil.ReadAll(xmlFile) + check(err) - re := regexp.MustCompile(` Date: Thu, 15 Jul 2021 13:26:13 -0400 Subject: [PATCH 05/18] fixing passing of coverage goal value --- .../templates/jobs/archetype-sdk-client.yml | 12 +++++++----- eng/pipelines/templates/steps/build-test.yml | 2 +- tools/internal/coverage/main.go | 16 ++++++++-------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/eng/pipelines/templates/jobs/archetype-sdk-client.yml b/eng/pipelines/templates/jobs/archetype-sdk-client.yml index cc980b20f6fd..9aed4f84ed0f 100644 --- a/eng/pipelines/templates/jobs/archetype-sdk-client.yml +++ b/eng/pipelines/templates/jobs/archetype-sdk-client.yml @@ -1,5 +1,6 @@ parameters: ServiceDirectory: '' + CoverageGoal: 0.99 stages: - stage: Build @@ -42,17 +43,18 @@ stages: - template: ../steps/create-go-workspace.yml - template: ../steps/set-scope.yml - parameters: + parameters: ServiceDirectory: ${{ parameters.ServiceDirectory }} GoWorkspace: $(GO_WORKSPACE_PATH) - template: ../steps/build-test.yml - parameters: + parameters: ServiceDirectory: ${{ parameters.ServiceDirectory }} GoWorkspace: $(GO_WORKSPACE_PATH) Scope: $(SCOPE) Image: $(vm.image) GoVersion: $(go.version) + CoverageGoal: ${{ parameters.CoverageGoal }} - job: Analyze displayName: Analyze @@ -70,18 +72,18 @@ stages: - template: ../steps/create-go-workspace.yml - template: ../steps/set-scope.yml - parameters: + parameters: ServiceDirectory: ${{ parameters.ServiceDirectory }} GoWorkspace: $(GO_WORKSPACE_PATH) - template: ../steps/analyze.yml - parameters: + parameters: ServiceDirectory: ${{ parameters.ServiceDirectory }} GoWorkspace: $(GO_WORKSPACE_PATH) Scope: $(SCOPE) LintVersion: $(GoLintCLIVersion) -# Below stage won't work until the release stage is added/necessary. +# Below stage won't work until the release stage is added/necessary. # "Releasing" is just the package in the repository on github, but there may be some other metadata related # tasks that become necessary later on. diff --git a/eng/pipelines/templates/steps/build-test.yml b/eng/pipelines/templates/steps/build-test.yml index 6c1611bd8b71..b48fcd390eab 100644 --- a/eng/pipelines/templates/steps/build-test.yml +++ b/eng/pipelines/templates/steps/build-test.yml @@ -72,7 +72,7 @@ steps: Get-Content ./coverage.json | gocov-html > ./coverage.html # use internal tool to fail if coverage is too low Get-Location - go run ../tools/internal/coverage/main.go --coverage-goal={{parameters.CoverageGoal}} --package-path=. + go run ../tools/internal/coverage/main.go --coverage-goal=${{ parameters.CoverageGoal}} --package-path=. displayName: 'Generate Coverage XML' workingDirectory: '${{parameters.GoWorkspace}}sdk' diff --git a/tools/internal/coverage/main.go b/tools/internal/coverage/main.go index 374802ee4ca4..3ce9c56b2f7f 100644 --- a/tools/internal/coverage/main.go +++ b/tools/internal/coverage/main.go @@ -48,14 +48,14 @@ func main() { fmt.Println(coverageFiles) coverageGoal := flag.Float64("coverage-goal", 0.80, "The goal coverage. This script will fail if coverage is below.") - packagePath := flag.String("package-path", "", "The path to a package from sdk/...") + // packagePath := flag.String("package-path", "", "The path to a package from sdk/...") flag.Parse() - if *packagePath == "" { - fmt.Println("Path was not provided, please provide a path to a package.") - os.Exit(1) - } + // if *packagePath == "" { + // fmt.Println("Path was not provided, please provide a path to a package.") + // os.Exit(1) + // } fmt.Printf("Checking coverage for package located at %v\n", rootPath) fmt.Printf("Failing if the coverage is below %.2f\n", *coverageGoal) @@ -63,8 +63,8 @@ func main() { // Need to add a step to find all coverage files // xmlFilePath := filepath.Join(rootPath, *packagePath, coverageXmlFile) - for _, coverageFiles := range coverageFiles { - xmlFile, err := os.Open(coverageFiles) + for _, coverageFile := range coverageFiles { + xmlFile, err := os.Open(coverageFile) check(err) defer xmlFile.Close() @@ -87,7 +87,7 @@ func main() { coverageFloat, err := strconv.ParseFloat(coverageNumber, 32) check(err) - fmt.Printf("Found a coverage of %.4f for package %v\n", coverageFloat, *packagePath) + fmt.Printf("Found a coverage of %.4f for package %v\n", coverageFloat, coverageFile) if coverageFloat < *coverageGoal { fmt.Printf("Coverage is lower than expected. Got %.4f, expected %.4f\n", coverageFloat, *coverageGoal) os.Exit(1) From 28b8608e59ea16c96f2a08926692f580421dfd54 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Thu, 15 Jul 2021 13:31:43 -0400 Subject: [PATCH 06/18] removing flag from build-test --- eng/pipelines/templates/steps/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/pipelines/templates/steps/build-test.yml b/eng/pipelines/templates/steps/build-test.yml index b48fcd390eab..1cee9a6c79b1 100644 --- a/eng/pipelines/templates/steps/build-test.yml +++ b/eng/pipelines/templates/steps/build-test.yml @@ -72,7 +72,7 @@ steps: Get-Content ./coverage.json | gocov-html > ./coverage.html # use internal tool to fail if coverage is too low Get-Location - go run ../tools/internal/coverage/main.go --coverage-goal=${{ parameters.CoverageGoal}} --package-path=. + go run ../tools/internal/coverage/main.go --coverage-goal=${{ parameters.CoverageGoal}} displayName: 'Generate Coverage XML' workingDirectory: '${{parameters.GoWorkspace}}sdk' From 4a5da223d2b4a94406f5e6e0b547a15da47b03a4 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Thu, 15 Jul 2021 13:43:43 -0400 Subject: [PATCH 07/18] fixing tools script for multiple files --- tools/internal/coverage/main.go | 55 +++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/tools/internal/coverage/main.go b/tools/internal/coverage/main.go index 3ce9c56b2f7f..b1f86abda1a9 100644 --- a/tools/internal/coverage/main.go +++ b/tools/internal/coverage/main.go @@ -43,9 +43,9 @@ func main() { coverageFiles = make([]string, 0) rootPath, err := filepath.Abs(".") check(err) - fmt.Println(rootPath) + // fmt.Println(rootPath) FindCoverageFiles(rootPath) - fmt.Println(coverageFiles) + // fmt.Println(coverageFiles) coverageGoal := flag.Float64("coverage-goal", 0.80, "The goal coverage. This script will fail if coverage is below.") // packagePath := flag.String("package-path", "", "The path to a package from sdk/...") @@ -57,12 +57,13 @@ func main() { // os.Exit(1) // } - fmt.Printf("Checking coverage for package located at %v\n", rootPath) + // fmt.Printf("Checking coverage for package located at %v\n", rootPath) fmt.Printf("Failing if the coverage is below %.2f\n", *coverageGoal) // Need to add a step to find all coverage files // xmlFilePath := filepath.Join(rootPath, *packagePath, coverageXmlFile) + coverageValues := make([]float64, 0) for _, coverageFile := range coverageFiles { xmlFile, err := os.Open(coverageFile) check(err) @@ -72,27 +73,49 @@ func main() { check(err) re := regexp.MustCompile(` Date: Thu, 15 Jul 2021 14:00:46 -0400 Subject: [PATCH 08/18] updating ci.yml files, polishing script --- .../templates/jobs/archetype-sdk-client.yml | 2 +- eng/pipelines/templates/steps/build-test.yml | 3 +-- sdk/agfood/armagfood/ci.yml | 1 + sdk/agrifood/armagrifood/ci.yml | 1 + sdk/authorization/armauthorization/ci.yml | 1 + sdk/azidentity/ci.yml | 1 + sdk/compute/armcompute/ci.yml | 1 + .../armcontainerregistry/ci.yml | 3 ++- .../armcontainerservice/ci.yml | 1 + sdk/keyvault/armkeyvault/ci.yml | 1 + sdk/monitor/armmonitor/ci.yml | 1 + sdk/network/armnetwork/ci.yml | 1 + sdk/privatedns/armprivatedns/ci.yml | 1 + sdk/resources/armresources/ci.yml | 1 + sdk/storage/armstorage/ci.yml | 1 + sdk/synapse/azartifacts/ci.yml | 4 +-- sdk/web/armweb/ci.yml | 1 + tools/internal/coverage/main.go | 25 +------------------ 18 files changed, 20 insertions(+), 30 deletions(-) diff --git a/eng/pipelines/templates/jobs/archetype-sdk-client.yml b/eng/pipelines/templates/jobs/archetype-sdk-client.yml index 9aed4f84ed0f..c03d2800d94c 100644 --- a/eng/pipelines/templates/jobs/archetype-sdk-client.yml +++ b/eng/pipelines/templates/jobs/archetype-sdk-client.yml @@ -1,6 +1,6 @@ parameters: ServiceDirectory: '' - CoverageGoal: 0.99 + CoverageGoal: 0.95 stages: - stage: Build diff --git a/eng/pipelines/templates/steps/build-test.yml b/eng/pipelines/templates/steps/build-test.yml index 1cee9a6c79b1..65bd79bebd23 100644 --- a/eng/pipelines/templates/steps/build-test.yml +++ b/eng/pipelines/templates/steps/build-test.yml @@ -4,7 +4,7 @@ parameters: Scope: 'sdk/...' Image: '' GoVersion: '' - CoverageGoal: 0.99 + CoverageGoal: 0.95 steps: @@ -71,7 +71,6 @@ steps: Get-Content ./coverage.json | gocov-xml > ./coverage.xml Get-Content ./coverage.json | gocov-html > ./coverage.html # use internal tool to fail if coverage is too low - Get-Location go run ../tools/internal/coverage/main.go --coverage-goal=${{ parameters.CoverageGoal}} displayName: 'Generate Coverage XML' workingDirectory: '${{parameters.GoWorkspace}}sdk' diff --git a/sdk/agfood/armagfood/ci.yml b/sdk/agfood/armagfood/ci.yml index 760bd529e50d..400328ad6760 100644 --- a/sdk/agfood/armagfood/ci.yml +++ b/sdk/agfood/armagfood/ci.yml @@ -13,3 +13,4 @@ stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml parameters: ServiceDirectory: 'agfood/armagfood' + CoverageGoal: 0.80 diff --git a/sdk/agrifood/armagrifood/ci.yml b/sdk/agrifood/armagrifood/ci.yml index 3b1fda8a9cbd..c73109761a47 100644 --- a/sdk/agrifood/armagrifood/ci.yml +++ b/sdk/agrifood/armagrifood/ci.yml @@ -13,3 +13,4 @@ stages: - template: /eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml parameters: ServiceDirectory: 'agrifood/armagrifood' + CoverageGoal: 0.80 diff --git a/sdk/authorization/armauthorization/ci.yml b/sdk/authorization/armauthorization/ci.yml index 605f490ff563..0980dc761e23 100644 --- a/sdk/authorization/armauthorization/ci.yml +++ b/sdk/authorization/armauthorization/ci.yml @@ -13,3 +13,4 @@ stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml parameters: ServiceDirectory: 'authorization/armauthorization' + CoverageGoal: 0.80 diff --git a/sdk/azidentity/ci.yml b/sdk/azidentity/ci.yml index e4496e8d0f38..910801352e21 100644 --- a/sdk/azidentity/ci.yml +++ b/sdk/azidentity/ci.yml @@ -13,3 +13,4 @@ stages: - template: ../../eng/pipelines/templates/jobs/archetype-sdk-client.yml parameters: ServiceDirectory: 'azidentity' + CoverageGoal: 0.80 diff --git a/sdk/compute/armcompute/ci.yml b/sdk/compute/armcompute/ci.yml index 04f7f82782a9..2919e3964538 100644 --- a/sdk/compute/armcompute/ci.yml +++ b/sdk/compute/armcompute/ci.yml @@ -13,3 +13,4 @@ stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml parameters: ServiceDirectory: 'compute/armcompute' + CoverageGoal: 0.80 diff --git a/sdk/containerregistry/armcontainerregistry/ci.yml b/sdk/containerregistry/armcontainerregistry/ci.yml index 8be8ad81a3fc..dea376d945a5 100644 --- a/sdk/containerregistry/armcontainerregistry/ci.yml +++ b/sdk/containerregistry/armcontainerregistry/ci.yml @@ -12,4 +12,5 @@ pr: stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml parameters: - ServiceDirectory: 'containerregistry/armcontainerregistry' \ No newline at end of file + ServiceDirectory: 'containerregistry/armcontainerregistry' + CoverageGoal: 0.80 diff --git a/sdk/containerservice/armcontainerservice/ci.yml b/sdk/containerservice/armcontainerservice/ci.yml index 0429d0e26b44..91ab64603e85 100644 --- a/sdk/containerservice/armcontainerservice/ci.yml +++ b/sdk/containerservice/armcontainerservice/ci.yml @@ -13,3 +13,4 @@ stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml parameters: ServiceDirectory: 'containerservice/armcontainerservice' + CoverageGoal: 0.80 diff --git a/sdk/keyvault/armkeyvault/ci.yml b/sdk/keyvault/armkeyvault/ci.yml index 845bc171bcf2..4f6e577e8a55 100644 --- a/sdk/keyvault/armkeyvault/ci.yml +++ b/sdk/keyvault/armkeyvault/ci.yml @@ -13,3 +13,4 @@ stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml parameters: ServiceDirectory: 'keyvault/armkeyvault' + CoverageGoal: 0.80 diff --git a/sdk/monitor/armmonitor/ci.yml b/sdk/monitor/armmonitor/ci.yml index 951eceb9ee5d..36117f9b454d 100644 --- a/sdk/monitor/armmonitor/ci.yml +++ b/sdk/monitor/armmonitor/ci.yml @@ -13,3 +13,4 @@ stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml parameters: ServiceDirectory: 'monitor/armmonitor' + CoverageGoal: 0.80 diff --git a/sdk/network/armnetwork/ci.yml b/sdk/network/armnetwork/ci.yml index 72ec4784aee3..57e149b12b6f 100644 --- a/sdk/network/armnetwork/ci.yml +++ b/sdk/network/armnetwork/ci.yml @@ -13,3 +13,4 @@ stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml parameters: ServiceDirectory: 'network/armnetwork' + CoverageGoal: 0.80 diff --git a/sdk/privatedns/armprivatedns/ci.yml b/sdk/privatedns/armprivatedns/ci.yml index 578a671d1861..121738be4107 100644 --- a/sdk/privatedns/armprivatedns/ci.yml +++ b/sdk/privatedns/armprivatedns/ci.yml @@ -13,3 +13,4 @@ stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml parameters: ServiceDirectory: 'privatedns/armprivatedns' + CoverageGoal: 0.80 diff --git a/sdk/resources/armresources/ci.yml b/sdk/resources/armresources/ci.yml index 1b893badf2ec..4f6b1e4d960d 100644 --- a/sdk/resources/armresources/ci.yml +++ b/sdk/resources/armresources/ci.yml @@ -13,3 +13,4 @@ stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml parameters: ServiceDirectory: 'resources/armresources' + CoverageGoal: 0.80 diff --git a/sdk/storage/armstorage/ci.yml b/sdk/storage/armstorage/ci.yml index 307eea0ed166..d3d2be2c0ad4 100644 --- a/sdk/storage/armstorage/ci.yml +++ b/sdk/storage/armstorage/ci.yml @@ -13,3 +13,4 @@ stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml parameters: ServiceDirectory: 'storage/armstorage' + CoverageGoal: 0.80 diff --git a/sdk/synapse/azartifacts/ci.yml b/sdk/synapse/azartifacts/ci.yml index b1310415977a..aea624bd75af 100644 --- a/sdk/synapse/azartifacts/ci.yml +++ b/sdk/synapse/azartifacts/ci.yml @@ -8,9 +8,9 @@ pr: paths: include: - sdk/synapse/azartifacts/ - + stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml parameters: ServiceDirectory: 'synapse/azartifacts' - + CoverageGoal: 0.80 diff --git a/sdk/web/armweb/ci.yml b/sdk/web/armweb/ci.yml index 8525bd2bfc28..aadadf160aeb 100644 --- a/sdk/web/armweb/ci.yml +++ b/sdk/web/armweb/ci.yml @@ -13,3 +13,4 @@ stages: - template: /eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml parameters: ServiceDirectory: 'web/armweb' + CoverageGoal: 0.80 diff --git a/tools/internal/coverage/main.go b/tools/internal/coverage/main.go index b1f86abda1a9..6fe08d185c7f 100644 --- a/tools/internal/coverage/main.go +++ b/tools/internal/coverage/main.go @@ -43,26 +43,14 @@ func main() { coverageFiles = make([]string, 0) rootPath, err := filepath.Abs(".") check(err) - // fmt.Println(rootPath) FindCoverageFiles(rootPath) - // fmt.Println(coverageFiles) - coverageGoal := flag.Float64("coverage-goal", 0.80, "The goal coverage. This script will fail if coverage is below.") - // packagePath := flag.String("package-path", "", "The path to a package from sdk/...") + coverageGoal := flag.Float64("coverage-goal", 0.95, "The goal coverage. This script will fail if coverage is below.") flag.Parse() - // if *packagePath == "" { - // fmt.Println("Path was not provided, please provide a path to a package.") - // os.Exit(1) - // } - - // fmt.Printf("Checking coverage for package located at %v\n", rootPath) fmt.Printf("Failing if the coverage is below %.2f\n", *coverageGoal) - // Need to add a step to find all coverage files - - // xmlFilePath := filepath.Join(rootPath, *packagePath, coverageXmlFile) coverageValues := make([]float64, 0) for _, coverageFile := range coverageFiles { xmlFile, err := os.Open(coverageFile) @@ -78,9 +66,6 @@ func main() { log.Fatalf("Could not match regexp to coverage.xml file.") } - // fmt.Printf("%q\n", re.FindAll(byteValue, -1)) - - // for _, value := range coverageValue { parts := strings.Split(string(coverageValue), "=") coverageNumber := parts[1] @@ -88,7 +73,6 @@ func main() { coverageFloat, err := strconv.ParseFloat(coverageNumber, 32) check(err) coverageValues = append(coverageValues, coverageFloat) - // } } if len(coverageValues) != len(coverageFiles) { @@ -111,11 +95,4 @@ func main() { fmt.Println("Coverage step failed") os.Exit(1) } - - // fmt.Printf("Found a coverage of %.4f for package %v\n", coverageFloat, coverageFile) - // if coverageFloat < *coverageGoal { - // fmt.Printf("Coverage is lower than expected. Got %.4f, expected %.4f\n", coverageFloat, *coverageGoal) - // os.Exit(1) - // } - } From 4c7d915c67d653c56479979106db306cb21fe43b Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Wed, 21 Jul 2021 16:31:52 -0400 Subject: [PATCH 09/18] removing coverage goals --- sdk/agfood/armagfood/ci.yml | 1 - sdk/agrifood/armagrifood/ci.yml | 1 - sdk/authorization/armauthorization/ci.yml | 1 - sdk/azcore/ci.yml | 1 + sdk/azidentity/ci.yml | 2 +- sdk/compute/armcompute/ci.yml | 1 - sdk/containerregistry/armcontainerregistry/ci.yml | 1 - sdk/containerservice/armcontainerservice/ci.yml | 1 - sdk/keyvault/armkeyvault/ci.yml | 1 - sdk/monitor/armmonitor/ci.yml | 1 - sdk/network/armnetwork/ci.yml | 1 - sdk/privatedns/armprivatedns/ci.yml | 1 - sdk/resources/armresources/ci.yml | 1 - sdk/storage/armstorage/ci.yml | 1 - sdk/synapse/azartifacts/ci.yml | 1 - sdk/to/ci.yml | 2 +- sdk/web/armweb/ci.yml | 1 - 17 files changed, 3 insertions(+), 16 deletions(-) diff --git a/sdk/agfood/armagfood/ci.yml b/sdk/agfood/armagfood/ci.yml index a75f68be96a1..691a946e6c07 100644 --- a/sdk/agfood/armagfood/ci.yml +++ b/sdk/agfood/armagfood/ci.yml @@ -13,4 +13,3 @@ stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client.yml parameters: ServiceDirectory: 'agfood/armagfood' - CoverageGoal: 0.80 diff --git a/sdk/agrifood/armagrifood/ci.yml b/sdk/agrifood/armagrifood/ci.yml index 7cfc68443215..77aa09520ef0 100644 --- a/sdk/agrifood/armagrifood/ci.yml +++ b/sdk/agrifood/armagrifood/ci.yml @@ -13,4 +13,3 @@ stages: - template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml parameters: ServiceDirectory: 'agrifood/armagrifood' - CoverageGoal: 0.80 diff --git a/sdk/authorization/armauthorization/ci.yml b/sdk/authorization/armauthorization/ci.yml index ff27f23ac6fd..6aadcffe031c 100644 --- a/sdk/authorization/armauthorization/ci.yml +++ b/sdk/authorization/armauthorization/ci.yml @@ -13,4 +13,3 @@ stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client.yml parameters: ServiceDirectory: 'authorization/armauthorization' - CoverageGoal: 0.80 diff --git a/sdk/azcore/ci.yml b/sdk/azcore/ci.yml index 9ed5180726cb..6f2876d795e3 100644 --- a/sdk/azcore/ci.yml +++ b/sdk/azcore/ci.yml @@ -15,3 +15,4 @@ stages: parameters: ServiceDirectory: 'azcore' RunTests: true + CoverageGoal: 0.85 diff --git a/sdk/azidentity/ci.yml b/sdk/azidentity/ci.yml index 8e00dd590f2a..1419fad322bd 100644 --- a/sdk/azidentity/ci.yml +++ b/sdk/azidentity/ci.yml @@ -13,5 +13,5 @@ stages: - template: ../../eng/pipelines/templates/jobs/archetype-sdk-client.yml parameters: ServiceDirectory: 'azidentity' - CoverageGoal: 0.80 + CoverageGoal: 0.68 RunTests: true diff --git a/sdk/compute/armcompute/ci.yml b/sdk/compute/armcompute/ci.yml index d5ccb8fd91ef..0d41291c2072 100644 --- a/sdk/compute/armcompute/ci.yml +++ b/sdk/compute/armcompute/ci.yml @@ -13,4 +13,3 @@ stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client.yml parameters: ServiceDirectory: 'compute/armcompute' - CoverageGoal: 0.80 diff --git a/sdk/containerregistry/armcontainerregistry/ci.yml b/sdk/containerregistry/armcontainerregistry/ci.yml index 9b8af0b3c2b1..33d739fc30fe 100644 --- a/sdk/containerregistry/armcontainerregistry/ci.yml +++ b/sdk/containerregistry/armcontainerregistry/ci.yml @@ -13,4 +13,3 @@ stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client.yml parameters: ServiceDirectory: 'containerregistry/armcontainerregistry' - CoverageGoal: 0.80 diff --git a/sdk/containerservice/armcontainerservice/ci.yml b/sdk/containerservice/armcontainerservice/ci.yml index 09ee3276579b..3fdd60cf0177 100644 --- a/sdk/containerservice/armcontainerservice/ci.yml +++ b/sdk/containerservice/armcontainerservice/ci.yml @@ -13,4 +13,3 @@ stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client.yml parameters: ServiceDirectory: 'containerservice/armcontainerservice' - CoverageGoal: 0.80 diff --git a/sdk/keyvault/armkeyvault/ci.yml b/sdk/keyvault/armkeyvault/ci.yml index f0ff7e66365e..1a7ab4335350 100644 --- a/sdk/keyvault/armkeyvault/ci.yml +++ b/sdk/keyvault/armkeyvault/ci.yml @@ -13,4 +13,3 @@ stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client.yml parameters: ServiceDirectory: 'keyvault/armkeyvault' - CoverageGoal: 0.80 diff --git a/sdk/monitor/armmonitor/ci.yml b/sdk/monitor/armmonitor/ci.yml index 90840c479e8e..f6a51997e22c 100644 --- a/sdk/monitor/armmonitor/ci.yml +++ b/sdk/monitor/armmonitor/ci.yml @@ -13,4 +13,3 @@ stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client.yml parameters: ServiceDirectory: 'monitor/armmonitor' - CoverageGoal: 0.80 diff --git a/sdk/network/armnetwork/ci.yml b/sdk/network/armnetwork/ci.yml index 513b8bdd94b4..31fb47aa984c 100644 --- a/sdk/network/armnetwork/ci.yml +++ b/sdk/network/armnetwork/ci.yml @@ -13,4 +13,3 @@ stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client.yml parameters: ServiceDirectory: 'network/armnetwork' - CoverageGoal: 0.80 diff --git a/sdk/privatedns/armprivatedns/ci.yml b/sdk/privatedns/armprivatedns/ci.yml index 26a108c9e6f8..06d97401a0c1 100644 --- a/sdk/privatedns/armprivatedns/ci.yml +++ b/sdk/privatedns/armprivatedns/ci.yml @@ -13,4 +13,3 @@ stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client.yml parameters: ServiceDirectory: 'privatedns/armprivatedns' - CoverageGoal: 0.80 diff --git a/sdk/resources/armresources/ci.yml b/sdk/resources/armresources/ci.yml index 260c6ff30d4f..c6996fdf6249 100644 --- a/sdk/resources/armresources/ci.yml +++ b/sdk/resources/armresources/ci.yml @@ -13,4 +13,3 @@ stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client.yml parameters: ServiceDirectory: 'resources/armresources' - CoverageGoal: 0.80 diff --git a/sdk/storage/armstorage/ci.yml b/sdk/storage/armstorage/ci.yml index 82b0c8a6c682..2be3a91b4f46 100644 --- a/sdk/storage/armstorage/ci.yml +++ b/sdk/storage/armstorage/ci.yml @@ -13,4 +13,3 @@ stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client.yml parameters: ServiceDirectory: 'storage/armstorage' - CoverageGoal: 0.80 diff --git a/sdk/synapse/azartifacts/ci.yml b/sdk/synapse/azartifacts/ci.yml index 99ec1b813606..bd8ece2c46f5 100644 --- a/sdk/synapse/azartifacts/ci.yml +++ b/sdk/synapse/azartifacts/ci.yml @@ -13,4 +13,3 @@ stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client.yml parameters: ServiceDirectory: 'synapse/azartifacts' - CoverageGoal: 0.80 diff --git a/sdk/to/ci.yml b/sdk/to/ci.yml index e685d1b05e7d..8fa2e11155a9 100644 --- a/sdk/to/ci.yml +++ b/sdk/to/ci.yml @@ -8,7 +8,7 @@ pr: paths: include: - sdk/to/ - + stages: - template: ../../eng/pipelines/templates/jobs/archetype-sdk-client.yml parameters: diff --git a/sdk/web/armweb/ci.yml b/sdk/web/armweb/ci.yml index c2cdc9a91292..debef9f72c33 100644 --- a/sdk/web/armweb/ci.yml +++ b/sdk/web/armweb/ci.yml @@ -13,4 +13,3 @@ stages: - template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml parameters: ServiceDirectory: 'web/armweb' - CoverageGoal: 0.80 From a1368739cef466aeada5441c8a6f9b3214db233e Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Wed, 21 Jul 2021 16:32:59 -0400 Subject: [PATCH 10/18] undoing changes --- sdk/containerregistry/armcontainerregistry/ci.yml | 2 +- sdk/synapse/azartifacts/ci.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk/containerregistry/armcontainerregistry/ci.yml b/sdk/containerregistry/armcontainerregistry/ci.yml index 33d739fc30fe..f4670ebf4109 100644 --- a/sdk/containerregistry/armcontainerregistry/ci.yml +++ b/sdk/containerregistry/armcontainerregistry/ci.yml @@ -12,4 +12,4 @@ pr: stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client.yml parameters: - ServiceDirectory: 'containerregistry/armcontainerregistry' + ServiceDirectory: 'containerregistry/armcontainerregistry' \ No newline at end of file diff --git a/sdk/synapse/azartifacts/ci.yml b/sdk/synapse/azartifacts/ci.yml index bd8ece2c46f5..467be0a35a07 100644 --- a/sdk/synapse/azartifacts/ci.yml +++ b/sdk/synapse/azartifacts/ci.yml @@ -13,3 +13,4 @@ stages: - template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client.yml parameters: ServiceDirectory: 'synapse/azartifacts' + From 56f0d2dcad0804364a5b6ed4c007e0382f431ffd Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Wed, 21 Jul 2021 16:41:44 -0400 Subject: [PATCH 11/18] dropping core down, fixing to.go lint --- sdk/azcore/ci.yml | 2 +- sdk/to/to.go | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sdk/azcore/ci.yml b/sdk/azcore/ci.yml index 6f2876d795e3..ad5a37a1ccaf 100644 --- a/sdk/azcore/ci.yml +++ b/sdk/azcore/ci.yml @@ -15,4 +15,4 @@ stages: parameters: ServiceDirectory: 'azcore' RunTests: true - CoverageGoal: 0.85 + CoverageGoal: 0.84 diff --git a/sdk/to/to.go b/sdk/to/to.go index bbc5af802db2..b9ccec2e5cac 100644 --- a/sdk/to/to.go +++ b/sdk/to/to.go @@ -44,7 +44,7 @@ func TimePtr(t time.Time) *time.Time { // Int32PtrArray returns an array of *int32 from the specified values. func Int32PtrArray(vals ...int32) []*int32 { - arr := make([]*int32, len(vals), len(vals)) + arr := make([]*int32, len(vals)) for i := range vals { arr[i] = Int32Ptr(vals[i]) } @@ -53,7 +53,7 @@ func Int32PtrArray(vals ...int32) []*int32 { // Int64PtrArray returns an array of *int64 from the specified values. func Int64PtrArray(vals ...int64) []*int64 { - arr := make([]*int64, len(vals), len(vals)) + arr := make([]*int64, len(vals)) for i := range vals { arr[i] = Int64Ptr(vals[i]) } @@ -62,7 +62,7 @@ func Int64PtrArray(vals ...int64) []*int64 { // Float32PtrArray returns an array of *float32 from the specified values. func Float32PtrArray(vals ...float32) []*float32 { - arr := make([]*float32, len(vals), len(vals)) + arr := make([]*float32, len(vals)) for i := range vals { arr[i] = Float32Ptr(vals[i]) } @@ -71,7 +71,7 @@ func Float32PtrArray(vals ...float32) []*float32 { // Float64PtrArray returns an array of *float64 from the specified values. func Float64PtrArray(vals ...float64) []*float64 { - arr := make([]*float64, len(vals), len(vals)) + arr := make([]*float64, len(vals)) for i := range vals { arr[i] = Float64Ptr(vals[i]) } @@ -80,7 +80,7 @@ func Float64PtrArray(vals ...float64) []*float64 { // BoolPtrArray returns an array of *bool from the specified values. func BoolPtrArray(vals ...bool) []*bool { - arr := make([]*bool, len(vals), len(vals)) + arr := make([]*bool, len(vals)) for i := range vals { arr[i] = BoolPtr(vals[i]) } @@ -89,7 +89,7 @@ func BoolPtrArray(vals ...bool) []*bool { // StringPtrArray returns an array of *string from the specified values. func StringPtrArray(vals ...string) []*string { - arr := make([]*string, len(vals), len(vals)) + arr := make([]*string, len(vals)) for i := range vals { arr[i] = StringPtr(vals[i]) } @@ -98,7 +98,7 @@ func StringPtrArray(vals ...string) []*string { // TimePtrArray returns an array of *time.Time from the specified values. func TimePtrArray(vals ...time.Time) []*time.Time { - arr := make([]*time.Time, len(vals), len(vals)) + arr := make([]*time.Time, len(vals)) for i := range vals { arr[i] = TimePtr(vals[i]) } From 295d9a2bdbc779d15160570e126e96b9e9e9c78f Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Thu, 22 Jul 2021 11:00:11 -0400 Subject: [PATCH 12/18] creating a config file for the SDK and using that instead of putting values in ci.yml --- eng/config.json | 12 ++++++++ sdk/azcore/ci.yml | 1 - sdk/azidentity/ci.yml | 1 - tools/internal/coverage/main.go | 49 ++++++++++++++++++++++++++++++--- 4 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 eng/config.json diff --git a/eng/config.json b/eng/config.json new file mode 100644 index 000000000000..d3a9dbdc69cd --- /dev/null +++ b/eng/config.json @@ -0,0 +1,12 @@ +{ + "Packages": [ + { + "Name": "azidentity", + "CoverageGoal": 0.68 + }, + { + "Name": "azcore", + "CoverageGoal": 0.68 + } + ] +} \ No newline at end of file diff --git a/sdk/azcore/ci.yml b/sdk/azcore/ci.yml index ad5a37a1ccaf..9ed5180726cb 100644 --- a/sdk/azcore/ci.yml +++ b/sdk/azcore/ci.yml @@ -15,4 +15,3 @@ stages: parameters: ServiceDirectory: 'azcore' RunTests: true - CoverageGoal: 0.84 diff --git a/sdk/azidentity/ci.yml b/sdk/azidentity/ci.yml index 1419fad322bd..5e5adcfd1511 100644 --- a/sdk/azidentity/ci.yml +++ b/sdk/azidentity/ci.yml @@ -13,5 +13,4 @@ stages: - template: ../../eng/pipelines/templates/jobs/archetype-sdk-client.yml parameters: ServiceDirectory: 'azidentity' - CoverageGoal: 0.68 RunTests: true diff --git a/tools/internal/coverage/main.go b/tools/internal/coverage/main.go index 6fe08d185c7f..48c6317a0772 100644 --- a/tools/internal/coverage/main.go +++ b/tools/internal/coverage/main.go @@ -1,7 +1,7 @@ package main import ( - "flag" + "encoding/json" "fmt" "io/ioutil" "log" @@ -12,10 +12,21 @@ import ( "strings" ) +type CodeCoverage struct { + Packages []Package `json:"Packages"` +} + +type Package struct { + Name string `json:"name"` + CoverageGoal float64 `json:"CoverageGoal"` +} + const ( coverageXmlFile = "coverage.xml" ) +var configFile, _ = filepath.Abs(filepath.Join("..", "eng", "config.json")) + func check(e error) { if e != nil { log.Fatal(e) @@ -39,15 +50,45 @@ func FindCoverageFiles(p string) { check(err) } +func ReadConfigData() *CodeCoverage { + jsonFile, err := os.Open(configFile) + check(err) + defer jsonFile.Close() + + byteValue, err := ioutil.ReadAll(jsonFile) + check(err) + + var cov CodeCoverage + err = json.Unmarshal([]byte(byteValue), &cov) + check(err) + return &cov +} + +// This supports doing a single package at a time. If this needs to be expanded in the future +// this method will have to return a []*float64 for each packages goal +func findCoverageGoal(covFiles []string, configData *CodeCoverage) *float64 { + var ret float64 + + for _, covFile := range covFiles { + for _, p := range configData.Packages { + if strings.Contains(covFile, p.Name) { + return &p.CoverageGoal + } + } + } + + return &ret +} + func main() { coverageFiles = make([]string, 0) rootPath, err := filepath.Abs(".") check(err) - FindCoverageFiles(rootPath) - coverageGoal := flag.Float64("coverage-goal", 0.95, "The goal coverage. This script will fail if coverage is below.") + FindCoverageFiles(rootPath) - flag.Parse() + configData := ReadConfigData() + coverageGoal := findCoverageGoal(coverageFiles, configData) fmt.Printf("Failing if the coverage is below %.2f\n", *coverageGoal) From aadf942e618cae5f9ca6c0891ece7245f5d1b89a Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Thu, 22 Jul 2021 11:01:58 -0400 Subject: [PATCH 13/18] putting coverage in a script --- eng/pipelines/templates/steps/build-test.yml | 15 +-------------- eng/scripts/create_coverage.ps1 | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 eng/scripts/create_coverage.ps1 diff --git a/eng/pipelines/templates/steps/build-test.yml b/eng/pipelines/templates/steps/build-test.yml index 177f809dff23..246a8f796901 100644 --- a/eng/pipelines/templates/steps/build-test.yml +++ b/eng/pipelines/templates/steps/build-test.yml @@ -47,20 +47,7 @@ steps: env: GO111MODULE: 'on' - - pwsh: | - $coverageFiles = [Collections.Generic.List[String]]@() - Get-Childitem -recurse -path $(SCOPE) -filter coverage.txt | foreach-object { - $covFile = $_.FullName - Write-Host "Adding $covFile to the list of code coverage files" - $coverageFiles.Add($covFile) - } - gocovmerge $coverageFiles > mergedCoverage.txt - gocov convert ./mergedCoverage.txt > ./coverage.json - # gocov converts rely on standard input - Get-Content ./coverage.json | gocov-xml > ./coverage.xml - Get-Content ./coverage.json | gocov-html > ./coverage.html - # use internal tool to fail if coverage is too low - go run ../tools/internal/coverage/main.go --coverage-goal=${{ parameters.CoverageGoal}} + - pwsh: ./eng/scripts/create_coverage.ps1 displayName: 'Generate Coverage XML' workingDirectory: '${{parameters.GoWorkspace}}sdk' diff --git a/eng/scripts/create_coverage.ps1 b/eng/scripts/create_coverage.ps1 new file mode 100644 index 000000000000..9fd5a58b8200 --- /dev/null +++ b/eng/scripts/create_coverage.ps1 @@ -0,0 +1,17 @@ +#Requires -Version 7.0 + +$coverageFiles = [Collections.Generic.List[String]]@() +Get-Childitem -recurse -path $(SCOPE) -filter coverage.txt | foreach-object { + $covFile = $_.FullName + Write-Host "Adding $covFile to the list of code coverage files" + $coverageFiles.Add($covFile) +} +gocovmerge $coverageFiles > mergedCoverage.txt +gocov convert ./mergedCoverage.txt > ./coverage.json + +# gocov converts rely on standard input +Get-Content ./coverage.json | gocov-xml > ./coverage.xml +Get-Content ./coverage.json | gocov-html > ./coverage.html + +# use internal tool to fail if coverage is too low +go run ../tools/internal/coverage/main.go \ No newline at end of file From cd10a1a0d02e6b1ecfbccd7b44ad46618a804b2b Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Thu, 22 Jul 2021 11:20:54 -0400 Subject: [PATCH 14/18] fixing location of script --- eng/pipelines/templates/steps/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/pipelines/templates/steps/build-test.yml b/eng/pipelines/templates/steps/build-test.yml index 246a8f796901..a743df0da820 100644 --- a/eng/pipelines/templates/steps/build-test.yml +++ b/eng/pipelines/templates/steps/build-test.yml @@ -47,7 +47,7 @@ steps: env: GO111MODULE: 'on' - - pwsh: ./eng/scripts/create_coverage.ps1 + - pwsh: ../eng/scripts/create_coverage.ps1 displayName: 'Generate Coverage XML' workingDirectory: '${{parameters.GoWorkspace}}sdk' From e0a6e0322e605d60e8cafb4cd3c1ca274a977322 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Thu, 22 Jul 2021 11:28:52 -0400 Subject: [PATCH 15/18] fixing scope --- eng/scripts/create_coverage.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/scripts/create_coverage.ps1 b/eng/scripts/create_coverage.ps1 index 9fd5a58b8200..062cbfe8c7a6 100644 --- a/eng/scripts/create_coverage.ps1 +++ b/eng/scripts/create_coverage.ps1 @@ -1,7 +1,7 @@ #Requires -Version 7.0 $coverageFiles = [Collections.Generic.List[String]]@() -Get-Childitem -recurse -path $(SCOPE) -filter coverage.txt | foreach-object { +Get-Childitem -recurse -path . -filter coverage.txt | foreach-object { $covFile = $_.FullName Write-Host "Adding $covFile to the list of code coverage files" $coverageFiles.Add($covFile) From d2205c8413d0699b4ef99575b2ee9d81ffa22d9d Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Thu, 22 Jul 2021 15:42:03 -0400 Subject: [PATCH 16/18] fixing powershell portions, float instead of &float64 --- eng/scripts/create_coverage.ps1 | 2 +- eng/scripts/get_module_dirs.ps1 | 2 +- eng/scripts/get_test_dirs.ps1 | 2 +- tools/internal/coverage/main.go | 16 +++++++--------- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/eng/scripts/create_coverage.ps1 b/eng/scripts/create_coverage.ps1 index 062cbfe8c7a6..385e598cddf8 100644 --- a/eng/scripts/create_coverage.ps1 +++ b/eng/scripts/create_coverage.ps1 @@ -1,7 +1,7 @@ #Requires -Version 7.0 $coverageFiles = [Collections.Generic.List[String]]@() -Get-Childitem -recurse -path . -filter coverage.txt | foreach-object { +Get-ChildItem -recurse -path . -filter coverage.txt | ForEach-Object { $covFile = $_.FullName Write-Host "Adding $covFile to the list of code coverage files" $coverageFiles.Add($covFile) diff --git a/eng/scripts/get_module_dirs.ps1 b/eng/scripts/get_module_dirs.ps1 index 5404ea45a7a7..f8cddb955163 100644 --- a/eng/scripts/get_module_dirs.ps1 +++ b/eng/scripts/get_module_dirs.ps1 @@ -5,7 +5,7 @@ Param( $modDirs = [Collections.Generic.List[String]]@() # find each module directory under $serviceDir -Get-Childitem -recurse -path $serviceDir -filter go.mod | foreach-object { +Get-ChildItem -recurse -path $serviceDir -filter go.mod | ForEach-Object { $cdir = $_.Directory Write-Host "Adding $cdir to list of module paths" $modDirs.Add($cdir) diff --git a/eng/scripts/get_test_dirs.ps1 b/eng/scripts/get_test_dirs.ps1 index 0ad6b8136616..c599382af411 100644 --- a/eng/scripts/get_test_dirs.ps1 +++ b/eng/scripts/get_test_dirs.ps1 @@ -5,7 +5,7 @@ Param( $testDirs = [Collections.Generic.List[String]]@() # find each directory under $serviceDir that contains Go test files -Get-Childitem -recurse -path $serviceDir -filter *_test.go | foreach-object { +Get-ChildItem -recurse -path $serviceDir -filter *_test.go | ForEach-Object { $cdir = $_.Directory $tests = Select-String -Path $_ 'Test' -AllMatches diff --git a/tools/internal/coverage/main.go b/tools/internal/coverage/main.go index 48c6317a0772..805a91d1580d 100644 --- a/tools/internal/coverage/main.go +++ b/tools/internal/coverage/main.go @@ -66,18 +66,16 @@ func ReadConfigData() *CodeCoverage { // This supports doing a single package at a time. If this needs to be expanded in the future // this method will have to return a []*float64 for each packages goal -func findCoverageGoal(covFiles []string, configData *CodeCoverage) *float64 { - var ret float64 - +func findCoverageGoal(covFiles []string, configData *CodeCoverage) float64 { for _, covFile := range covFiles { for _, p := range configData.Packages { if strings.Contains(covFile, p.Name) { - return &p.CoverageGoal + return p.CoverageGoal } } } - - return &ret + fmt.Println("WARNING: Could not find a coverage goal, defaulting to 95%.") + return 0.95 } func main() { @@ -90,7 +88,7 @@ func main() { configData := ReadConfigData() coverageGoal := findCoverageGoal(coverageFiles, configData) - fmt.Printf("Failing if the coverage is below %.2f\n", *coverageGoal) + fmt.Printf("Failing if the coverage is below %.2f\n", coverageGoal) coverageValues := make([]float64, 0) for _, coverageFile := range coverageFiles { @@ -123,11 +121,11 @@ func main() { failedCoverage := false for i := range coverageValues { status := "Succeeded" - if coverageValues[i] < *coverageGoal { + if coverageValues[i] < coverageGoal { status = "Failed" } fmt.Printf("Status: %v\tCoverage file: %v\t Coverage Amount: %.4f\n", status, coverageFiles[i], coverageValues[i]) - if coverageValues[i] < *coverageGoal { + if coverageValues[i] < coverageGoal { failedCoverage = true } } From 7e2e1c5b83b75d221bcee683f2b00e0f1d9672a0 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Thu, 22 Jul 2021 18:11:44 -0400 Subject: [PATCH 17/18] forcing pipelines --- eng/scripts/create_coverage.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/eng/scripts/create_coverage.ps1 b/eng/scripts/create_coverage.ps1 index 385e598cddf8..56b1a6b3f8a4 100644 --- a/eng/scripts/create_coverage.ps1 +++ b/eng/scripts/create_coverage.ps1 @@ -6,6 +6,8 @@ Get-ChildItem -recurse -path . -filter coverage.txt | ForEach-Object { Write-Host "Adding $covFile to the list of code coverage files" $coverageFiles.Add($covFile) } + +# merge coverage files gocovmerge $coverageFiles > mergedCoverage.txt gocov convert ./mergedCoverage.txt > ./coverage.json From b6cb5920a15bc8b9e6d4e871ee18bd750633dd37 Mon Sep 17 00:00:00 2001 From: Sean Kane <68240067+seankane-msft@users.noreply.github.com> Date: Mon, 26 Jul 2021 10:53:25 -0400 Subject: [PATCH 18/18] Update tools/internal/coverage/main.go Co-authored-by: Ben Broderick Phillips --- tools/internal/coverage/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/internal/coverage/main.go b/tools/internal/coverage/main.go index 805a91d1580d..9ac4d26e39c3 100644 --- a/tools/internal/coverage/main.go +++ b/tools/internal/coverage/main.go @@ -99,7 +99,7 @@ func main() { byteValue, err := ioutil.ReadAll(xmlFile) check(err) - re := regexp.MustCompile(`