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

Sync eng/common directory with azure-sdk-tools for PR 6250 #36708

Merged
merged 7 commits into from
May 31, 2023
Merged
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
59 changes: 39 additions & 20 deletions eng/common/scripts/TypeSpec-Project-Process.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ function CreateUpdate-TspLocation([System.Object]$tspConfig, [string]$TypeSpecPr
# Create service-dir if not exist
$serviceDir = Join-Path $repoRoot $serviceDir
if (!(Test-Path -Path $serviceDir)) {
New-Item -Path $serviceDir -ItemType Directory
New-Item -Path $serviceDir -ItemType Directory | Out-Null
Write-Host "created service folder $serviceDir"
}

# Create package-dir if not exist
$packageDir = Join-Path $serviceDir $packageDir
if (!(Test-Path -Path $packageDir)) {
New-Item -Path $packageDir -ItemType Directory
New-Item -Path $packageDir -ItemType Directory | Out-Null
Write-Host "created package folder $packageDir"
}

Expand All @@ -59,11 +59,15 @@ function CreateUpdate-TspLocation([System.Object]$tspConfig, [string]$TypeSpecPr

# Update tsp-location.yaml
$tspLocationYaml["commit"] = $CommitHash
Write-Host "updated tsp-location.yaml commit to $CommitHash"
$tspLocationYaml["repo"] = $repo
Write-Host "updated tsp-location.yaml repo to $repo"
$tspLocationYaml["directory"] = $TypeSpecProjectDirectory
Write-Host "updated tsp-location.yaml directory to $TypeSpecProjectDirectory"
$tspLocationYaml["additionalDirectories"] = $additionalDirs
Write-Host "updated tsp-location.yaml additionalDirectories to $additionalDirs"
$tspLocationYaml |ConvertTo-Yaml | Out-File $tspLocationYamlPath
Write-Host "updated tsp-location.yaml in $packageDir"
Write-Host "finished updating tsp-location.yaml in $packageDir"
return $packageDir
}

Expand All @@ -87,22 +91,13 @@ function Get-PackageDir([System.Object]$tspConfig) {
return $packageDir
}

$repo = ""
if ($RepoUrl) {
if ($RepoUrl -match "^https://github.com/(?<repo>[^/]*/azure-rest-api-specs(-pr)?).*") {
$repo = $Matches["repo"]
}
else {
Write-Host "Parameter 'RepoUrl' has incorrect value: $RepoUrl. It should be similar like 'https://github.com/Azure/azure-rest-api-specs'"
exit 1
}
}

$repoRootPath = (Join-Path $PSScriptRoot .. .. ..)
$repoRootPath = Resolve-Path $repoRootPath
$repoRootPath = $repoRootPath -replace "\\", "/"
$tspConfigPath = Join-Path $repoRootPath 'tspconfig.yaml'
$tmpTspConfigPath = $tspConfigPath
$repo = ""
# remote url scenario
# 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/(?<repo>Azure/azure-rest-api-specs(-pr)?)/blob/(?<commit>[0-9a-f]{40})/(?<path>.*)/tspconfig.yaml$') {
try {
Expand All @@ -119,15 +114,32 @@ if ($TypeSpecProjectDirectory -match '^https://github.com/(?<repo>Azure/azure-re
$CommitHash = $Matches["commit"]
# TODO support the branch name in url then get the commithash from branch name
} else {
# local path scenario
$tspConfigPath = Join-Path $TypeSpecProjectDirectory "tspconfig.yaml"
if (!(Test-Path $tspConfigPath)) {
Write-Error "Failed to find tspconfig.yaml in '$TypeSpecProjectDirectory'"
exit 1
}
$TypeSpecProjectDirectory = $TypeSpecProjectDirectory.Replace("\", "/")
if ($TypeSpecProjectDirectory -match "^.*/(?<path>specification/.*)$") {
$TypeSpecProjectDirectory = $Matches["path"]
} else {
Write-Error "'$TypeSpecProjectDirectory' doesn't have 'specification' in path."
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'"
if (!$CommitHash) {
Write-Error "Parameter of Commithash is not provided in the local path scenario."
exit 1
}
if (!$RepoUrl) {
Write-Error "Parameter of RepoUrl:$RepoUrl is not provided in the local path scenario."
exit 1
}
if ($RepoUrl -match "^https://github.com/(?<repo>[^/]*/azure-rest-api-specs(-pr)?).*") {
$repo = $Matches["repo"]
}
else {
Write-Error "Parameter 'RepoUrl' has incorrect value:$RepoUrl. It should be similar like 'https://github.com/Azure/azure-rest-api-specs'"
exit 1
}
}
Expand All @@ -142,6 +154,13 @@ if (Test-Path $tmpTspConfigPath) {
$sdkProjectFolder = CreateUpdate-TspLocation $tspConfigYaml $TypeSpecProjectDirectory $CommitHash $repo $repoRootPath

# call TypeSpec-Project-Sync.ps1
& "$PSScriptRoot/TypeSpec-Project-Sync.ps1" $sdkProjectFolder
$syncScript = Join-Path $PSScriptRoot TypeSpec-Project-Sync.ps1
& $syncScript $sdkProjectFolder
if ($LASTEXITCODE) { exit $LASTEXITCODE }

# call TypeSpec-Project-Generate.ps1
& "$PSScriptRoot/TypeSpec-Project-Generate.ps1" $sdkProjectFolder
$generateScript = Join-Path $PSScriptRoot TypeSpec-Project-Generate.ps1
& $generateScript $sdkProjectFolder
if ($LASTEXITCODE) { exit $LASTEXITCODE }

return $sdkProjectFolder