-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathtest.yml
More file actions
194 lines (172 loc) · 9.29 KB
/
test.yml
File metadata and controls
194 lines (172 loc) · 9.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
parameters:
jobName: TestPkgWin
imageName: windows-latest
displayName: PowerShell Core on Windows
powershellExecutable: pwsh
buildDirectory: '.'
useAzAuth: false
jobs:
- job: ${{ parameters.jobName }}
pool:
vmImage: ${{ parameters.imageName }}
displayName: ${{ parameters.displayName }}
steps:
- ${{ parameters.powershellExecutable }}: |
Install-Module -Name 'Microsoft.PowerShell.SecretManagement' -force -SkipPublisherCheck -AllowClobber
Install-Module -Name 'Microsoft.PowerShell.SecretStore' -force -SkipPublisherCheck -AllowClobber
$vaultPassword = ConvertTo-SecureString $("a!!"+ (Get-Random -Maximum ([int]::MaxValue))) -AsPlainText -Force
Set-SecretStoreConfiguration -Authentication None -Interaction None -Confirm:$false -Password $vaultPassword
Register-SecretVault -Name SecretStore -ModuleName Microsoft.PowerShell.SecretStore -DefaultVault
displayName: Install Secret store
condition: eq(${{ parameters.useAzAuth }}, false)
- task: NuGetAuthenticate@1
displayName: Install Azure Artifacts Credential Provider
inputs:
forceReinstallCredentialProvider: true
- task: DownloadBuildArtifacts@0
displayName: 'Download artifacts'
inputs:
buildType: current
downloadType: specific
itemPattern: '**/*.nupkg'
downloadPath: '$(System.ArtifactsDirectory)'
- ${{ parameters.powershellExecutable }}: |
Get-ChildItem -Path "$(System.ArtifactsDirectory)"
displayName: Capture artifacts directory
- ${{ parameters.powershellExecutable }}: |
$modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules'
if (Test-Path -Path $modulePath) {
Write-Verbose -Verbose "Deleting existing temp module path: $modulePath"
Remove-Item -Path $modulePath -Recurse -Force -ErrorAction Ignore
}
if (! (Test-Path -Path $modulePath)) {
Write-Verbose -Verbose "Creating new temp module path: $modulePath"
$null = New-Item -Path $modulePath -ItemType Directory
}
displayName: Create temporary module path
- ${{ parameters.powershellExecutable }}: |
$modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules'
Write-Verbose -Verbose "Install Microsoft.PowerShell.PSResourceGet to temp module path"
Save-Module -Name Microsoft.PowerShell.PSResourceGet -Path $modulePath -Force -Verbose
Write-Verbose -Verbose "Install Pester 4.X to temp module path"
Save-Module -Name "Pester" -MaximumVersion 4.99 -Path $modulePath -Force
displayName: Install Microsoft.PowerShell.PSResourceGet and Pester
- ${{ parameters.powershellExecutable }}: |
$modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules'
$env:PSModulePath = $modulePath + [System.IO.Path]::PathSeparator + $env:PSModulePath
Write-Verbose -Verbose "Importing build utilities (buildtools.psd1)"
Import-Module -Name (Join-Path -Path '${{ parameters.buildDirectory }}' -ChildPath 'buildtools.psd1') -Force
#
Install-ModulePackageForTest -PackagePath "$(System.ArtifactsDirectory)" -ErrorAction stop -Verbose
displayName: Install module for test from downloaded artifact
workingDirectory: ${{ parameters.buildDirectory }}
- task: AzurePowerShell@5
inputs:
azureSubscription: PSResourceGetACR
azurePowerShellVersion: LatestVersion
ScriptType: InlineScript
pwsh: true
inline: |
Write-Verbose -Verbose "Setting up secret for Azure Artifacts Credential Provider"
$azt = (Get-AzAccessToken).Token | ConvertFrom-SecureString -AsPlainText
Write-Verbose -Verbose "Setting up Azure Artifacts Credential Provider secret - token - $azt"
$ADORepoName = "psrg-credprovidertest"
$ADORepoUri = "https://pkgs.dev.azure.com/powershell-rel/PSResourceGet/_packaging/psrg-credprovidertest/nuget/v2"
$endpointCredsObj = @{ endpointCredentials = @( @{ endpoint = $ADoRepoURI; password = $azt })}
$VSS_NUGET_EXTERNAL_FEED_ENDPOINTS = $endpointCredsObj | ConvertTo-Json -Compress
Write-Verbose -Verbose "Setting VSS_NUGET_EXTERNAL_FEED_ENDPOINTS environment variable $VSS_NUGET_EXTERNAL_FEED_ENDPOINTS"
$vstsCommandString = "vso[task.setvariable variable=VSS_NUGET_EXTERNAL_FEED_ENDPOINTS]$VSS_NUGET_EXTERNAL_FEED_ENDPOINTS"
Write-Host "sending " + $vstsCommandString
Write-Host "##$vstsCommandString"
displayName: 'Setup Azure Artifacts Credential Provider secret'
condition: eq(${{ parameters.useAzAuth }}, false)
- pwsh: |
Get-ChildItem -Path env: | Out-String -width 9999 -Stream | Write-Verbose -Verbose
displayName: Capture environment
- task: AzurePowerShell@5
inputs:
azureSubscription: PSResourceGetACR
azurePowerShellVersion: LatestVersion
ScriptType: InlineScript
pwsh: true
inline: |
Write-Verbose -Verbose "Getting Azure Container Registry"
Get-AzContainerRegistry -ResourceGroupName 'PSResourceGet' -Name 'psresourcegettest' | Select-Object -Property *
Write-Verbose -Verbose "Setting up secret for Azure Container Registry"
$azt = Get-AzAccessToken
$tenantId = $azt.TenantID
Set-Secret -Name "AzureAccessToken: $tenantId" -Secret $azt.Token -Verbose
$vstsCommandString = "vso[task.setvariable variable=TenantId]$tenantId"
Write-Host "sending " + $vstsCommandString
Write-Host "##$vstsCommandString"
displayName: 'Setup Azure Container Registry secret'
condition: eq(${{ parameters.useAzAuth }}, false)
- powershell: |
# Set environment variable to identify in tests that secret store should not be used.
$vstsCommandString = "vso[task.setvariable variable=UsingAzAuth]true"
Write-Host "sending " + $vstsCommandString
Write-Host "##$vstsCommandString"
displayName: 'Set UsingAzAuth environment variable'
condition: eq(${{ parameters.useAzAuth }}, true)
- task: AzurePowerShell@5
inputs:
azureSubscription: PSResourceGetACR
azurePowerShellVersion: LatestVersion
ScriptType: InlineScript
inline: |
$acrRepositoryNamesFolder = Join-Path -Path ([Environment]::GetFolderPath([System.Environment+SpecialFolder]::LocalApplicationData)) -ChildPath 'TempModules'
Write-Verbose -Verbose "Creating new folder for acr repository names file to be placed with path: $acrRepositoryNamesFolder"
$null = New-Item -Path $acrRepositoryNamesFolder -ItemType Directory
$acrRepositoryNamesFilePath = Join-Path -Path $acrRepositoryNamesFolder -ChildPath 'ACRTestRepositoryNames.txt'
New-Item -Path $acrRepositoryNamesFilePath
displayName: 'Upload empty file for ACR functional tests to write test repository names to'
- task: AzurePowerShell@5
inputs:
azureSubscription: PSResourceGetACR
azurePowerShellVersion: LatestVersion
pwsh: true
ScriptType: InlineScript
inline: |
$modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules'
$env:PSModulePath = $modulePath + [System.IO.Path]::PathSeparator + $env:PSModulePath
Write-Verbose -Verbose "Importing build utilities (buildtools.psd1)"
Import-Module -Name (Join-Path -Path '${{ parameters.buildDirectory }}' -ChildPath 'buildtools.psd1') -Force
Invoke-ModuleTestsACR -Type Functional
env:
MAPPED_GITHUB_PAT: $(github_pat)
MAPPED_ADO_PUBLIC_PAT: $(ado_public_pat)
MAPPED_ADO_PRIVATE_PAT: $(ado_private_pat)
MAPPED_ADO_PRIVATE_REPO_URL: $(ado_private_repo_url)
displayName: 'Execute functional tests with AzAuth'
condition: eq(${{ parameters.useAzAuth }}, true)
- ${{ parameters.powershellExecutable }}: |
$modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules'
$env:PSModulePath = $modulePath + [System.IO.Path]::PathSeparator + $env:PSModulePath
Write-Verbose -Verbose "Importing build utilities (buildtools.psd1)"
Import-Module -Name (Join-Path -Path '${{ parameters.buildDirectory }}' -ChildPath 'buildtools.psd1') -Force
Invoke-ModuleTests -Type Functional
env:
MAPPED_GITHUB_PAT: $(github_pat)
MAPPED_ADO_PUBLIC_PAT: $(ado_public_pat)
MAPPED_ADO_PRIVATE_PAT: $(ado_private_pat)
MAPPED_ADO_PRIVATE_REPO_URL: $(ado_private_repo_url)
displayName: Execute functional tests
workingDirectory: ${{ parameters.buildDirectory }}
errorActionPreference: continue
condition: eq(${{ parameters.useAzAuth }}, false)
- task: AzurePowerShell@5
inputs:
azureSubscription: PSResourceGetACR
azurePowerShellVersion: LatestVersion
ScriptType: InlineScript
inline: |
$registryName = 'psresourcegettest'
$acrRepositoryNamesFolder = Join-Path -Path ([Environment]::GetFolderPath([System.Environment+SpecialFolder]::LocalApplicationData)) -ChildPath 'TempModules'
$acrRepositoryNamesFilePath = Join-Path -Path $acrRepositoryNamesFolder -ChildPath 'ACRTestRepositoryNames.txt'
$repositoryNames = Get-Content -Path $acrRepositoryNamesFilePath
foreach ($name in $repositoryNames)
{
# Delete images in the repository (including tags, unique layers, manifests) created for ACR tests
Remove-AzContainerRegistryRepository -Name $name -RegistryName $registryName
}
displayName: 'Delete test repositories from ACR'