From c3f8bccd27fe76e0a8ae41aed8c364f838d5804a Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Wed, 31 May 2023 00:41:25 -0700 Subject: [PATCH] Sync eng/common directory with azure-sdk-tools for PR 6222 (#4674) * Updated typespec common script * Updated per the review comment --------- Co-authored-by: raychen --- eng/common/scripts/TypeSpec-Project-Process.ps1 | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/eng/common/scripts/TypeSpec-Project-Process.ps1 b/eng/common/scripts/TypeSpec-Project-Process.ps1 index a5e909d5d..3efe62f1d 100644 --- a/eng/common/scripts/TypeSpec-Project-Process.ps1 +++ b/eng/common/scripts/TypeSpec-Project-Process.ps1 @@ -102,11 +102,11 @@ $repoRootPath = (Join-Path $PSScriptRoot .. .. ..) $repoRootPath = Resolve-Path $repoRootPath $repoRootPath = $repoRootPath -replace "\\", "/" $tspConfigPath = Join-Path $repoRootPath 'tspconfig.yaml' +$tmpTspConfigPath = $tspConfigPath # example url of tspconfig.yaml: https://github.com/Azure/azure-rest-api-specs-pr/blob/724ccc4d7ef7655c0b4d5c5ac4a5513f19bbef35/specification/containerservice/Fleet.Management/tspconfig.yaml if ($TypeSpecProjectDirectory -match '^https://github.com/(?Azure/azure-rest-api-specs(-pr)?)/blob/(?[0-9a-f]{40})/(?.*)/tspconfig.yaml$') { try { - $TypeSpecProjectDirectory = $TypeSpecProjectDirectory -replace "github.com", "raw.githubusercontent.com" - $TypeSpecProjectDirectory = $TypeSpecProjectDirectory -replace "/blob/", "/" + $TypeSpecProjectDirectory = $TypeSpecProjectDirectory -replace "https://github.com/(.*)/(tree|blob)", "https://raw.githubusercontent.com/`$1" Invoke-WebRequest $TypeSpecProjectDirectory -OutFile $tspConfigPath -MaximumRetryCount 3 } catch { @@ -119,13 +119,25 @@ if ($TypeSpecProjectDirectory -match '^https://github.com/(?Azure/azure-re $CommitHash = $Matches["commit"] # TODO support the branch name in url then get the commithash from branch name } else { + if ($TypeSpecProjectDirectory -match "^.*/(?specification/.*)$") { + $TypeSpecProjectDirectory = $Matches["path"] + } else { + Write-Error "'$TypeSpecProjectDirectory' doesn't have 'specification' in path." + exit 1 + } $tspConfigPath = Join-Path $TypeSpecProjectDirectory "tspconfig.yaml" if (!(Test-Path $tspConfigPath)) { Write-Error "Failed to find tspconfig.yaml in '$TypeSpecProjectDirectory'" exit 1 } } + $tspConfigYaml = Get-Content $tspConfigPath -Raw | ConvertFrom-Yaml + +# delete the tmporary tspconfig.yaml downloaded from github +if (Test-Path $tmpTspConfigPath) { + Remove-Item $tspConfigPath +} # call CreateUpdate-TspLocation function $sdkProjectFolder = CreateUpdate-TspLocation $tspConfigYaml $TypeSpecProjectDirectory $CommitHash $repo $repoRootPath