From 7843c33496aaf764ec34dc1c018931372bd7a7df Mon Sep 17 00:00:00 2001 From: Sima Zhu Date: Fri, 20 Nov 2020 08:58:11 -0800 Subject: [PATCH 1/9] Move to common eng docindex folder --- .../TestResources/New-TestResources.ps1 | 598 +++++++++--------- .../TestResources/New-TestResources.ps1.md | 7 +- eng/common/scripts/ChangeLog-Operations.ps1 | 117 +++- eng/common/scripts/Package-Properties.ps1 | 10 +- eng/common/scripts/SemVer.ps1 | 9 +- eng/scripts/Language-Settings.ps1 | 3 + 6 files changed, 422 insertions(+), 322 deletions(-) diff --git a/eng/common/TestResources/New-TestResources.ps1 b/eng/common/TestResources/New-TestResources.ps1 index 7af197ef9ddd7..25f0b18c31cf6 100644 --- a/eng/common/TestResources/New-TestResources.ps1 +++ b/eng/common/TestResources/New-TestResources.ps1 @@ -125,374 +125,387 @@ $exitActions = @({ } }) -trap { - # Like using try..finally in PowerShell, but without keeping track of more braces or tabbing content. - $exitActions.Invoke() +New-Variable -Name 'initialContext' -Value (Get-AzContext) -Option Constant +if ($initialContext) { + $exitActions += { + Write-Verbose "Restoring initial context: $($initialContext.Account)" + $null = $initialContext | Select-AzContext + } } -# Enumerate test resources to deploy. Fail if none found. -$repositoryRoot = "$PSScriptRoot/../../.." | Resolve-Path -$root = [System.IO.Path]::Combine($repositoryRoot, "sdk", $ServiceDirectory) | Resolve-Path -$templateFileName = 'test-resources.json' -$templateFiles = @() -# Azure SDK Developer Playground -$defaultSubscription = "faa080af-c1d8-40ad-9cce-e1a450ca5b57" +# try..finally will also trap Ctrl+C. +try { -Write-Verbose "Checking for '$templateFileName' files under '$root'" -Get-ChildItem -Path $root -Filter $templateFileName -Recurse | ForEach-Object { - $templateFile = $_.FullName + # Enumerate test resources to deploy. Fail if none found. + $repositoryRoot = "$PSScriptRoot/../../.." | Resolve-Path + $root = [System.IO.Path]::Combine($repositoryRoot, "sdk", $ServiceDirectory) | Resolve-Path + $templateFileName = 'test-resources.json' + $templateFiles = @() + # Azure SDK Developer Playground + $defaultSubscription = "faa080af-c1d8-40ad-9cce-e1a450ca5b57" - Write-Verbose "Found template '$templateFile'" - $templateFiles += $templateFile -} + Write-Verbose "Checking for '$templateFileName' files under '$root'" + Get-ChildItem -Path $root -Filter $templateFileName -Recurse | ForEach-Object { + $templateFile = $_.FullName -if (!$templateFiles) { - Write-Warning -Message "No template files found under '$root'" - exit -} + Write-Verbose "Found template '$templateFile'" + $templateFiles += $templateFile + } -$UserName = if ($env:USER) { $env:USER } else { "${env:USERNAME}" } -# Remove spaces, etc. that may be in $UserName -$UserName = $UserName -replace '\W' + if (!$templateFiles) { + Write-Warning -Message "No template files found under '$root'" + exit + } -# If no base name is specified use current user name -if (!$BaseName) { - $BaseName = "$UserName$ServiceDirectory" + $UserName = if ($env:USER) { $env:USER } else { "${env:USERNAME}" } + # Remove spaces, etc. that may be in $UserName + $UserName = $UserName -replace '\W' + + # Make sure $BaseName is set. + if ($CI) { + $BaseName = 't' + (New-Guid).ToString('n').Substring(0, 16) + Log "Generated base name '$BaseName' for CI build" + } elseif (!$BaseName) { + $BaseName = "$UserName$ServiceDirectory" + Log "BaseName was not set. Using default base name: '$BaseName'" + } # Make sure pre- and post-scripts are passed formerly required arguments. $PSBoundParameters['BaseName'] = $BaseName - Log "BaseName was not set. Using default base name: '$BaseName'" -} + # Try detecting repos that support OutFile and defaulting to it + if (!$CI -and !$PSBoundParameters.ContainsKey('OutFile') -and $IsWindows) { + # TODO: find a better way to detect the language + if (Test-Path "$repositoryRoot/eng/service.proj") { + $OutFile = $true + Log "Detected .NET repository. Defaulting OutFile to true. Test environment settings would be stored into the file so you don't need to set environment variables manually." + } + } -# Try detecting repos that support OutFile and defaulting to it -if (!$CI -and !$PSBoundParameters.ContainsKey('OutFile') -and $IsWindows) { - # TODO: find a better way to detect the language - if (Test-Path "$repositoryRoot/eng/service.proj") { - $OutFile = $true - Log "Detected .NET repository. Defaulting OutFile to true. Test environment settings would be stored into the file so you don't need to set environment variables manually." + # If no location is specified use safe default locations for the given + # environment. If no matching environment is found $Location remains an empty + # string. + if (!$Location) { + $Location = @{ + 'AzureCloud' = 'westus2'; + 'AzureUSGovernment' = 'usgovvirginia'; + 'AzureChinaCloud' = 'chinaeast2'; + 'Dogfood' = 'westus' + }[$Environment] + + Write-Verbose "Location was not set. Using default location for environment: '$Location'" } -} -# If no location is specified use safe default locations for the given -# environment. If no matching environment is found $Location remains an empty -# string. -if (!$Location) { - $Location = @{ - 'AzureCloud' = 'westus2'; - 'AzureUSGovernment' = 'usgovvirginia'; - 'AzureChinaCloud' = 'chinaeast2'; - 'Dogfood' = 'westus' - }[$Environment] - - Write-Verbose "Location was not set. Using default location for environment: '$Location'" -} + if (!$CI) { -if (!$CI) { + # Make sure the user is logged in to create a service principal. + $context = Get-AzContext; + if (!$context) { + Log "You are not logged in; connecting to 'Azure SDK Developer Playground'" + $context = (Connect-AzAccount -Subscription $defaultSubscription).Context + } - # Make sure the user is logged in to create a service principal. - $context = Get-AzContext; - if (!$context) { - Log "You are not logged in; connecting to 'Azure SDK Developer Playground'" - $context = (Connect-AzAccount -Subscription $defaultSubscription).Context - } + # If no test application ID is specified during an interactive session, create a new service principal. + if (!$TestApplicationId) { - # If no test application ID is specified during an interactive session, create a new service principal. - if (!$TestApplicationId) { - Log "TestApplicationId was not specified; creating a new service principal" - $servicePrincipal = New-AzADServicePrincipal -Role Owner + # Cache the created service principal in this session for frequent reuse. + $servicePrincipal = if ($AzureTestPrincipal) { + Log "TestApplicationId was not specified; loading the cached service principal" + $AzureTestPrincipal + } else { + Log "TestApplicationId was not specified; creating a new service principal" + $global:AzureTestPrincipal = New-AzADServicePrincipal -Role Owner - $TestApplicationId = $servicePrincipal.ApplicationId - $TestApplicationSecret = (ConvertFrom-SecureString $servicePrincipal.Secret -AsPlainText); + Log "Created service principal '$AzureTestPrincipal'" + $AzureTestPrincipal + } - # Make sure pre- and post-scripts are passed formerly required arguments. - $PSBoundParameters['TestApplicationId'] = $TestApplicationId - $PSBoundParameters['TestApplicationSecret'] = $TestApplicationSecret + $TestApplicationId = $servicePrincipal.ApplicationId + $TestApplicationSecret = (ConvertFrom-SecureString $servicePrincipal.Secret -AsPlainText); - Log "Created service principal '$TestApplicationId'" - } + # Make sure pre- and post-scripts are passed formerly required arguments. + $PSBoundParameters['TestApplicationId'] = $TestApplicationId + $PSBoundParameters['TestApplicationSecret'] = $TestApplicationSecret + } - if (!$ProvisionerApplicationId) { - $ProvisionerApplicationId = $TestApplicationId - $ProvisionerApplicationSecret = $TestApplicationSecret - $TenantId = $context.Tenant.Id + if (!$ProvisionerApplicationId) { + $ProvisionerApplicationId = $TestApplicationId + $ProvisionerApplicationSecret = $TestApplicationSecret + $TenantId = $context.Tenant.Id + } } -} -# Log in as and run pre- and post-scripts as the provisioner service principal. -if ($ProvisionerApplicationId) { - $null = Disable-AzContextAutosave -Scope Process + # Log in as and run pre- and post-scripts as the provisioner service principal. + if ($ProvisionerApplicationId) { + $null = Disable-AzContextAutosave -Scope Process - Log "Logging into service principal '$ProvisionerApplicationId'" - $provisionerSecret = ConvertTo-SecureString -String $ProvisionerApplicationSecret -AsPlainText -Force - $provisionerCredential = [System.Management.Automation.PSCredential]::new($ProvisionerApplicationId, $provisionerSecret) + Log "Logging into service principal '$ProvisionerApplicationId'" + $provisionerSecret = ConvertTo-SecureString -String $ProvisionerApplicationSecret -AsPlainText -Force + $provisionerCredential = [System.Management.Automation.PSCredential]::new($ProvisionerApplicationId, $provisionerSecret) - # Use the given subscription ID if provided. - $subscriptionArgs = if ($SubscriptionId) { - @{SubscriptionId = $SubscriptionId} - } else { - @{} - } + # Use the given subscription ID if provided. + $subscriptionArgs = if ($SubscriptionId) { + @{SubscriptionId = $SubscriptionId} + } else { + @{} + } - $provisionerAccount = Retry { - Connect-AzAccount -Force:$Force -Tenant $TenantId -Credential $provisionerCredential -ServicePrincipal -Environment $Environment @subscriptionArgs - } + $provisionerAccount = Retry { + Connect-AzAccount -Force:$Force -Tenant $TenantId -Credential $provisionerCredential -ServicePrincipal -Environment $Environment @subscriptionArgs + } - $exitActions += { - Write-Verbose "Logging out of service principal '$($provisionerAccount.Context.Account)'" + $exitActions += { + Write-Verbose "Logging out of service principal '$($provisionerAccount.Context.Account)'" - # Only attempt to disconnect if the -WhatIf flag was not set. Otherwise, this call is not necessary and will fail. - if ($PSCmdlet.ShouldProcess($ProvisionerApplicationId)) { - $null = Disconnect-AzAccount -AzureContext $provisionerAccount.Context + # Only attempt to disconnect if the -WhatIf flag was not set. Otherwise, this call is not necessary and will fail. + if ($PSCmdlet.ShouldProcess($ProvisionerApplicationId)) { + $null = Disconnect-AzAccount -AzureContext $provisionerAccount.Context + } } } -} -# Get test application OID from ID if not already provided. -if ($TestApplicationId -and !$TestApplicationOid) { - $testServicePrincipal = Retry { - Get-AzADServicePrincipal -ApplicationId $TestApplicationId - } + # Get test application OID from ID if not already provided. + if ($TestApplicationId -and !$TestApplicationOid) { + $testServicePrincipal = Retry { + Get-AzADServicePrincipal -ApplicationId $TestApplicationId + } - if ($testServicePrincipal -and $testServicePrincipal.Id) { - $script:TestApplicationOid = $testServicePrincipal.Id + if ($testServicePrincipal -and $testServicePrincipal.Id) { + $script:TestApplicationOid = $testServicePrincipal.Id + } } -} - -# Determine the Azure context that the script is running in. -$context = Get-AzContext; -# If the ServiceDirectory is an absolute path use the last directory name -# (e.g. D:\foo\bar\ -> bar) -$serviceName = if (Split-Path -IsAbsolute $ServiceDirectory) { - Split-Path -Leaf $ServiceDirectory -} else { - $ServiceDirectory -} - -if ($CI) { - $BaseName = 't' + (New-Guid).ToString('n').Substring(0, 16) - Write-Verbose "Generated base name '$BaseName' for CI build" -} - -$ResourceGroupName = if ($ResourceGroupName) { - $ResourceGroupName -} elseif ($CI) { - # Format the resource group name based on resource group naming recommendations and limitations. - "rg-{0}-$BaseName" -f ($serviceName -replace '[\\\/:]', '-').Substring(0, [Math]::Min($serviceName.Length, 90 - $BaseName.Length - 4)).Trim('-') -} else { - "rg-$BaseName" -} + # Determine the Azure context that the script is running in. + $context = Get-AzContext; -# Tag the resource group to be deleted after a certain number of hours if specified. -$tags = @{ - Creator = $UserName - ServiceDirectory = $ServiceDirectory -} + # If the ServiceDirectory is an absolute path use the last directory name + # (e.g. D:\foo\bar\ -> bar) + $serviceName = if (Split-Path -IsAbsolute $ServiceDirectory) { + Split-Path -Leaf $ServiceDirectory + } else { + $ServiceDirectory + } -if ($PSBoundParameters.ContainsKey('DeleteAfterHours')) { - $deleteAfter = [DateTime]::UtcNow.AddHours($DeleteAfterHours) - $tags.Add('DeleteAfter', $deleteAfter.ToString('o')) -} + $ResourceGroupName = if ($ResourceGroupName) { + $ResourceGroupName + } elseif ($CI) { + # Format the resource group name based on resource group naming recommendations and limitations. + "rg-{0}-$BaseName" -f ($serviceName -replace '[\\\/:]', '-').Substring(0, [Math]::Min($serviceName.Length, 90 - $BaseName.Length - 4)).Trim('-') + } else { + "rg-$BaseName" + } -if ($CI) { - # Add tags for the current CI job. - $tags += @{ - BuildId = "${env:BUILD_BUILDID}" - BuildJob = "${env:AGENT_JOBNAME}" - BuildNumber = "${env:BUILD_BUILDNUMBER}" - BuildReason = "${env:BUILD_REASON}" + # Tag the resource group to be deleted after a certain number of hours if specified. + $tags = @{ + Creator = $UserName + ServiceDirectory = $ServiceDirectory } - # Set the resource group name variable. - Write-Host "Setting variable 'AZURE_RESOURCEGROUP_NAME': $ResourceGroupName" - Write-Host "##vso[task.setvariable variable=AZURE_RESOURCEGROUP_NAME;]$ResourceGroupName" - if ($EnvironmentVariables.ContainsKey('AZURE_RESOURCEGROUP_NAME') -and ` - $EnvironmentVariables['AZURE_RESOURCEGROUP_NAME'] -ne $ResourceGroupName) - { - Write-Warning ("Overwriting 'EnvironmentVariables.AZURE_RESOURCEGROUP_NAME' with value " + - "'$($EnvironmentVariables['AZURE_RESOURCEGROUP_NAME'])' " + "to new value '$($ResourceGroupName)'") + if ($PSBoundParameters.ContainsKey('DeleteAfterHours')) { + $deleteAfter = [DateTime]::UtcNow.AddHours($DeleteAfterHours) + $tags.Add('DeleteAfter', $deleteAfter.ToString('o')) } - $EnvironmentVariables['AZURE_RESOURCEGROUP_NAME'] = $ResourceGroupName -} -Log "Creating resource group '$ResourceGroupName' in location '$Location'" -$resourceGroup = Retry { - New-AzResourceGroup -Name "$ResourceGroupName" -Location $Location -Tag $tags -Force:$Force -} + if ($CI) { + # Add tags for the current CI job. + $tags += @{ + BuildId = "${env:BUILD_BUILDID}" + BuildJob = "${env:AGENT_JOBNAME}" + BuildNumber = "${env:BUILD_BUILDNUMBER}" + BuildReason = "${env:BUILD_REASON}" + } -if ($resourceGroup.ProvisioningState -eq 'Succeeded') { - # New-AzResourceGroup would've written an error and stopped the pipeline by default anyway. - Write-Verbose "Successfully created resource group '$($resourceGroup.ResourceGroupName)'" -} -elseif (($resourceGroup -eq $null) -and (-not $PSCmdlet.ShouldProcess($resourceGroupName))) { - # If the -WhatIf flag was passed, there will be no resource group created. Fake it. - $resourceGroup = [PSCustomObject]@{ - ResourceGroupName = $resourceGroupName - Location = $Location + # Set the resource group name variable. + Write-Host "Setting variable 'AZURE_RESOURCEGROUP_NAME': $ResourceGroupName" + Write-Host "##vso[task.setvariable variable=AZURE_RESOURCEGROUP_NAME;]$ResourceGroupName" + if ($EnvironmentVariables.ContainsKey('AZURE_RESOURCEGROUP_NAME') -and ` + $EnvironmentVariables['AZURE_RESOURCEGROUP_NAME'] -ne $ResourceGroupName) + { + Write-Warning ("Overwriting 'EnvironmentVariables.AZURE_RESOURCEGROUP_NAME' with value " + + "'$($EnvironmentVariables['AZURE_RESOURCEGROUP_NAME'])' " + "to new value '$($ResourceGroupName)'") + } + $EnvironmentVariables['AZURE_RESOURCEGROUP_NAME'] = $ResourceGroupName } -} -# Populate the template parameters and merge any additional specified. -$templateParameters = @{ - baseName = $BaseName - testApplicationId = $TestApplicationId - testApplicationOid = "$TestApplicationOid" -} + Log "Creating resource group '$ResourceGroupName' in location '$Location'" + $resourceGroup = Retry { + New-AzResourceGroup -Name "$ResourceGroupName" -Location $Location -Tag $tags -Force:$Force + } -if ($TenantId) { - $templateParameters.Add('tenantId', $TenantId) -} -if ($TestApplicationSecret) { - $templateParameters.Add('testApplicationSecret', $TestApplicationSecret) -} + if ($resourceGroup.ProvisioningState -eq 'Succeeded') { + # New-AzResourceGroup would've written an error and stopped the pipeline by default anyway. + Write-Verbose "Successfully created resource group '$($resourceGroup.ResourceGroupName)'" + } + elseif (!$resourceGroup -and !$PSCmdlet.ShouldProcess($resourceGroupName)) { + # If the -WhatIf flag was passed, there will be no resource group created. Fake it. + $resourceGroup = [PSCustomObject]@{ + ResourceGroupName = $resourceGroupName + Location = $Location + } + } -MergeHashes $ArmTemplateParameters $(Get-Variable templateParameters) -MergeHashes $AdditionalParameters $(Get-Variable templateParameters) + # Populate the template parameters and merge any additional specified. + $templateParameters = @{ + baseName = $BaseName + testApplicationId = $TestApplicationId + testApplicationOid = "$TestApplicationOid" + } -# Include environment-specific parameters only if not already provided as part of the "ArmTemplateParameters" -if (($context.Environment.StorageEndpointSuffix) -and (-not ($templateParameters.ContainsKey('storageEndpointSuffix')))) { - $templateParameters.Add('storageEndpointSuffix', $context.Environment.StorageEndpointSuffix) -} + if ($TenantId) { + $templateParameters.Add('tenantId', $TenantId) + } + if ($TestApplicationSecret) { + $templateParameters.Add('testApplicationSecret', $TestApplicationSecret) + } -# Try to detect the shell based on the parent process name (e.g. launch via shebang). -$shell, $shellExportFormat = if (($parentProcessName = (Get-Process -Id $PID).Parent.ProcessName) -and $parentProcessName -eq 'cmd') { - 'cmd', 'set {0}={1}' -} elseif (@('bash', 'csh', 'tcsh', 'zsh') -contains $parentProcessName) { - 'shell', 'export {0}={1}' -} else { - 'PowerShell', '${{env:{0}}} = ''{1}''' -} + MergeHashes $ArmTemplateParameters $(Get-Variable templateParameters) + MergeHashes $AdditionalParameters $(Get-Variable templateParameters) -# Deploy the templates -foreach ($templateFile in $templateFiles) { - # Deployment fails if we pass in more parameters than are defined. - Write-Verbose "Removing unnecessary parameters from template '$templateFile'" - $templateJson = Get-Content -LiteralPath $templateFile | ConvertFrom-Json - $templateParameterNames = $templateJson.parameters.PSObject.Properties.Name - - $templateFileParameters = $templateParameters.Clone() - foreach ($key in $templateParameters.Keys) { - if ($templateParameterNames -notcontains $key) { - Write-Verbose "Removing unnecessary parameter '$key'" - $templateFileParameters.Remove($key) - } + # Include environment-specific parameters only if not already provided as part of the "ArmTemplateParameters" + if (($context.Environment.StorageEndpointSuffix) -and (-not ($templateParameters.ContainsKey('storageEndpointSuffix')))) { + $templateParameters.Add('storageEndpointSuffix', $context.Environment.StorageEndpointSuffix) } - $preDeploymentScript = $templateFile | Split-Path | Join-Path -ChildPath 'test-resources-pre.ps1' - if (Test-Path $preDeploymentScript) { - Log "Invoking pre-deployment script '$preDeploymentScript'" - &$preDeploymentScript -ResourceGroupName $ResourceGroupName @PSBoundParameters + # Try to detect the shell based on the parent process name (e.g. launch via shebang). + $shell, $shellExportFormat = if (($parentProcessName = (Get-Process -Id $PID).Parent.ProcessName) -and $parentProcessName -eq 'cmd') { + 'cmd', 'set {0}={1}' + } elseif (@('bash', 'csh', 'tcsh', 'zsh') -contains $parentProcessName) { + 'shell', 'export {0}={1}' + } else { + 'PowerShell', '${{env:{0}}} = ''{1}''' } - Log "Deploying template '$templateFile' to resource group '$($resourceGroup.ResourceGroupName)'" - $deployment = Retry { - $lastDebugPreference = $DebugPreference - try { - if ($CI) { - $DebugPreference = "Continue" + # Deploy the templates + foreach ($templateFile in $templateFiles) { + # Deployment fails if we pass in more parameters than are defined. + Write-Verbose "Removing unnecessary parameters from template '$templateFile'" + $templateJson = Get-Content -LiteralPath $templateFile | ConvertFrom-Json + $templateParameterNames = $templateJson.parameters.PSObject.Properties.Name + + $templateFileParameters = $templateParameters.Clone() + foreach ($key in $templateParameters.Keys) { + if ($templateParameterNames -notcontains $key) { + Write-Verbose "Removing unnecessary parameter '$key'" + $templateFileParameters.Remove($key) } - New-AzResourceGroupDeployment -Name $BaseName -ResourceGroupName $resourceGroup.ResourceGroupName -TemplateFile $templateFile -TemplateParameterObject $templateFileParameters - } catch { - Write-Output @" -================================================== -For help debugging live test provisioning issues, -see http://aka.ms/azsdk/engsys/live-test-help, -================================================== + } + + $preDeploymentScript = $templateFile | Split-Path | Join-Path -ChildPath 'test-resources-pre.ps1' + if (Test-Path $preDeploymentScript) { + Log "Invoking pre-deployment script '$preDeploymentScript'" + &$preDeploymentScript -ResourceGroupName $ResourceGroupName @PSBoundParameters + } + + Log "Deploying template '$templateFile' to resource group '$($resourceGroup.ResourceGroupName)'" + $deployment = Retry { + $lastDebugPreference = $DebugPreference + try { + if ($CI) { + $DebugPreference = "Continue" + } + New-AzResourceGroupDeployment -Name $BaseName -ResourceGroupName $resourceGroup.ResourceGroupName -TemplateFile $templateFile -TemplateParameterObject $templateFileParameters + } catch { + Write-Output @" +##################################################### +# For help debugging live test provisioning issues, # +# see http://aka.ms/azsdk/engsys/live-test-help, # +##################################################### "@ - throw - } finally { - $DebugPreference = $lastDebugPreference + throw + } finally { + $DebugPreference = $lastDebugPreference + } } - } - if ($deployment.ProvisioningState -eq 'Succeeded') { - # New-AzResourceGroupDeployment would've written an error and stopped the pipeline by default anyway. - Write-Verbose "Successfully deployed template '$templateFile' to resource group '$($resourceGroup.ResourceGroupName)'" - } + if ($deployment.ProvisioningState -eq 'Succeeded') { + # New-AzResourceGroupDeployment would've written an error and stopped the pipeline by default anyway. + Write-Verbose "Successfully deployed template '$templateFile' to resource group '$($resourceGroup.ResourceGroupName)'" + } - $serviceDirectoryPrefix = $serviceName.ToUpperInvariant() + "_" - - # Add default values - $deploymentOutputs = @{ - "$($serviceDirectoryPrefix)CLIENT_ID" = $TestApplicationId; - "$($serviceDirectoryPrefix)CLIENT_SECRET" = $TestApplicationSecret; - "$($serviceDirectoryPrefix)TENANT_ID" = $context.Tenant.Id; - "$($serviceDirectoryPrefix)SUBSCRIPTION_ID" = $context.Subscription.Id; - "$($serviceDirectoryPrefix)RESOURCE_GROUP" = $resourceGroup.ResourceGroupName; - "$($serviceDirectoryPrefix)LOCATION" = $resourceGroup.Location; - "$($serviceDirectoryPrefix)ENVIRONMENT" = $context.Environment.Name; - "$($serviceDirectoryPrefix)AZURE_AUTHORITY_HOST" = $context.Environment.ActiveDirectoryAuthority; - "$($serviceDirectoryPrefix)RESOURCE_MANAGER_URL" = $context.Environment.ResourceManagerUrl; - "$($serviceDirectoryPrefix)SERVICE_MANAGEMENT_URL" = $context.Environment.ServiceManagementUrl; - "$($serviceDirectoryPrefix)STORAGE_ENDPOINT_SUFFIX" = $context.Environment.StorageEndpointSuffix; - } + $serviceDirectoryPrefix = $serviceName.ToUpperInvariant() + "_" + + # Add default values + $deploymentOutputs = @{ + "$($serviceDirectoryPrefix)CLIENT_ID" = $TestApplicationId; + "$($serviceDirectoryPrefix)CLIENT_SECRET" = $TestApplicationSecret; + "$($serviceDirectoryPrefix)TENANT_ID" = $context.Tenant.Id; + "$($serviceDirectoryPrefix)SUBSCRIPTION_ID" = $context.Subscription.Id; + "$($serviceDirectoryPrefix)RESOURCE_GROUP" = $resourceGroup.ResourceGroupName; + "$($serviceDirectoryPrefix)LOCATION" = $resourceGroup.Location; + "$($serviceDirectoryPrefix)ENVIRONMENT" = $context.Environment.Name; + "$($serviceDirectoryPrefix)AZURE_AUTHORITY_HOST" = $context.Environment.ActiveDirectoryAuthority; + "$($serviceDirectoryPrefix)RESOURCE_MANAGER_URL" = $context.Environment.ResourceManagerUrl; + "$($serviceDirectoryPrefix)SERVICE_MANAGEMENT_URL" = $context.Environment.ServiceManagementUrl; + "$($serviceDirectoryPrefix)STORAGE_ENDPOINT_SUFFIX" = $context.Environment.StorageEndpointSuffix; + } - MergeHashes $EnvironmentVariables $(Get-Variable deploymentOutputs) + MergeHashes $EnvironmentVariables $(Get-Variable deploymentOutputs) - foreach ($key in $deployment.Outputs.Keys) { - $variable = $deployment.Outputs[$key] + foreach ($key in $deployment.Outputs.Keys) { + $variable = $deployment.Outputs[$key] - # Work around bug that makes the first few characters of environment variables be lowercase. - $key = $key.ToUpperInvariant() + # Work around bug that makes the first few characters of environment variables be lowercase. + $key = $key.ToUpperInvariant() - if ($variable.Type -eq 'String' -or $variable.Type -eq 'SecureString') { - $deploymentOutputs[$key] = $variable.Value + if ($variable.Type -eq 'String' -or $variable.Type -eq 'SecureString') { + $deploymentOutputs[$key] = $variable.Value + } } - } - if ($OutFile) { - if (!$IsWindows) { - Write-Host "File option is supported only on Windows" - } + if ($OutFile) { + if (!$IsWindows) { + Write-Host "File option is supported only on Windows" + } - $outputFile = "$templateFile.env" + $outputFile = "$templateFile.env" - $environmentText = $deploymentOutputs | ConvertTo-Json; - $bytes = ([System.Text.Encoding]::UTF8).GetBytes($environmentText) - $protectedBytes = [Security.Cryptography.ProtectedData]::Protect($bytes, $null, [Security.Cryptography.DataProtectionScope]::CurrentUser) + $environmentText = $deploymentOutputs | ConvertTo-Json; + $bytes = ([System.Text.Encoding]::UTF8).GetBytes($environmentText) + $protectedBytes = [Security.Cryptography.ProtectedData]::Protect($bytes, $null, [Security.Cryptography.DataProtectionScope]::CurrentUser) - Set-Content $outputFile -Value $protectedBytes -AsByteStream -Force + Set-Content $outputFile -Value $protectedBytes -AsByteStream -Force - Write-Host "Test environment settings`n $environmentText`nstored into encrypted $outputFile" - } else { + Write-Host "Test environment settings`n $environmentText`nstored into encrypted $outputFile" + } else { - if (!$CI) { - # Write an extra new line to isolate the environment variables for easy reading. - Log "Persist the following environment variables based on your detected shell ($shell):`n" - } + if (!$CI) { + # Write an extra new line to isolate the environment variables for easy reading. + Log "Persist the following environment variables based on your detected shell ($shell):`n" + } - foreach ($key in $deploymentOutputs.Keys) { - $value = $deploymentOutputs[$key] - $EnvironmentVariables[$key] = $value + foreach ($key in $deploymentOutputs.Keys) { + $value = $deploymentOutputs[$key] + $EnvironmentVariables[$key] = $value + + if ($CI) { + # Treat all ARM template output variables as secrets since "SecureString" variables do not set values. + # In order to mask secrets but set environment variables for any given ARM template, we set variables twice as shown below. + Write-Host "Setting variable '$key': ***" + Write-Host "##vso[task.setvariable variable=_$key;issecret=true;]$($value)" + Write-Host "##vso[task.setvariable variable=$key;]$($value)" + } else { + Write-Host ($shellExportFormat -f $key, $value) + } + } - if ($CI) { - # Treat all ARM template output variables as secrets since "SecureString" variables do not set values. - # In order to mask secrets but set environment variables for any given ARM template, we set variables twice as shown below. - Write-Host "Setting variable '$key': ***" - Write-Host "##vso[task.setvariable variable=_$key;issecret=true;]$($value)" - Write-Host "##vso[task.setvariable variable=$key;]$($value)" - } else { - Write-Host ($shellExportFormat -f $key, $value) + if ($key) { + # Isolate the environment variables for easy reading. + Write-Host "`n" + $key = $null } } - if ($key) { - # Isolate the environment variables for easy reading. - Write-Host "`n" - $key = $null + $postDeploymentScript = $templateFile | Split-Path | Join-Path -ChildPath 'test-resources-post.ps1' + if (Test-Path $postDeploymentScript) { + Log "Invoking post-deployment script '$postDeploymentScript'" + &$postDeploymentScript -ResourceGroupName $ResourceGroupName -DeploymentOutputs $deploymentOutputs @PSBoundParameters } } - $postDeploymentScript = $templateFile | Split-Path | Join-Path -ChildPath 'test-resources-post.ps1' - if (Test-Path $postDeploymentScript) { - Log "Invoking post-deployment script '$postDeploymentScript'" - &$postDeploymentScript -ResourceGroupName $ResourceGroupName -DeploymentOutputs $deploymentOutputs @PSBoundParameters - } +} finally { + $exitActions.Invoke() } -$exitActions.Invoke() - # Suppress output locally if ($CI) { return $EnvironmentVariables @@ -634,12 +647,7 @@ The environment file would be scoped to the current repository directory. .EXAMPLE Connect-AzAccount -Subscription "REPLACE_WITH_SUBSCRIPTION_ID" -$testAadApp = New-AzADServicePrincipal -Role Owner -DisplayName 'azure-sdk-live-test-app' -New-TestResources.ps1 ` - -BaseName 'uuid123' ` - -ServiceDirectory 'keyvault' ` - -TestApplicationId $testAadApp.ApplicationId.ToString() ` - -TestApplicationSecret (ConvertFrom-SecureString $testAadApp.Secret -AsPlainText) +New-TestResources.ps1 -ServiceDirectory 'keyvault' Run this in a desktop environment to create new AAD apps and Service Principals that can be used to provision resources and run live tests. diff --git a/eng/common/TestResources/New-TestResources.ps1.md b/eng/common/TestResources/New-TestResources.ps1.md index 515a51bd373cd..096c7e70aa37e 100644 --- a/eng/common/TestResources/New-TestResources.ps1.md +++ b/eng/common/TestResources/New-TestResources.ps1.md @@ -56,12 +56,7 @@ specified in $ProvisionerApplicationId and $ProvisionerApplicationSecret. ### EXAMPLE 1 ``` Connect-AzAccount -Subscription "REPLACE_WITH_SUBSCRIPTION_ID" -$testAadApp = New-AzADServicePrincipal -Role Owner -DisplayName 'azure-sdk-live-test-app' -New-TestResources.ps1 ` - -BaseName 'uuid123' ` - -ServiceDirectory 'keyvault' ` - -TestApplicationId $testAadApp.ApplicationId.ToString() ` - -TestApplicationSecret (ConvertFrom-SecureString $testAadApp.Secret -AsPlainText) +New-TestResources.ps1 -ServiceDirectory 'keyvault' ``` Run this in a desktop environment to create new AAD apps and Service Principals diff --git a/eng/common/scripts/ChangeLog-Operations.ps1 b/eng/common/scripts/ChangeLog-Operations.ps1 index d644d022658aa..43dba5d74e6fb 100644 --- a/eng/common/scripts/ChangeLog-Operations.ps1 +++ b/eng/common/scripts/ChangeLog-Operations.ps1 @@ -1,6 +1,10 @@ # Common Changelog Operations +. "${PSScriptRoot}\logging.ps1" +. "${PSScriptRoot}\SemVer.ps1" -$RELEASE_TITLE_REGEX = "(?^\#+.*(?\b\d+\.\d+\.\d+([^0-9\s][^\s:]+)?)(\s(?\(Unreleased\)|\(\d{4}-\d{2}-\d{2}\)))?)" +$RELEASE_TITLE_REGEX = "(?^\#+.*(?\b\d+\.\d+\.\d+([^0-9\s][^\s:]+)?)(\s+(?\(Unreleased\)|\(\d{4}-\d{2}-\d{2}\)))?)" +$CHANGELOG_UNRELEASED_STATUS = "(Unreleased)" +$CHANGELOG_DATE_FORMAT = "yyyy-MM-dd" # Returns a Collection of changeLogEntry object containing changelog info for all version present in the gived CHANGELOG function Get-ChangeLogEntries { @@ -11,7 +15,7 @@ function Get-ChangeLogEntries { $changeLogEntries = @{} if (!(Test-Path $ChangeLogLocation)) { - Write-Error "ChangeLog[${ChangeLogLocation}] does not exist" + LogError "ChangeLog[${ChangeLogLocation}] does not exist" return $null } @@ -23,9 +27,9 @@ function Get-ChangeLogEntries { if ($line -match $RELEASE_TITLE_REGEX) { $changeLogEntry = [pscustomobject]@{ ReleaseVersion = $matches["version"] - ReleaseStatus = $matches["releaseStatus"] - ReleaseTitle = $line - ReleaseContent = @() # Release content without the version title + ReleaseStatus = $matches["releaseStatus"] + ReleaseTitle = "## {0} {1}" -f $matches["version"], $matches["releaseStatus"] + ReleaseContent = @() } $changeLogEntries[$changeLogEntry.ReleaseVersion] = $changeLogEntry } @@ -72,6 +76,7 @@ function Get-ChangeLogEntryAsString { return ChangeLogEntryAsString $changeLogEntry } + function ChangeLogEntryAsString($changeLogEntry) { if (!$changeLogEntry) { return "[Missing change log entry]" @@ -93,7 +98,7 @@ function Confirm-ChangeLogEntry { $changeLogEntry = Get-ChangeLogEntry -ChangeLogLocation $ChangeLogLocation -VersionString $VersionString if (!$changeLogEntry) { - Write-Error "ChangeLog[${ChangeLogLocation}] does not have an entry for version ${VersionString}." + LogError "ChangeLog[${ChangeLogLocation}] does not have an entry for version ${VersionString}." return $false } @@ -103,28 +108,108 @@ function Confirm-ChangeLogEntry { Write-Host "-----" if ([System.String]::IsNullOrEmpty($changeLogEntry.ReleaseStatus)) { - Write-Error "Entry does not have a correct release status. Please ensure the status is set to a date '(yyyy-MM-dd)' or '(Unreleased)' if not yet released." + LogError "Entry does not have a correct release status. Please ensure the status is set to a date '($CHANGELOG_DATE_FORMAT)' or '$CHANGELOG_UNRELEASED_STATUS' if not yet released." return $false } if ($ForRelease -eq $True) { - if ($changeLogEntry.ReleaseStatus -eq "(Unreleased)") { - Write-Error "Entry has no release date set. Please ensure to set a release date with format 'yyyy-MM-dd'." + if ($changeLogEntry.ReleaseStatus -eq $CHANGELOG_UNRELEASED_STATUS) { + LogError "Entry has no release date set. Please ensure to set a release date with format '$CHANGELOG_DATE_FORMAT'." return $false } + else { + $status = $changeLogEntry.ReleaseStatus.Trim().Trim("()") + try { + [DateTime]$status + } + catch { + LogError "Invalid date [ $status ] passed as status for Version [$($changeLogEntry.ReleaseVersion)]." + return $false + } + } if ([System.String]::IsNullOrWhiteSpace($changeLogEntry.ReleaseContent)) { - Write-Error "Entry has no content. Please ensure to provide some content of what changed in this version." + LogError "Entry has no content. Please ensure to provide some content of what changed in this version." return $false } } return $true } -function Set-TestChangeLog($TestVersion, $changeLogFile, $ReleaseEntry) { - Set-Content -Path $changeLogFile -Value @" -# Release History -## $TestVersion ($(Get-Date -f "yyyy-MM-dd")) -- $ReleaseEntry -"@ +function New-ChangeLogEntry { + param ( + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [String]$Version, + [String]$Status=$CHANGELOG_UNRELEASED_STATUS, + [String[]]$Content + ) + + # Validate RelaseStatus + $Status = $Status.Trim().Trim("()") + if ($Status -ne "Unreleased") { + try { + $Status = ([DateTime]$Status).ToString($CHANGELOG_DATE_FORMAT) + } + catch { + LogWarning "Invalid date [ $Status ] passed as status for Version [$Version]. Please use a valid date in the format '$CHANGELOG_DATE_FORMAT' or use '$CHANGELOG_UNRELEASED_STATUS'" + return $null + } + } + $Status = "($Status)" + + # Validate Version + try { + $Version = ([AzureEngSemanticVersion]::ParseVersionString($Version)).ToString() + } + catch { + LogWarning "Invalid version [ $Version ]." + return $null + } + + if (!$Content) { $Content = @() } + + $newChangeLogEntry = [pscustomobject]@{ + ReleaseVersion = $Version + ReleaseStatus = $Status + ReleaseTitle = "## $Version $Status" + ReleaseContent = $Content + } + + return $newChangeLogEntry +} + +function Set-ChangeLogContent { + param ( + [Parameter(Mandatory = $true)] + [String]$ChangeLogLocation, + [Parameter(Mandatory = $true)] + $ChangeLogEntries + ) + + $changeLogContent = @() + $changeLogContent += "# Release History" + $changeLogContent += "" + + try + { + $VersionsSorted = [AzureEngSemanticVersion]::SortVersionStrings($ChangeLogEntries.Keys) + } + catch { + LogError "Problem sorting version in ChangeLogEntries" + return + } + + foreach ($version in $VersionsSorted) { + $changeLogEntry = $ChangeLogEntries[$version] + $changeLogContent += $changeLogEntry.ReleaseTitle + if ($changeLogEntry.ReleaseContent.Count -eq 0) { + $changeLogContent += @("","") + } + else { + $changeLogContent += $changeLogEntry.ReleaseContent + } + } + + Set-Content -Path $ChangeLogLocation -Value $changeLogContent } \ No newline at end of file diff --git a/eng/common/scripts/Package-Properties.ps1 b/eng/common/scripts/Package-Properties.ps1 index f17b244f3f220..d75b897f28c63 100644 --- a/eng/common/scripts/Package-Properties.ps1 +++ b/eng/common/scripts/Package-Properties.ps1 @@ -1,4 +1,6 @@ # Helper functions for retireving useful information from azure-sdk-for-* repo +. "${PSScriptRoot}\logging.ps1" + class PackageProps { [string]$Name @@ -81,7 +83,7 @@ function Get-PkgProperties $serviceDirectoryPath = Join-Path $RepoRoot "sdk" $ServiceDirectory if (!(Test-Path $serviceDirectoryPath)) { - Write-Error "Service Directory $ServiceDirectory does not exist" + LogError "Service Directory $ServiceDirectory does not exist" exit 1 } @@ -97,7 +99,7 @@ function Get-PkgProperties } else { - Write-Error "The function '$GetPackageInfoFromRepoFn' was not found." + LogError "The function '$GetPackageInfoFromRepoFn' was not found." } if ($pkgProps -ne $null) @@ -105,7 +107,7 @@ function Get-PkgProperties return $pkgProps } } - Write-Error "Failed to retrive Properties for $PackageName" + LogError "Failed to retrive Properties for $PackageName" } # Takes ServiceName and Repo Root Directory @@ -175,7 +177,7 @@ function Get-PkgListFromYml ($ciYmlPath) } if ($artifactsInCI -eq $null) { - Write-Error "Failed to retrive package names in ci $ciYmlPath" + LogError "Failed to retrive package names in ci $ciYmlPath" } return $artifactsInCI } \ No newline at end of file diff --git a/eng/common/scripts/SemVer.ps1 b/eng/common/scripts/SemVer.ps1 index 0efdfae9cd425..ab4eef38052b5 100644 --- a/eng/common/scripts/SemVer.ps1 +++ b/eng/common/scripts/SemVer.ps1 @@ -22,8 +22,10 @@ class AzureEngSemanticVersion { [string] $RawVersion [bool] $IsSemVerFormat [string] $DefaultPrereleaseLabel + # Regex inspired but simplified from https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string static [string] $SEMVER_REGEX = "(?0|[1-9]\d*)\.(?0|[1-9]\d*)\.(?0|[1-9]\d*)(?:(?-?)(?[a-zA-Z-]*)(?\.?)(?0|[1-9]\d*))?" + static [string] $ParseLanguage = $Language static [AzureEngSemanticVersion] ParseVersionString([string] $versionString) { @@ -57,7 +59,12 @@ class AzureEngSemanticVersion { $this.Minor = [int]$matches.Minor $this.Patch = [int]$matches.Patch - $this.SetupDefaultConventions() + if ([AzureEngSemanticVersion]::ParseLanguage -eq "python") { + $this.SetupPythonConventions() + } + else { + $this.SetupDefaultConventions() + } if ($null -eq $matches['prelabel']) { diff --git a/eng/scripts/Language-Settings.ps1 b/eng/scripts/Language-Settings.ps1 index 19f906ece0dcb..bbe44b0b8894c 100644 --- a/eng/scripts/Language-Settings.ps1 +++ b/eng/scripts/Language-Settings.ps1 @@ -3,6 +3,8 @@ $PackageRepository = "Maven" $packagePattern = "*.pom" $MetadataUri = "https://raw.githubusercontent.com/Azure/azure-sdk/master/_data/releases/latest/java-packages.csv" $BlobStorageUrl = "https://azuresdkdocs.blob.core.windows.net/%24web?restype=container&comp=list&prefix=java%2F&delimiter=%2F" +$IndexHtmlLoc = "index.html" +$AppTitle = "Azure SDK for Java" function Get-java-PackageInfoFromRepo ($pkgPath, $serviceDirectory, $pkgName) { @@ -156,6 +158,7 @@ function Publish-java-GithubIODocs ($DocLocation, $PublicArtifactLocation) } function Get-java-GithubIoDocIndex() { + Mutate-Files -appTitle $AppTitle -lang $Language -indexhtmlloc $IndexHtmlLoc # Fetch out all package metadata from csv file. $metadata = Get-CSVMetadata -MetadataUri $MetadataUri # Leave the track 2 packages if multiple packages fetched out. From 2c95b4d200bde7331285f26312e2e6a8549876c4 Mon Sep 17 00:00:00 2001 From: Sima Zhu Date: Fri, 20 Nov 2020 09:27:39 -0800 Subject: [PATCH 2/9] Added some comments --- eng/scripts/Language-Settings.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/eng/scripts/Language-Settings.ps1 b/eng/scripts/Language-Settings.ps1 index 3087687bb8b1b..81dc68d886ead 100644 --- a/eng/scripts/Language-Settings.ps1 +++ b/eng/scripts/Language-Settings.ps1 @@ -159,6 +159,7 @@ function Publish-java-GithubIODocs ($DocLocation, $PublicArtifactLocation) } function Get-java-GithubIoDocIndex() { + # Fill in language specific information using script. Mutate-Files -appTitle $AppTitle -lang $Language -indexhtmlloc $IndexHtmlLoc # Fetch out all package metadata from csv file. $metadata = Get-CSVMetadata -MetadataUri $MetadataUri From 85b5cde73149553c813c9aa48d6ac8e3f33e1be3 Mon Sep 17 00:00:00 2001 From: Sima Zhu Date: Fri, 20 Nov 2020 09:30:36 -0800 Subject: [PATCH 3/9] Remove the global var --- eng/common/pipelines/templates/steps/docindex.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/eng/common/pipelines/templates/steps/docindex.yml b/eng/common/pipelines/templates/steps/docindex.yml index 002c009bc6a3d..1e0cd6f484dd7 100644 --- a/eng/common/pipelines/templates/steps/docindex.yml +++ b/eng/common/pipelines/templates/steps/docindex.yml @@ -1,7 +1,5 @@ jobs: - job: CreateDocIndex - variables: - - template: templates/variables/globals.yml pool: vmImage: windows-2019 steps: From ad91c510ff781bf6f22ee2fd5cb0055b78319ad1 Mon Sep 17 00:00:00 2001 From: Sima Zhu Date: Fri, 20 Nov 2020 10:12:11 -0800 Subject: [PATCH 4/9] More changes to yml --- eng/common/pipelines/templates/steps/docindex.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/eng/common/pipelines/templates/steps/docindex.yml b/eng/common/pipelines/templates/steps/docindex.yml index 1e0cd6f484dd7..099597776cf8c 100644 --- a/eng/common/pipelines/templates/steps/docindex.yml +++ b/eng/common/pipelines/templates/steps/docindex.yml @@ -47,6 +47,7 @@ jobs: targetPath: $(Build.ArtifactStagingDirectory)/docfx_project/_site - pwsh: | + git commit -am "Save the language updates." git checkout -b gh-pages-local --track origin/gh-pages-root workingDirectory: $(Build.SourcesDirectory) displayName: Git pull GH pages branch From 39debc46741cf80675a6112edfe7411d3e2fc5b1 Mon Sep 17 00:00:00 2001 From: Sima Zhu Date: Fri, 20 Nov 2020 10:35:38 -0800 Subject: [PATCH 5/9] Added name and email info --- eng/common/pipelines/templates/steps/docindex.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/pipelines/templates/steps/docindex.yml b/eng/common/pipelines/templates/steps/docindex.yml index 099597776cf8c..38462c45435e8 100644 --- a/eng/common/pipelines/templates/steps/docindex.yml +++ b/eng/common/pipelines/templates/steps/docindex.yml @@ -47,7 +47,7 @@ jobs: targetPath: $(Build.ArtifactStagingDirectory)/docfx_project/_site - pwsh: | - git commit -am "Save the language updates." + git -c user.name=`"azure-sdk`" -c user.email=`"azuresdk@microsoft.com`" commit -am "Save the language updates." git checkout -b gh-pages-local --track origin/gh-pages-root workingDirectory: $(Build.SourcesDirectory) displayName: Git pull GH pages branch From af42ec82e22d98076342121415b4f40e5a5e2654 Mon Sep 17 00:00:00 2001 From: Sima Zhu Date: Fri, 20 Nov 2020 11:48:37 -0800 Subject: [PATCH 6/9] new changes --- eng/common/docgeneration/Generate-DocIndex.ps1 | 2 +- eng/common/pipelines/templates/steps/docindex.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/common/docgeneration/Generate-DocIndex.ps1 b/eng/common/docgeneration/Generate-DocIndex.ps1 index 84fd562715508..e2691e604f071 100644 --- a/eng/common/docgeneration/Generate-DocIndex.ps1 +++ b/eng/common/docgeneration/Generate-DocIndex.ps1 @@ -162,7 +162,7 @@ function GenerateDocfxTocContent([Hashtable]$tocContent, [String]$lang) { Copy-Item "${DocGenDir}/assets/logo.svg" -Destination "${DocOutDir}/_site/" -Force } -function Mutate-Files { +function UpdateDocIndexFiles { Param ( [Parameter(Mandatory=$true)] [String]$appTitle, [Parameter(Mandatory=$true)] [String]$lang, diff --git a/eng/common/pipelines/templates/steps/docindex.yml b/eng/common/pipelines/templates/steps/docindex.yml index 38462c45435e8..c5c54af0c431e 100644 --- a/eng/common/pipelines/templates/steps/docindex.yml +++ b/eng/common/pipelines/templates/steps/docindex.yml @@ -47,7 +47,7 @@ jobs: targetPath: $(Build.ArtifactStagingDirectory)/docfx_project/_site - pwsh: | - git -c user.name=`"azure-sdk`" -c user.email=`"azuresdk@microsoft.com`" commit -am "Save the language updates." + git reset --hard HEAD git checkout -b gh-pages-local --track origin/gh-pages-root workingDirectory: $(Build.SourcesDirectory) displayName: Git pull GH pages branch From 577cd6ae1658be472cb4298f127a95d09b71568b Mon Sep 17 00:00:00 2001 From: Sima Zhu Date: Fri, 20 Nov 2020 11:53:34 -0800 Subject: [PATCH 7/9] force git checkout --- eng/common/pipelines/templates/steps/docindex.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/eng/common/pipelines/templates/steps/docindex.yml b/eng/common/pipelines/templates/steps/docindex.yml index c5c54af0c431e..488c835a82894 100644 --- a/eng/common/pipelines/templates/steps/docindex.yml +++ b/eng/common/pipelines/templates/steps/docindex.yml @@ -47,8 +47,7 @@ jobs: targetPath: $(Build.ArtifactStagingDirectory)/docfx_project/_site - pwsh: | - git reset --hard HEAD - git checkout -b gh-pages-local --track origin/gh-pages-root + git checkout -b gh-pages-local --track origin/gh-pages-root -f workingDirectory: $(Build.SourcesDirectory) displayName: Git pull GH pages branch From 612de9e95aea81f5db1b0000931fe045838c7322 Mon Sep 17 00:00:00 2001 From: Sima Zhu Date: Fri, 20 Nov 2020 12:05:21 -0800 Subject: [PATCH 8/9] change fucntion nme --- eng/scripts/Language-Settings.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/scripts/Language-Settings.ps1 b/eng/scripts/Language-Settings.ps1 index 81dc68d886ead..b9bd26b5d04bb 100644 --- a/eng/scripts/Language-Settings.ps1 +++ b/eng/scripts/Language-Settings.ps1 @@ -160,7 +160,7 @@ function Publish-java-GithubIODocs ($DocLocation, $PublicArtifactLocation) function Get-java-GithubIoDocIndex() { # Fill in language specific information using script. - Mutate-Files -appTitle $AppTitle -lang $Language -indexhtmlloc $IndexHtmlLoc + UpdateDocIndexFiles -appTitle $AppTitle -lang $Language -indexhtmlloc $IndexHtmlLoc # Fetch out all package metadata from csv file. $metadata = Get-CSVMetadata -MetadataUri $MetadataUri # Leave the track 2 packages if multiple packages fetched out. From 00bbbc6ca418ccefd3435492d0e34a0f9bf88ef1 Mon Sep 17 00:00:00 2001 From: Sima Zhu Date: Fri, 20 Nov 2020 15:31:42 -0800 Subject: [PATCH 9/9] testing on new params --- eng/common/docgeneration/Generate-DocIndex.ps1 | 8 ++++---- eng/scripts/Language-Settings.ps1 | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/eng/common/docgeneration/Generate-DocIndex.ps1 b/eng/common/docgeneration/Generate-DocIndex.ps1 index e2691e604f071..55b639cd54f0c 100644 --- a/eng/common/docgeneration/Generate-DocIndex.ps1 +++ b/eng/common/docgeneration/Generate-DocIndex.ps1 @@ -119,7 +119,7 @@ function GenerateDocfxTocContent([Hashtable]$tocContent, [String]$lang) { New-Item -Path $YmlPath -Name "toc.yml" -Force $visitedService = @{} # Sort and display toc service name by alphabetical order, and then sort artifact by order. - foreach ($serviceMapping in ($tocContent.GetEnumerator() | Sort-Object Value[0], Key)) { + foreach ($serviceMapping in ($tocContent.GetEnumerator() | Sort-Object Value, Key)) { $artifact = $serviceMapping.Key $serviceName = $serviceMapping.Value[0] $displayName = $serviceMapping.Value[1] @@ -164,7 +164,7 @@ function GenerateDocfxTocContent([Hashtable]$tocContent, [String]$lang) { function UpdateDocIndexFiles { Param ( - [Parameter(Mandatory=$true)] [String]$appTitle, + [Parameter(Mandatory=$true)] [String]$appTitleLang, [Parameter(Mandatory=$true)] [String]$lang, [Parameter(Mandatory=$true)] [String]$indexhtmlloc, [Parameter(Mandatory=$false)] [String]$packageRegex = "`"`"", @@ -172,8 +172,8 @@ function UpdateDocIndexFiles { ) # Update docfx.json $docfxContent = Get-Content -Path $DocfxJsonPath -Raw - $docfxContent = $docfxContent -replace "`"_appTitle`": `"`"", "`"_appTitle`": `"$appTitle`"" - $docfxContent = $docfxContent -replace "`"_appFooter`": `"`"", "`"_appFooter`": `"$appTitle`"" + $docfxContent = $docfxContent -replace "`"_appTitle`": `"`"", "`"_appTitle`": `"Azure SDK for $appTitleLang`"" + $docfxContent = $docfxContent -replace "`"_appFooter`": `"`"", "`"_appFooter`": `"Azure SDK for $appTitleLang`"" Set-Content -Path $DocfxJsonPath -Value $docfxContent # Update main.js var lang $mainJsContent = Get-Content -Path $MainJsPath -Raw diff --git a/eng/scripts/Language-Settings.ps1 b/eng/scripts/Language-Settings.ps1 index b9bd26b5d04bb..161de2c528d96 100644 --- a/eng/scripts/Language-Settings.ps1 +++ b/eng/scripts/Language-Settings.ps1 @@ -4,7 +4,7 @@ $packagePattern = "*.pom" $MetadataUri = "https://raw.githubusercontent.com/Azure/azure-sdk/master/_data/releases/latest/java-packages.csv" $BlobStorageUrl = "https://azuresdkdocs.blob.core.windows.net/%24web?restype=container&comp=list&prefix=java%2F&delimiter=%2F" $IndexHtmlLoc = "index.html" -$AppTitle = "Azure SDK for Java" +$AppTitleLang = "Java" function Get-java-PackageInfoFromRepo ($pkgPath, $serviceDirectory, $pkgName) { @@ -160,7 +160,7 @@ function Publish-java-GithubIODocs ($DocLocation, $PublicArtifactLocation) function Get-java-GithubIoDocIndex() { # Fill in language specific information using script. - UpdateDocIndexFiles -appTitle $AppTitle -lang $Language -indexhtmlloc $IndexHtmlLoc + UpdateDocIndexFiles -appTitleLang $AppTitleLang -lang $Language -indexhtmlloc $IndexHtmlLoc # Fetch out all package metadata from csv file. $metadata = Get-CSVMetadata -MetadataUri $MetadataUri # Leave the track 2 packages if multiple packages fetched out.