Skip to content

Implemented live test and integrated into Azure pipeline #20505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .azure-pipelines/daily-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ jobs:
git clean -xdf

- task: PowerShell@2
displayName: Prepare Powershell $(PSVersion)
displayName: Prepare Powershell $(PSVersion)
inputs:
filePath: 'tools/Test/SmokeTest/PrepareRequiredPowershell.ps1'
arguments: '-RequiredPsVersion $(PSVersion)'
arguments: '-RequiredPsVersion $(PSVersion)'

- task: PowerShell@2
displayName: 'Install platyPS'
Expand All @@ -49,7 +49,7 @@ jobs:
inputs:
command: custom
custom: msbuild
arguments: 'build.proj /t:"Build" /p:"Configuration=Release"'
arguments: 'build.proj /t:"Build" /p:"Configuration=Release;TurnOnTestCoverage=true"'

- task: PowerShell@2
displayName: 'Bump Version'
Expand All @@ -60,7 +60,7 @@ jobs:
Get-PSRepository `
./tools/RunVersionController.ps1 -Release 'Daily Build $(today)' `
Exit"
dotnet tool run pwsh -c $command
dotnet tool run pwsh -c $command

- task: PowerShell@2
displayName: 'Clean artifacts folder'
Expand All @@ -74,7 +74,7 @@ jobs:
inputs:
command: custom
custom: msbuild
arguments: 'build.proj /t:Build /p:Configuration=Release'
arguments: 'build.proj /t:Build /p:Configuration=Release;TurnOnTestCoverage=true'

- task: EsrpCodeSigning@1
inputs:
Expand Down Expand Up @@ -132,7 +132,7 @@ jobs:
SessionTimeout: '60'
MaxConcurrency: '50'
MaxRetryAttempts: '5'

- task: EsrpCodeSigning@1
displayName: 'Sign 3rd Party [Strong Name]'
inputs:
Expand Down
128 changes: 128 additions & 0 deletions .azure-pipelines/live-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
parameters:
- name: win_image
displayName: Windows Image Version
type: string
default: windows-2019
- name: linux_image
displayName: Linux Image Version
type: string
default: ubuntu-20.04
- name: macOS_image
displayName: MacOS Image Version
type: string
default: macOS-11
- name: win_ps_5_1
displayName: Windows PowerShell 5.1 Version
type: string
default: 5.1
- name: ps_7_0_x
displayName: PowerShell 7.0.x Version
type: string
default: 7.0.13
- name: ps_7_1_x
displayName: PowerShell 7.1.x Version
type: string
default: 7.1.7
- name: ps_7_2_x
displayName: PowerShell 7.2.x Version
type: string
default: 7.2.7
- name: ps_latest
displayName: PowerShell Latest Version
type: string
default: latest
- name: dotnet_sdk_6
displayName: .NET 6 SDK Version
type: string
default: 6.0.x
- name: dotnet_sdk_7
displayName: .NET 7 SDK Version
type: string
default: 7.0.x

variables:
LiveTestArtifactsName: LiveTestArtifacts
LiveTestDataLocation: $(Pipeline.Workspace)/$(LiveTestArtifactsName)
EnableTestCoverage: true
TestCoverageLocation: $(LiveTestDataLocation)

pr: none
trigger: none

jobs:
- template: util/live-test-steps.yml
parameters:
name: 'win_ps_5_1'
vmImage: ${{ parameters.win_image }}
psVersion: ${{ parameters.win_ps_5_1 }}
dotnetVersion: ${{ parameters.dotnet_sdk_6 }}

- template: util/live-test-steps.yml
parameters:
name: 'ps_7_0_x_win'
vmImage: ${{ parameters.win_image }}
psVersion: ${{ parameters.ps_7_0_x }}
dotnetVersion: ${{ parameters.dotnet_sdk_6 }}

- template: util/live-test-steps.yml
parameters:
name: 'ps_7_1_x_win'
vmImage: ${{ parameters.win_image }}
psVersion: ${{ parameters.ps_7_1_x }}
dotnetVersion: ${{ parameters.dotnet_sdk_6 }}

