Skip to content

Commit

Permalink
[Eng] remove need for get_test_dirs.ps1 (#15874)
Browse files Browse the repository at this point in the history
* remove need for get_test_dirs.ps1

* removing get_test_dirs.ps1 entirely

* test and coverage all in one step

* skipping gocovmerge, gocov convert directly on coverage.txt

* cleanup

* try an arm directory with new ci

* failIfCoverageEmpty -> false

* removing RunTests param

* removing RunTests from ci

* undoing changes to identity
  • Loading branch information
seankane-msft authored Oct 20, 2021
1 parent 81dd8da commit 51e1954
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 151 deletions.
6 changes: 1 addition & 5 deletions eng/pipelines/templates/jobs/archetype-sdk-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ parameters:
- name: ServiceDirectory
type: string
default: ''
- name: RunTests
type: boolean
default: false
- name: RunLiveTests
type: boolean
default: false
Expand Down Expand Up @@ -113,8 +110,7 @@ stages:
GoWorkspace: $(GO_WORKSPACE_PATH)
Image: $(vm.image)
GoVersion: $(go.version)
RunTests: ${{ parameters.RunTests }}
TestProxy: true
TestProxy: true # Do we need this conditional if it's always true? @benbp
EnvVars:
AZURE_RECORD_MODE: 'playback'

Expand Down
91 changes: 40 additions & 51 deletions eng/pipelines/templates/steps/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ parameters:
- name: TestProxy
type: boolean
default: false
- name: RunTests
type: boolean
default: false
- name: EnvVars
type: object
default: {}
Expand Down Expand Up @@ -44,56 +41,48 @@ steps:
arguments: -vet -skipBuild -filter '${{ parameters.ServiceDirectory }}'
workingDirectory: '${{ parameters.GoWorkspace }}'

- ${{ if eq(parameters.RunTests, 'true') }}:
- pwsh: |
go install github.com/jstemmer/go-junit-report@v0.9.1
go install github.com/axw/gocov/gocov@v1.0.0
go install github.com/AlekSi/gocov-xml@v1.0.0
go install github.com/matm/gocov-html@v0.0.0-20200509184451-71874e2e203b
go install github.com/wadey/gocovmerge@v0.0.0-20160331181800-b5bfa59ec0ad
displayName: "Install Coverage and Junit Dependencies"
workingDirectory: '${{parameters.GoWorkspace}}'
- ${{ if eq(parameters.TestProxy, true) }}:
- template: /eng/common/testproxy/test-proxy-docker.yml
- pwsh: |
go install github.com/jstemmer/go-junit-report@v0.9.1
go install github.com/axw/gocov/gocov@v1.0.0
go install github.com/AlekSi/gocov-xml@v1.0.0
go install github.com/matm/gocov-html@v0.0.0-20200509184451-71874e2e203b
displayName: "Install Coverage and Junit Dependencies"
workingDirectory: '${{parameters.GoWorkspace}}'
- task: PowerShell@2
displayName: 'Run Tests'
inputs:
targetType: 'filePath'
filePath: ./eng/scripts/run_tests.ps1
arguments: '${{ parameters.ServiceDirectory }}'
pwsh: true
env:
GO111MODULE: 'on'
PROXY_CERT: $(Build.SourcesDirectory)/eng/common/testproxy/dotnet-devcert.crt
${{ insert }}: ${{ parameters.EnvVars }}
- ${{ if eq(parameters.TestProxy, true) }}:
- template: /eng/common/testproxy/test-proxy-docker.yml

- ${{ if eq(parameters.TestProxy, true) }}:
- pwsh: |
# ambitious_azsdk_test_proxy is the hardcoded container name used
# by the test proxy startup script
docker logs ambitious_azsdk_test_proxy
displayName: 'Dump Test Proxy logs'
condition: succeededOrFailed()
- pwsh: ./eng/scripts/create_coverage.ps1 ${{parameters.ServiceDirectory}}
displayName: 'Generate Coverage XML'
env:
GO111MODULE: 'off'
- task: PowerShell@2
displayName: 'Run Tests'
inputs:
targetType: 'filePath'
filePath: ./eng/scripts/run_tests.ps1
arguments: '${{ parameters.ServiceDirectory }}'
pwsh: true
env:
GO111MODULE: 'on'
PROXY_CERT: $(Build.SourcesDirectory)/eng/common/testproxy/dotnet-devcert.crt
${{ insert }}: ${{ parameters.EnvVars }}

- task: PublishTestResults@2
- ${{ if eq(parameters.TestProxy, true) }}:
- pwsh: |
# ambitious_azsdk_test_proxy is the hardcoded container name used
# by the test proxy startup script
docker logs ambitious_azsdk_test_proxy
displayName: 'Dump Test Proxy logs'
condition: succeededOrFailed()
inputs:
testRunner: JUnit
testResultsFiles: '${{parameters.GoWorkspace}}sdk/${{parameters.ServiceDirectory}}/**/report.xml'
testRunTitle: 'Go ${{ parameters.GoVersion }} on ${{ parameters.Image }}'
failTaskOnFailedTests: true
- task: PublishCodeCoverageResults@1
condition: succeededOrFailed()
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: './coverage.xml'
additionalCodeCoverageFiles: './coverage.html'
failIfCoverageEmpty: true
- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testRunner: JUnit
testResultsFiles: '${{parameters.GoWorkspace}}sdk/${{parameters.ServiceDirectory}}/**/report.xml'
testRunTitle: 'Go ${{ parameters.GoVersion }} on ${{ parameters.Image }}'
failTaskOnFailedTests: true

- task: PublishCodeCoverageResults@1
condition: succeededOrFailed()
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: './coverage.xml'
additionalCodeCoverageFiles: './coverage.html'
38 changes: 0 additions & 38 deletions eng/scripts/create_coverage.ps1

This file was deleted.

27 changes: 0 additions & 27 deletions eng/scripts/get_test_dirs.ps1

This file was deleted.

55 changes: 37 additions & 18 deletions eng/scripts/run_tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,41 @@ Param(
[string] $serviceDirectory
)

Write-Host "Finding test directories in 'sdk/$serviceDirectory'"
$testDirs = & $PSScriptRoot/get_test_dirs.ps1 -serviceDir $serviceDirectory
Write-Host $testDirs

foreach ($td in $testDirs) {
Push-Location $td
Write-Host "##[command]Executing 'go test -run "^Test" -v -coverprofile coverage.txt .' in $td"
go test -run "^Test" -v -coverprofile coverage.txt . | Tee-Object -FilePath outfile.txt
if ($LASTEXITCODE) {
exit $LASTEXITCODE
}
Get-Content outfile.txt | go-junit-report > report.xml

# if no tests were actually run (e.g. examples) delete the coverage file so it's omitted from the coverage report
if (Select-String -path ./report.xml -pattern '<testsuites></testsuites>' -simplematch -quiet) {
Write-Host "##[command]Deleting empty coverage file"
Remove-Item coverage.txt
}
Push-Location sdk/$serviceDirectory
Write-Host "##[command] Executing 'go test -run "^Test" -v -coverprofile coverage.txt ./...' in sdk/$serviceDirectory"

go test -run "^Test" -v -coverprofile coverage.txt ./... | Tee-Object -FilePath outfile.txt
if ($LASTEXITCODE) {
exit $LASTEXITCODE
}
Get-Content outfile.txt | go-junit-report > report.xml

# if no tests were actually run (e.g. examples) delete the coverage file so it's omitted from the coverage report
if (Select-String -path ./report.xml -pattern '<testsuites></testsuites>' -simplematch -quiet) {
Write-Host "##[command]Deleting empty coverage file"
Remove-Item coverage.txt
Remove-Item outfile.txt
Remove-Item report.xml

Pop-Location
} else {
# Tests were actually run create a coverage report
$repoRoot = Resolve-Path "$PSScriptRoot/../../"

gocov convert ./coverage.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

Move-Item ./coverage.xml $repoRoot
Move-Item ./coverage.html $repoRoot

# use internal tool to fail if coverage is too low
Pop-Location

go run $repoRoot/eng/tools/internal/coverage/coverage.go `
-config $repoRoot/eng/config.json `
-serviceDirectory $serviceDirectory `
-searchDirectory $repoRoot
}
1 change: 0 additions & 1 deletion sdk/azcore/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ stages:
- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml
parameters:
ServiceDirectory: azcore
RunTests: true
6 changes: 2 additions & 4 deletions sdk/data/azcosmos/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ stages:
- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml
parameters:
ServiceDirectory: 'data/azcosmos'
RunTests: true
- stage: Emulator
displayName: 'Cosmos Emulator'
jobs:
Expand Down Expand Up @@ -70,11 +69,10 @@ stages:
- template: /eng/pipelines/templates/steps/create-go-workspace.yml

- template: /eng/pipelines/templates/steps/build-test.yml
parameters:
parameters:
ServiceDirectory: 'data/azcosmos'
GoWorkspace: $(GO_WORKSPACE_PATH)
Image: $(vm.image)
GoVersion: $(go.version)
RunTests: true
EnvVars:
EnvVars:
EMULATOR: 'true'
1 change: 0 additions & 1 deletion sdk/data/aztables/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ stages:
- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml
parameters:
ServiceDirectory: 'data/aztables'
RunTests: true
RunLiveTests: true
1 change: 0 additions & 1 deletion sdk/internal/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ stages:
- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml
parameters:
ServiceDirectory: internal
RunTests: true
LicenseCheck: false
1 change: 0 additions & 1 deletion sdk/keyvault/azsecrets/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ stages:
- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml
parameters:
ServiceDirectory: 'keyvault/azsecrets'
RunTests: true
RunLiveTests: true
3 changes: 1 addition & 2 deletions sdk/messaging/azservicebus/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pr:
- main
- feature/*
- hotfix/*
- release/*
- release/*
paths:
include:
- sdk/messaging/azservicebus
Expand All @@ -25,5 +25,4 @@ stages:
- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml
parameters:
ServiceDirectory: 'messaging/azservicebus'
RunTests: true
RunLiveTests: true
1 change: 0 additions & 1 deletion sdk/storage/azblob/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ stages:
- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml
parameters:
ServiceDirectory: 'storage/azblob'
RunTests: true
1 change: 0 additions & 1 deletion sdk/template/aztemplate/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@ stages:
- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml
parameters:
ServiceDirectory: 'template/aztemplate'
RunTests: true

0 comments on commit 51e1954

Please sign in to comment.