Skip to content

Commit b59cd44

Browse files
authored
Update eng/common (#2137)
- Updated to latest from azure-sdk-tools as of commit 046153339b
1 parent a909a44 commit b59cd44

File tree

7 files changed

+460
-261
lines changed

7 files changed

+460
-261
lines changed

eng/common/TestResources/New-TestResources.ps1.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Deploys live test resources defined for a service directory to Azure.
1313
## SYNTAX
1414

1515
### Default (Default)
16-
```pwsh
16+
```
1717
New-TestResources.ps1 [-BaseName <String>] [-ResourceGroupName <String>] [-ServiceDirectory] <String>
1818
[-TestResourcesDirectory <String>] [-TestApplicationId <String>] [-TestApplicationSecret <String>]
1919
[-TestApplicationOid <String>] [-SubscriptionId <String>] [-DeleteAfterHours <Int32>] [-Location <String>]
@@ -24,7 +24,7 @@ New-TestResources.ps1 [-BaseName <String>] [-ResourceGroupName <String>] [-Servi
2424
```
2525

2626
### Provisioner
27-
```pwsh
27+
```
2828
New-TestResources.ps1 [-BaseName <String>] [-ResourceGroupName <String>] [-ServiceDirectory] <String>
2929
[-TestResourcesDirectory <String>] [-TestApplicationId <String>] [-TestApplicationSecret <String>]
3030
[-TestApplicationOid <String>] -TenantId <String> [-SubscriptionId <String>]
@@ -59,7 +59,7 @@ or those specified in $ProvisionerApplicationId and $ProvisionerApplicationSecre
5959
## EXAMPLES
6060

6161
### EXAMPLE 1
62-
```pwsh
62+
```
6363
Connect-AzAccount -Subscription 'REPLACE_WITH_SUBSCRIPTION_ID'
6464
New-TestResources.ps1 keyvault
6565
```
@@ -74,7 +74,7 @@ Requires PowerShell 7 to use ConvertFrom-SecureString -AsPlainText or convert
7474
the SecureString to plaintext by another means.
7575

7676
### EXAMPLE 2
77-
```pwsh
77+
```
7878
Connect-AzAccount -Subscription 'REPLACE_WITH_SUBSCRIPTION_ID'
7979
New-TestResources.ps1 `
8080
-BaseName 'azsdk' `
@@ -96,7 +96,7 @@ Requires PowerShell 7 to use ConvertFrom-SecureString -AsPlainText or convert
9696
the SecureString to plaintext by another means.
9797

9898
### EXAMPLE 3
99-
```pwsh
99+
```
100100
Connect-AzAccount -Subscription 'REPLACE_WITH_SUBSCRIPTION_ID'
101101
New-TestResources.ps1 `
102102
-BaseName 'azsdk' `
@@ -115,7 +115,7 @@ to the 'TestApplicationId' for the resource group and the resources that it cont
115115
without altering its existing permissions.
116116

117117
### EXAMPLE 4
118-
```pwsh
118+
```
119119
New-TestResources.ps1 `
120120
-BaseName 'azsdk' `
121121
-ServiceDirectory 'keyvault' `
@@ -145,7 +145,7 @@ Requires PowerShell 7 to use ConvertFrom-SecureString -AsPlainText or convert
145145
the SecureString to plaintext by another means.
146146

147147
### EXAMPLE 5
148-
```pwsh
148+
```
149149
New-TestResources.ps1 `
150150
-ServiceDirectory '$(ServiceDirectory)' `
151151
-TenantId '$(TenantId)' `

eng/common/pipelines/templates/archetype-typespec-emitter.yml

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,19 @@ extends:
101101
pool: ${{ parameters.Pool }}
102102
jobs:
103103
- job: Build
104+
variables:
105+
emitterNpmrcPath: $(Agent.TempDirectory)/${{ parameters.EmitterPackagePath }}/.npmrc
104106
steps:
105107
- template: /eng/common/pipelines/templates/steps/sparse-checkout.yml
106108
parameters:
107109
Paths: ${{ parameters.SparseCheckoutPaths }}
108110

109111
- ${{ parameters.InitializationSteps }}
110112

113+
- template: /eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml
114+
parameters:
115+
npmrcPath: $(emitterNpmrcPath)
116+
111117
# Initialize-WorkingDirectory.ps1 is responsible for setting the emitterVersion output variable.
112118
- task: PowerShell@2
113119
displayName: 'Run initialize script'
@@ -126,6 +132,8 @@ extends:
126132
-OutputDirectory "$(Build.ArtifactStagingDirectory)"
127133
-UseTypeSpecNext:$${{ parameters.UseTypeSpecNext }}
128134
-EmitterPackagePath:${{ parameters.EmitterPackagePath }}
135+
env:
136+
NPM_CONFIG_USERCONFIG: $(emitterNpmrcPath)
129137

130138
- task: PowerShell@2
131139
displayName: 'Run build script'
@@ -137,6 +145,8 @@ extends:
137145
-TargetNpmJsFeed:$${{ parameters.PublishPublic }}
138146
-EmitterPackagePath:${{ parameters.EmitterPackagePath }}
139147
-GeneratorVersion: $(initialize.emitterVersion)
148+
env:
149+
NPM_CONFIG_USERCONFIG: $(emitterNpmrcPath)
140150

141151
- pwsh: |
142152
$sourceBranch = '$(Build.SourceBranch)'
@@ -237,7 +247,7 @@ extends:
237247
- template: /eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml
238248
parameters:
239249
npmrcPath: $(buildArtifactsPath)/packages/.npmrc
240-
registryUrl: https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-js-test-autorest/npm/registry/
250+
registryUrl: https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-js/npm/registry/
241251

242252
# publish to devops feed
243253
- pwsh: |
@@ -260,7 +270,7 @@ extends:
260270

261271
- ${{ if parameters.PublishPublic }}:
262272
# publish to npmjs.org using ESRP
263-
- task: EsrpRelease@9
273+
- task: EsrpRelease@11
264274
inputs:
265275
displayName: Publish to npmjs.org
266276
ConnectedServiceName: Azure SDK PME Managed Identity
@@ -288,6 +298,7 @@ extends:
288298
pullRequestTargetBranch: 'main'
289299
buildArtifactsPath: $(Pipeline.Workspace)/build_artifacts
290300
branchName: $[stageDependencies.Build.Build.outputs['set_branch_name.branchName']]
301+
tspClientNpmrcPath: $(Agent.TempDirectory)/tsp-client/.npmrc
291302
pool: ${{ parameters.Pool }}
292303
jobs:
293304
- job: Initialize
@@ -302,10 +313,16 @@ extends:
302313
- download: current
303314
displayName: Download pipeline artifacts
304315

316+
- template: /eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml
317+
parameters:
318+
npmrcPath: $(tspClientNpmrcPath)
319+
305320
- pwsh: |
306321
npm ci
307322
displayName: Install tsp-client
308323
workingDirectory: $(Build.SourcesDirectory)/eng/common/tsp-client
324+
env:
325+
NPM_CONFIG_USERCONFIG: $(tspClientNpmrcPath)
309326
310327
- pwsh: |
311328
# Resolve EmitterPackageJsonOutputPath to absolute path if it's relative
@@ -331,6 +348,8 @@ extends:
331348
}
332349
displayName: Generate emitter-package.json and emitter-package-lock files
333350
workingDirectory: $(Build.SourcesDirectory)/eng/common/tsp-client
351+
env:
352+
NPM_CONFIG_USERCONFIG: $(tspClientNpmrcPath)
334353
335354
- ${{ parameters.InitializationSteps }}
336355

@@ -372,6 +391,7 @@ extends:
372391
variables:
373392
matrixArtifactsPath: $(Pipeline.Workspace)/matrix_artifacts
374393
AzureSdkRepoName: $[format('azure-sdk/{0}', split(variables['Build.Repository.Name'], '/')[1])]
394+
emitterNpmrcPath: $(Agent.TempDirectory)/${{ parameters.EmitterPackagePath }}/.npmrc
375395
steps:
376396
- checkout: self
377397
- pwsh: |
@@ -390,6 +410,10 @@ extends:
390410

391411
- ${{ parameters.InitializationSteps }}
392412

413+
- template: /eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml
414+
parameters:
415+
npmrcPath: $(emitterNpmrcPath)
416+
393417
- task: PowerShell@2
394418
displayName: Call regeneration script
395419
inputs:
@@ -399,6 +423,8 @@ extends:
399423
-PackageDirectoriesFile "$(matrixArtifactsPath)/$(DirectoryList)"
400424
workingDirectory: $(Build.SourcesDirectory)
401425
continueOnError: true
426+
env:
427+
NPM_CONFIG_USERCONFIG: $(emitterNpmrcPath)
402428

403429
- template: /eng/common/pipelines/templates/steps/git-push-changes.yml
404430
parameters:
@@ -529,6 +555,7 @@ extends:
529555
matrix: ${{ parameters.TestMatrix }}
530556
variables:
531557
buildArtifactsPath: $(Pipeline.Workspace)/build_artifacts
558+
emitterNpmrcPath: $(Agent.TempDirectory)/${{ parameters.EmitterPackagePath }}/.npmrc
532559
steps:
533560
- template: /eng/common/pipelines/templates/steps/sparse-checkout.yml
534561
parameters:
@@ -540,6 +567,10 @@ extends:
540567

541568
- ${{ parameters.InitializationSteps }}
542569

570+
- template: /eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml
571+
parameters:
572+
npmrcPath: $(emitterNpmrcPath)
573+
543574
- task: PowerShell@2
544575
displayName: 'Run initialize script'
545576
inputs:
@@ -548,6 +579,8 @@ extends:
548579
arguments: >
549580
-BuildArtifactsPath '$(buildArtifactsPath)/lock-files'
550581
-EmitterPackagePath: ${{ parameters.EmitterPackagePath }}
582+
env:
583+
NPM_CONFIG_USERCONFIG: $(emitterNpmrcPath)
551584

552585
- task: PowerShell@2
553586
displayName: 'Run test script'
@@ -558,6 +591,8 @@ extends:
558591
$(TestArguments)
559592
-OutputDirectory "$(Build.ArtifactStagingDirectory)"
560593
-EmitterPackagePath: ${{ parameters.EmitterPackagePath }}
594+
env:
595+
NPM_CONFIG_USERCONFIG: $(emitterNpmrcPath)
561596

562597
- template: /eng/common/pipelines/templates/steps/publish-1es-artifact.yml
563598
parameters:

eng/common/pipelines/templates/jobs/npm-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
7171
- ${{ if eq(parameters.Registry, 'https://registry.npmjs.org/') }}:
7272

73-
- task: EsrpRelease@9
73+
- task: EsrpRelease@11
7474
displayName: 'Publish ${{ parameters.ArtifactName }} via ESRP'
7575
condition: and(succeeded(), ne(variables['SkipPublishing'], 'true'))
7676
inputs:

eng/common/pipelines/templates/steps/eng-common-workflow-enforcer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ steps:
2121
}
2222
if ((!"$(System.PullRequest.SourceBranch)".StartsWith("sync-.github")) -and "$(System.PullRequest.TargetBranch)" -match "^(refs/heads/)?$(DefaultBranch)$")
2323
{
24-
# This list needs to be kept in sync with the FilePatterns listed in eng/pipelines/eng-github-config-sync.yml
24+
# This list needs to be kept in sync with the FilePatterns listed in eng/pipelines/sync-.github.yml
2525
$filePatterns = @(".github/workflows/*event*", ".github/workflows/post-apiview.yml", ".github/skills/azsdk-common-*/**")
2626
$filesInCommonDir = @()
2727
foreach ($filePattern in $filePatterns) {
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
<#
5+
.SYNOPSIS
6+
Converts an APIView token JSON file into a markdown file.
7+
8+
.DESCRIPTION
9+
Reads an APIView token JSON file (tree-style format) and renders its ReviewLines into
10+
a fenced markdown code block. This script is language-agnostic and works with token
11+
files produced by any APIView parser.
12+
13+
.PARAMETER TokenJsonPath
14+
Required. Path to the input APIView token JSON file.
15+
16+
.PARAMETER OutputPath
17+
Required. Path to write the output markdown file. If a directory is given, the file will be
18+
named api.md inside that directory.
19+
20+
.EXAMPLE
21+
./Export-APIViewMarkdown.ps1 -TokenJsonPath ./azure-core_python.json -OutputPath ./api.md
22+
23+
.EXAMPLE
24+
./Export-APIViewMarkdown.ps1 -TokenJsonPath ./azure-sdk_java.json -OutputPath ./output/
25+
#>
26+
27+
[CmdletBinding()]
28+
param(
29+
[Parameter(Mandatory = $true)]
30+
[string]$TokenJsonPath,
31+
32+
[Parameter(Mandatory = $true)]
33+
[string]$OutputPath
34+
)
35+
36+
Set-StrictMode -Version 3
37+
$ErrorActionPreference = 'Stop'
38+
39+
function Render-Token {
40+
<#
41+
.SYNOPSIS
42+
Renders a single ReviewToken object to a string, applying HasPrefixSpace and HasSuffixSpace.
43+
#>
44+
param([PSCustomObject]$Token)
45+
46+
$prefix = if ($Token.HasPrefixSpace -eq $true) { " " } else { "" }
47+
$suffix = if ($Token.HasSuffixSpace -eq $true) { " " } else { "" }
48+
return "$prefix$($Token.Value)$suffix"
49+
}
50+
51+
function Render-ReviewLines {
52+
<#
53+
.SYNOPSIS
54+
Recursively renders a list of ReviewLine objects into an array of strings.
55+
#>
56+
param(
57+
[object[]]$ReviewLines,
58+
[int]$IndentLevel = 0
59+
)
60+
61+
$result = [System.Collections.Generic.List[string]]::new()
62+
$indent = " " * $IndentLevel
63+
64+
foreach ($line in $ReviewLines) {
65+
$tokens = @($line.Tokens)
66+
67+
if ($tokens.Count -eq 0) {
68+
# Blank line
69+
$result.Add("")
70+
}
71+
else {
72+
$lineText = ($tokens | ForEach-Object { Render-Token $_ }) -join ""
73+
if ($lineText.Trim() -ne "") {
74+
$result.Add("$indent$lineText")
75+
}
76+
else {
77+
$result.Add("")
78+
}
79+
}
80+
81+
# Recursively render children with increased indentation
82+
$childrenProp = $line.PSObject.Properties.Item('Children')
83+
if ($null -ne $childrenProp -and $null -ne $childrenProp.Value -and $childrenProp.Value.Count -gt 0) {
84+
$childLines = Render-ReviewLines -ReviewLines $childrenProp.Value -IndentLevel ($IndentLevel + 1)
85+
foreach ($childLine in $childLines) {
86+
$result.Add($childLine)
87+
}
88+
}
89+
}
90+
91+
return $result
92+
}
93+
94+
# --- Main ---
95+
96+
if (-not (Test-Path $TokenJsonPath)) {
97+
Write-Error "Token JSON file not found: $TokenJsonPath"
98+
exit 1
99+
}
100+
101+
$tokenJson = Get-Content -Path $TokenJsonPath -Raw | ConvertFrom-Json
102+
103+
if (-not $tokenJson.ReviewLines) {
104+
Write-Error "The token JSON file does not contain a 'ReviewLines' property."
105+
exit 1
106+
}
107+
108+
# Resolve output path: if a directory is given, default filename to api.md
109+
if (Test-Path $OutputPath -PathType Container) {
110+
$OutputPath = Join-Path $OutputPath "api.md"
111+
}
112+
elseif (-not [System.IO.Path]::HasExtension($OutputPath)) {
113+
$OutputPath = Join-Path $OutputPath "api.md"
114+
}
115+
116+
# Read language from the token JSON, falling back to empty string
117+
$language = if ($tokenJson.PSObject.Properties.Item('Language') -and $tokenJson.Language) {
118+
$tokenJson.Language.ToLower()
119+
} else {
120+
""
121+
}
122+
123+
# Map full language names to common code fence identifiers
124+
$languageAliases = @{
125+
"python" = "py"
126+
"javascript" = "js"
127+
"typescript" = "ts"
128+
}
129+
if ($languageAliases.ContainsKey($language)) {
130+
$language = $languageAliases[$language]
131+
}
132+
133+
$reviewLines = @($tokenJson.ReviewLines)
134+
$renderedLines = Render-ReviewLines -ReviewLines $reviewLines
135+
136+
$fenceOpen = "``````$language"
137+
$fenceClose = "``````"
138+
139+
$outputLines = [System.Collections.Generic.List[string]]::new()
140+
$outputLines.Add($fenceOpen)
141+
foreach ($line in $renderedLines) {
142+
$outputLines.Add($line)
143+
}
144+
$outputLines.Add($fenceClose)
145+
146+
$outputContent = $outputLines -join "`n"
147+
148+
$outputDir = Split-Path -Parent $OutputPath
149+
if ($outputDir -and -not (Test-Path $outputDir)) {
150+
New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
151+
}
152+
153+
Set-Content -Path $OutputPath -Value $outputContent -NoNewline -Encoding utf8
154+
155+
Write-Host "Generated markdown: $OutputPath"

0 commit comments

Comments
 (0)