- template: util/live-test-steps.yml
parameters:
name: 'ps_7_2_x_win'
vmImage: ${{ parameters.win_image }}
psVersion: ${{ parameters.ps_7_2_x }}
dotnetVersion: ${{ parameters.dotnet_sdk_6 }}

- template: util/live-test-steps.yml
parameters:
name: 'ps_latest_win'
vmImage: ${{ parameters.win_image }}
psVersion: ${{ parameters.ps_latest }}
dotnetVersion: ${{ parameters.dotnet_sdk_7 }}

- template: util/live-test-steps.yml
parameters:
name: 'ps_7_0_x_linux'
vmImage: ${{ parameters.linux_image }}
psVersion: ${{ parameters.ps_7_0_x }}
dotnetVersion: ${{ parameters.dotnet_sdk_6 }}

- template: util/live-test-steps.yml
parameters:
name: 'ps_7_1_x_linux'
vmImage: ${{ parameters.linux_image }}
psVersion: ${{ parameters.ps_7_1_x }}
dotnetVersion: ${{ parameters.dotnet_sdk_6 }}

- template: util/live-test-steps.yml
parameters:
name: 'ps_7_2_x_linux'
vmImage: ${{ parameters.linux_image }}
psVersion: ${{ parameters.ps_7_2_x }}
dotnetVersion: ${{ parameters.dotnet_sdk_6 }}

- template: util/live-test-steps.yml
parameters:
name: 'ps_latest_linux'
vmImage: ${{ parameters.linux_image }}
psVersion: ${{ parameters.ps_latest }}
dotnetVersion: ${{ parameters.dotnet_sdk_7 }}

- template: util/live-test-steps.yml
parameters:
name: 'ps_7_2_x_macOS'
vmImage: ${{ parameters.macOS_image }}
psVersion: ${{ parameters.ps_7_2_x }}
dotnetVersion: ${{ parameters.dotnet_sdk_6 }}

- template: util/live-test-steps.yml
parameters:
name: 'ps_latest_macOS'
vmImage: ${{ parameters.macOS_image }}
psVersion: ${{ parameters.ps_latest }}
dotnetVersion: ${{ parameters.dotnet_sdk_7 }}
111 changes: 111 additions & 0 deletions .azure-pipelines/util/live-test-steps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
parameters:
- name: name
- name: vmImage
- name: psVersion
- name: dotnetVersion

jobs:
- job: ${{ parameters.name }}
timeoutInMinutes: 180
pool:
vmImage: ${{ parameters.vmImage }}

steps:
- task: UseDotNet@2
condition: ne('${{ parameters.dotnetVersion }}', '')
displayName: Install desired .NET version ${{ parameters.dotnetVersion }}
inputs:
packageType: sdk
version: ${{ parameters.dotnetVersion }}

- task: PowerShell@2
displayName: Install desired Powershell version ${{ parameters.psVersion }}
inputs:
pwsh: true
targetType: filePath
filePath: ./tools/TestFx/Live/InitializeLiveTestEnvironment.ps1
arguments: -DesiredVersion ${{ parameters.psVersion }}

- task: PowerShell@2
displayName: Create live test data location directory
inputs:
pwsh: true
targetType: inline
script:
New-Item -Name $(LiveTestArtifactsName) -Path $(Pipeline.Workspace) -ItemType Directory -Force

- task: DownloadPipelineArtifact@2
condition: and(succeeded(), eq(variables['GalleryName'], 'DailyBuild'), eq(variables['BuildPipelineBuildId'], ''))
displayName: Download latest artifacts from daily build pipeline main branch
inputs:
buildType: specific
project: $(ProjectToDownloadArtifacts)
definition: $(BuildPipelineDefinitionId)
buildVersionToDownload: latestFromBranch
branchName: refs/heads/master
artifactName: $(ArtifactName)
targetPath: $(Pipeline.Workspace)

