From 9021e0a8ed50e719d7473616794e312cf44d9de3 Mon Sep 17 00:00:00 2001 From: azure-sdk Date: Thu, 1 Oct 2020 17:57:23 +0000 Subject: [PATCH] Sync eng/common directory with azure-sdk-tools repository for Tools PR 1031 --- .../TestResources/New-TestResources.ps1 | 4 +- .../TestResources/New-TestResources.ps1.md | 1 + .../TestResources/Remove-TestResources.ps1 | 2 +- .../TestResources/deploy-test-resources.yml | 4 +- eng/common/TestResources/setup-az-modules.yml | 36 +++++++++++ eng/common/scripts/New-ReleaseAsset.ps1 | 62 +++++++++++++++++++ 6 files changed, 104 insertions(+), 5 deletions(-) create mode 100644 eng/common/TestResources/setup-az-modules.yml create mode 100644 eng/common/scripts/New-ReleaseAsset.ps1 diff --git a/eng/common/TestResources/New-TestResources.ps1 b/eng/common/TestResources/New-TestResources.ps1 index 0552f9dd5e..59aab61fe7 100644 --- a/eng/common/TestResources/New-TestResources.ps1 +++ b/eng/common/TestResources/New-TestResources.ps1 @@ -55,7 +55,7 @@ param ( [string] $Location = '', [Parameter()] - [ValidateSet('AzureCloud', 'AzureUSGovernment', 'AzureChinaCloud')] + [ValidateSet('AzureCloud', 'AzureUSGovernment', 'AzureChinaCloud', 'Dogfood')] [string] $Environment = 'AzureCloud', [Parameter()] @@ -141,6 +141,7 @@ if (!$Location) { 'AzureCloud' = 'westus2'; 'AzureUSGovernment' = 'usgovvirginia'; 'AzureChinaCloud' = 'chinaeast2'; + 'Dogfood' = 'westus' }[$Environment] Write-Verbose "Location was not set. Using default location for environment: '$Location'" @@ -512,6 +513,7 @@ is based on the cloud to which the template is being deployed: * AzureCloud -> 'westus2' * AzureUSGovernment -> 'usgovvirginia' * AzureChinaCloud -> 'chinaeast2' +* Dogfood -> 'westus' .PARAMETER Environment Name of the cloud environment. The default is the Azure Public Cloud diff --git a/eng/common/TestResources/New-TestResources.ps1.md b/eng/common/TestResources/New-TestResources.ps1.md index 579def9a1d..aab44b896d 100644 --- a/eng/common/TestResources/New-TestResources.ps1.md +++ b/eng/common/TestResources/New-TestResources.ps1.md @@ -322,6 +322,7 @@ is based on the cloud to which the template is being deployed: * AzureCloud -\> 'westus2' * AzureUSGovernment -\> 'usgovvirginia' * AzureChinaCloud -\> 'chinaeast2' +* Dogfood -\> 'westus' ```yaml Type: String diff --git a/eng/common/TestResources/Remove-TestResources.ps1 b/eng/common/TestResources/Remove-TestResources.ps1 index 0c5c464bc8..37f3f5851c 100644 --- a/eng/common/TestResources/Remove-TestResources.ps1 +++ b/eng/common/TestResources/Remove-TestResources.ps1 @@ -43,7 +43,7 @@ param ( [string] $ServiceDirectory, [Parameter()] - [ValidateSet('AzureCloud', 'AzureUSGovernment', 'AzureChinaCloud')] + [ValidateSet('AzureCloud', 'AzureUSGovernment', 'AzureChinaCloud', 'Dogfood')] [string] $Environment = 'AzureCloud', [Parameter()] diff --git a/eng/common/TestResources/deploy-test-resources.yml b/eng/common/TestResources/deploy-test-resources.yml index 4987fb43d1..7f6b6daac9 100644 --- a/eng/common/TestResources/deploy-test-resources.yml +++ b/eng/common/TestResources/deploy-test-resources.yml @@ -18,9 +18,7 @@ parameters: # } steps: - # New-TestResources command requires Az module - - pwsh: Install-Module -Name Az -Scope CurrentUser -AllowClobber -Force -Verbose - displayName: Install Azure PowerShell module + - template: /eng/common/TestResources/setup-az-modules.yml - pwsh: | $subscriptionConfiguration = @" diff --git a/eng/common/TestResources/setup-az-modules.yml b/eng/common/TestResources/setup-az-modules.yml new file mode 100644 index 0000000000..9329ddf588 --- /dev/null +++ b/eng/common/TestResources/setup-az-modules.yml @@ -0,0 +1,36 @@ +# Cloud Configuration will be splat into parameters of `Add-AzEnvironment`. It +# should be JSON in the form (not all fields are required): +# { +# "Name": "", +# "PublishSettingsFileUrl": "", +# "ServiceEndpoint": "", +# "ManagementPortalUrl": "", +# "ActiveDirectoryEndpoint": "", +# "ActiveDirectoryServiceEndpointResourceId": "", +# "ResourceManagerEndpoint": "", +# "GalleryEndpoint": "", +# "GraphEndpoint": "", +# "GraphAudience": "", +# "AzureKeyVaultDnsSuffix": "", +# "AzureKeyVaultServiceEndpointResourceId": "" +# } + +steps: + - bash: sudo chown -R runner ~/.Azure + displayName: (MacOS) Grant access to ~/.Azure + condition: contains(variables['OSVmImage'], 'mac') + + # New-TestResources command requires Az module + - pwsh: Install-Module -Name Az -Scope CurrentUser -AllowClobber -Force -Verbose + displayName: Install Azure PowerShell module + + - task: Powershell@2 + inputs: + displayName: Register Dogfood environment + targetType: inline + pwsh: true + script: | + $environmentSpec = @" + $(env-config-dogfood) + "@ | ConvertFrom-Json -AsHashtable; + Add-AzEnvironment @environmentSpec diff --git a/eng/common/scripts/New-ReleaseAsset.ps1 b/eng/common/scripts/New-ReleaseAsset.ps1 new file mode 100644 index 0000000000..83efcc097e --- /dev/null +++ b/eng/common/scripts/New-ReleaseAsset.ps1 @@ -0,0 +1,62 @@ +<# +.SYNOPSIS +Uploads the release asset and returns the resulting object from the upload + +.PARAMETER ReleaseTag +Tag to look up release + +.PARAMETER AssetPath +Location of the asset file to upload + +.PARAMETER GitHubRepo +Name of the GitHub repo to search (of the form Azure/azure-sdk-for-cpp) + +#> + +param ( + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [string] $ReleaseTag, + + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [string] $AssetPath, + + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [string] $GitHubRepo, + + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [string] $GitHubPat +) + +# Get information about release at $ReleaseTag +$releaseInfoUrl = "https://api.github.com/repos/$GitHubRepo/releases/tags/$ReleaseTag" +Write-Verbose "Requesting release info from $releaseInfoUrl" +$release = Invoke-RestMethod ` + -Uri $releaseInfoUrl ` + -Method GET + +$assetFilename = Split-Path $AssetPath -Leaf + +# Upload URL comes in the literal form (yes, those curly braces) of: +# https://uploads.github.com/repos/Azure/azure-sdk-for-cpp/releases/123/assets{?name,label} +# Converts to something like: +# https://uploads.github.com/repos/Azure/azure-sdk-for-cpp/releases/123/assets?name=foo.tar.gz +# Docs: https://docs.github.com/en/rest/reference/repos#get-a-release-by-tag-name +$uploadUrl = $release.upload_url.Split('{')[0] + "?name=$assetFilename" + +Write-Verbose "Uploading $assetFilename to $uploadUrl" + +$asset = Invoke-RestMethod ` + -Uri $uploadUrl ` + -Method POST ` + -InFile $AssetPath ` + -Credential $credentials ` + -Headers @{ Authorization = "token $GitHubPat" } ` + -ContentType "application/gzip" + +Write-Verbose "Upload complete. Browser download URL: $($asset.browser_download_url)" + +return $asset