Skip to content
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

Modify logic of deploying Arm template according to artifacts #18773

Closed
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
34 changes: 28 additions & 6 deletions eng/common/TestResources/New-TestResources.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ param (
[Parameter(Mandatory = $true, Position = 0)]
[string] $ServiceDirectory,

[Parameter()]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @benbp

You cannot edit these common files in the language repo instead you need to follow the https://github.com/Azure/azure-sdk-tools/blob/master/doc/common/common_engsys.md#workflow

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @weshaggard , I will follow the workflow and work with @benbp .

[string] $Artifacts,

[Parameter()]
[ValidatePattern('^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$')]
[string] $TestApplicationId,
Expand Down Expand Up @@ -144,16 +147,30 @@ try {
# Azure SDK Developer Playground
$defaultSubscription = "faa080af-c1d8-40ad-9cce-e1a450ca5b57"

Write-Verbose "Checking for '$templateFileName' files under '$root'"
Get-ChildItem -Path $root -Filter $templateFileName -Recurse | ForEach-Object {
$templateFile = $_.FullName
# Deploy test resources according to Artifacts
if ($Artifacts) {
$Artifacts.TrimStart(",").Split(",") | ForEach-Object {
$templateFilePath = Join-Path $root $_
Write-Verbose "Checking for '$templateFileName' files under '$templateFilePath'"
Get-ChildItem -Path $templateFilePath -Filter $templateFileName -Recurse | ForEach-Object {
$templateFile = $_.FullName

Write-Verbose "Found template '$templateFile'"
$templateFiles += $templateFile
}
}
} else {
Write-Verbose "Checking for '$templateFileName' files under '$root'"
Get-ChildItem -Path $root -Filter $templateFileName -Recurse | ForEach-Object {
$templateFile = $_.FullName

Write-Verbose "Found template '$templateFile'"
$templateFiles += $templateFile
Write-Verbose "Found template '$templateFile'"
$templateFiles += $templateFile
}
}

if (!$templateFiles) {
Write-Warning -Message "No template files found under '$root'"
Write-Warning -Message "No template files found"
exit
}

Expand Down Expand Up @@ -550,6 +567,11 @@ A directory under 'sdk' in the repository root - optionally with subdirectories
specified - in which to discover ARM templates named 'test-resources.json'.
This can also be an absolute path or specify parent directories.

.PARAMETER Artifacts
A string of all artifact names defined in tests.yml under ServiceDirectory. If the

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep same style, use Artifact instead of artifact

value is not set, then all ARM templates under ServiceDirectory will be found to deploy
test resources. Otherwise, only templates under ServiceDirectory/artifact will be discovered.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ServiceDirectory/Artifact


.PARAMETER TestApplicationId
The AAD Application ID to authenticate the test runner against deployed
resources. Passed to the ARM template as 'testApplicationId'.
Expand Down
25 changes: 22 additions & 3 deletions eng/common/TestResources/New-TestResources.ps1.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Deploys live test resources defined for a service directory to Azure.
### Default (Default)
```
New-TestResources.ps1 [-BaseName <String>] [-ResourceGroupName <String>] [-ServiceDirectory] <String>
[-TestApplicationId <String>] [-TestApplicationSecret <String>] [-TestApplicationOid <String>]
[-Artifacts <String>] [-TestApplicationId <String>] [-TestApplicationSecret <String>] [-TestApplicationOid <String>]
[-DeleteAfterHours <Int32>] [-Location <String>] [-Environment <String>] [-ArmTemplateParameters <Hashtable>]
[-AdditionalParameters <Hashtable>] [-EnvironmentVariables <Hashtable>] [-CI] [-Force] [-OutFile] [-WhatIf]
[-Confirm] [<CommonParameters>]
Expand All @@ -35,8 +35,9 @@ New-TestResources.ps1 [-BaseName <String>] [-ResourceGroupName <String>] [-Servi
Deploys live test resouces specified in test-resources.json files to a resource
group.

This script searches the directory specified in $ServiceDirectory recursively
for files named test-resources.json.
This script searches for files named test-resources.json in each artifact project
of $Artifacts under $ServiceDirectory recursively. When $Artifacts is not set, the

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes directory name not equal to artifact name.
So maybe we can use SubDirectories instead of Artifacts?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

script will search the directory $ServiceDirectory directly.
All found test-resources.json files will be
deployed to the test resource group.

Expand Down Expand Up @@ -70,6 +71,7 @@ the SecureString to plaintext by another means.
New-TestResources.ps1 `
-BaseName 'Generated' `
-ServiceDirectory '$(ServiceDirectory)' `
-Artifacts '$(Artifacts)' `
-TenantId '$(TenantId)' `
-ProvisionerApplicationId '$(ProvisionerId)' `
-ProvisionerApplicationSecret '$(ProvisionerSecret)' `
Expand Down Expand Up @@ -142,6 +144,23 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -Artifacts
A string of all artifact names defined in tests.yml under ServiceDirectory. If the
value is not set, then all ARM templates under ServiceDirectory will be found to deploy
test resources. Otherwise, only templates under ServiceDirectory/artifact will be discovered.

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -TestApplicationId
The AAD Application ID to authenticate the test runner against deployed
resources.
Expand Down
12 changes: 11 additions & 1 deletion eng/common/TestResources/deploy-test-resources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ parameters:
DeleteAfterHours: 8
Location: ''
SubscriptionConfiguration: $(sub-config-azure-cloud-test-resources)

Artifacts: []
# SubscriptionConfiguration will be splatted into the parameters of the test
# resources script. It should be JSON in the form:
# {
Expand Down Expand Up @@ -35,6 +35,15 @@ parameters:
steps:
- template: /eng/common/TestResources/setup-az-modules.yml

- pwsh: |
Write-Host "##vso[task.setvariable variable=ArtifactList;]"
displayName: Initialize artifact list variable

- ${{each artifact in parameters.Artifacts }}:
- pwsh: |
Write-Host "##vso[task.setvariable variable=ArtifactList;]$(ArtifactList),${{artifact.name}}"
displayName: Append ${{artifact.name}} to artifact list

- pwsh: |
eng/common/TestResources/Import-AzModules.ps1

Expand All @@ -48,6 +57,7 @@ steps:
eng/common/TestResources/New-TestResources.ps1 `
-BaseName 'Generated' `
-ServiceDirectory '${{ parameters.ServiceDirectory }}' `
-Artifacts '$(ArtifactList)' `
-Location '${{ parameters.Location }}' `
-DeleteAfterHours '${{ parameters.DeleteAfterHours }}' `
@subscriptionConfiguration `
Expand Down
3 changes: 2 additions & 1 deletion eng/pipelines/templates/jobs/archetype-sdk-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,15 @@ jobs:
SubscriptionConfiguration: $(SubscriptionConfiguration)
ArmTemplateParameters: $(ArmTemplateParameters)
Location: $(Location)
Artifacts: ${{ parameters.Artifacts }}

- ${{ parameters.PreRunSteps }}

- template: ../steps/generate-project-list.yml
parameters:
Artifacts: ${{parameters.Artifacts}}
AdditionalModules: ${{parameters.AdditionalModules}}

- task: UsePythonVersion@0
displayName: 'Use Python 3.6'
inputs:
Expand Down