- task: DownloadPipelineArtifact@2
condition: and(succeeded(), eq(variables['GalleryName'], 'DailyBuild'), ne(variables['BuildPipelineBuildId'], ''))
displayName: Download specific artifacts from daily build pipeline
inputs:
buildType: specific
project: $(ProjectToDownloadArtifacts)
definition: $(BuildPipelineDefinitionId)
buildVersionToDownload: specific
pipelineId: $(BuildPipelineBuildId)
artifactName: $(ArtifactName)
targetPath: $(Pipeline.Workspace)

- task: PowerShell@2
condition: and(succeeded(), eq(variables['GalleryName'], 'DailyBuild'))
displayName: Copy artifacts to local repository
inputs:
pwsh: true
targetType: inline
script: |
$azPackagesDir = New-Item -Name AzPackages -Path $(LiveTestDataLocation) -ItemType Directory -Force
$azPackagesFiles = Join-Path -Path $(Pipeline.Workspace) -ChildPath *.nupkg
Move-Item -Path $azPackagesFiles -Destination $azPackagesDir
Get-ChildItem -LiteralPath $azPackagesDir

- task: PowerShell@2
displayName: Install desired Az module from $(GalleryName)
inputs:
pwsh: true
targetType: filePath
filePath: ./tools/TestFx/Live/InvokeLiveTestCITask.ps1
arguments: -UseWindowsPowerShell ('${{ parameters.psVersion }}' -eq '5.1') -ScriptFile './tools/TestFx/Live/InstallLiveTestAzModules.ps1 -Source $(GalleryName) -AzPackagesLocation (Convert-Path -LiteralPath $(LiveTestDataLocation) | Join-Path -ChildPath AzPackages)'

- task: PowerShell@2
displayName: Connect Azure with live test service principal
inputs:
pwsh: true
targetType: filePath
filePath: ./tools/TestFx/Live/InvokeLiveTestCITask.ps1
arguments: -UseWindowsPowerShell ('${{ parameters.psVersion }}' -eq '5.1') -ScriptFile './tools/TestFx/Live/ConnectLiveTestServicePrincipal.ps1 $(LiveTestServicePrincipalSubscriptionId) $(LiveTestServicePrincipalTenantId) $(LiveTestServicePrincipalId) $(LiveTestServicePrincipalSecret)'

- task: PowerShell@2
displayName: Run top E2E live scenarios
inputs:
pwsh: true
targetType: filePath
filePath: ./tools/TestFx/Live/InvokeLiveTestCITask.ps1
arguments: -UseWindowsPowerShell ('${{ parameters.psVersion }}' -eq '5.1') -ScriptFile './tools/TestFx/Live/InvokeLiveTestScenarios.ps1 $(Build.BuildId) ${{ parameters.vmImage }} ${{ parameters.psVersion }} $(Build.SourcesDirectory) $(LiveTestDataLocation)'
failOnStderr: true

- task: PowerShell@2
displayName: Save live test results to Kusto
inputs:
pwsh: true
targetType: filePath
filePath: ./tools/TestFx/Live/SaveLiveTestResult.ps1
arguments: $(KustoServicePrincipalTenantId) $(KustoServicePrincipalId) $(KustoServicePrincipalSecret) $(KustoClusterName) $(KustoClusterRegion) $(LiveTestDatabaseName) $(LiveTestTableName) $(TestCoverageTableName) $(LiveTestDataLocation)

- task: PublishPipelineArtifact@1
displayName: Publish live test results to pipeline artifact
inputs:
artifact: livetest-os-${{ parameters.vmImage }}-powershell-${{ parameters.psVersion }}
targetPath: $(LiveTestDataLocation)
condition: always()
13 changes: 8 additions & 5 deletions build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@
<DockerRoot>$(RepoRoot)docker</DockerRoot>
<DockerTools>$(RepoTools)Docker</DockerTools>
<DockerImageName Condition="'$(DockerImageName)' == ''">azure-powershell</DockerImageName>
<!-- XML documentation related -->

<!-- XML documentation related -->
<GenerateDocumentationFile Condition="'$(GenerateDocumentationFile)' != 'false'">true</GenerateDocumentationFile>

<!-- Test coverage flag -->
<TurnOnTestCoverage Condition="'$(TurnOnTestCoverage)' != 'true'">false</TurnOnTestCoverage>
</PropertyGroup>

<!-- Tasks -->
Expand Down Expand Up @@ -194,9 +197,9 @@
<BuildAction Condition="'$(Configuration)' != 'Release'">build</BuildAction>
<BuildAction Condition="'$(Configuration)' == 'Release'">publish</BuildAction>
</PropertyGroup>
<Exec Command="$(PowerShellCoreCommandPrefix) &quot;.\tools\ExecuteCIStep.ps1 -Build -RepoArtifacts $(RepoArtifacts) -Configuration $(Configuration) -GenerateDocumentationFile $(GenerateDocumentationFile) -BuildAction $(BuildAction)&quot;" />

<Exec Command="$(PowerShellCoreCommandPrefix) &quot;.\tools\ExecuteCIStep.ps1 -Build -RepoArtifacts $(RepoArtifacts) -Configuration $(Configuration) -GenerateDocumentationFile $(GenerateDocumentationFile) -EnableTestCoverage $(TurnOnTestCoverage) -BuildAction $(BuildAction)&quot;" />

<!-- Build version controller -->
<Exec Command="dotnet build $(RepoTools)VersionController/VersionController.Netcore.csproj -c $(Configuration)" />

Expand Down
4 changes: 2 additions & 2 deletions src/Az.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<SignAssembly>true</SignAssembly>
<DelaySign>true</DelaySign>
<AssemblyOriginatorKeyFile>$(RepoSrc)MSSharedLibKey.snk</AssemblyOriginatorKeyFile>
<DefineConstants>TRACE;RELEASE;NETSTANDARD;SIGN</DefineConstants>
<DefineConstants>TRACE;RELEASE;NETSTANDARD;SIGN;$(TestCoverage)</DefineConstants>
</PropertyGroup>

<!-- Resources -->
Expand Down Expand Up @@ -53,4 +53,4 @@
<None Update="*.ps1xml" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>
</Project>
22 changes: 14 additions & 8 deletions tools/ExecuteCIStep.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ Param(
[String]
$BuildAction='build',

[Switch]
[String]
$GenerateDocumentationFile,

[String]
$EnableTestCoverage,

[Switch]
$Test,

Expand All @@ -37,10 +40,10 @@ Param(

[Switch]
$StaticAnalysisDependency,

[Switch]
$StaticAnalysisSignature,

[Switch]
$StaticAnalysisHelp,

Expand Down Expand Up @@ -70,14 +73,17 @@ $ErrorActionPreference = 'Stop'
If ($Build)
{
$LogFile = "$RepoArtifacts/Build.Log"
If ($GenerateDocumentationFile)
$buildCmdResult = "dotnet $BuildAction $RepoArtifacts/Azure.PowerShell.sln -c $Configuration -fl '/flp1:logFile=$LogFile;verbosity=quiet'"
If ($GenerateDocumentationFile -eq "false")
{
dotnet $BuildAction $RepoArtifacts/Azure.PowerShell.sln -c $Configuration -fl "/flp1:logFile=$LogFile;verbosity=quiet"
$buildCmdResult += " -p:GenerateDocumentationFile=false"
}
Else
if ($EnableTestCoverage -eq "true")
{
dotnet $BuildAction $RepoArtifacts/Azure.PowerShell.sln -c $Configuration -p:GenerateDocumentationFile=false -fl "/flp1:logFile=$LogFile;verbosity=quiet"
$buildCmdResult += " -p:TestCoverage=TESTCOVERAGE"
}
Invoke-Expression -Command $buildCmdResult

If (Test-Path -Path "$RepoArtifacts/PipelineResult")
{
$LogContent = Get-Content $LogFile
Expand Down Expand Up @@ -324,4 +330,4 @@ If ($StaticAnalysisUX)
dotnet $RepoArtifacts/StaticAnalysis/StaticAnalysis.Netcore.dll -p $RepoArtifacts/$Configuration -r $StaticAnalysisOutputDirectory --analyzers ux -u -m $UXModuleList
}
Return
}
}
Loading