Skip to content

Commit 6fdff4d

Browse files
authored
Merge branch 'main' into dev/Aman-Jain-14/StorageCache_AutoImport_2025-05-01_API_spec
2 parents 469363a + 6061deb commit 6fdff4d

File tree

777 files changed

+147637
-188
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

777 files changed

+147637
-188
lines changed

.github/workflows/post-apiview.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: After APIView
2+
3+
on:
4+
check_run:
5+
types: [completed]
6+
7+
permissions:
8+
pull-requests: write
9+
contents: read
10+
11+
jobs:
12+
post-apiview:
13+
name: After APIView
14+
runs-on: ubuntu-24.04
15+
if: |
16+
github.event.check_run.check_suite.app.name == 'Azure Pipelines' && (
17+
contains(github.event.check_run.name, 'APIView') ||
18+
contains(github.event.check_run.name, 'SDK Generation') )
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
with:
23+
sparse-checkout: 'eng/common'
24+
25+
- name: Create APIView Comment on PR
26+
run: |
27+
. "eng/common/scripts/Helpers/ApiView-Helpers.ps1"
28+
Set-ApiViewCommentForRelatedIssues -HeadCommitish ${{ github.event.check_run.head_sha }} -AuthToken ${{ secrets.GITHUB_TOKEN }}
29+
shell: pwsh

eng/common/pipelines/templates/stages/archetype-sdk-tool-pwsh.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ parameters:
1010
- name: TargetTags
1111
type: string
1212
default: ''
13+
- name: PreTestSteps
14+
type: object
15+
default: []
1316

1417
variables:
1518
- template: /eng/pipelines/templates/variables/globals.yml
@@ -36,6 +39,8 @@ stages:
3639
vmImage: $(Image)
3740

3841
steps:
42+
- ${{ parameters.PreTestSteps }}
43+
3944
- template: /eng/common/pipelines/templates/steps/run-pester-tests.yml
4045
parameters:
4146
TargetDirectory: ${{ parameters.TargetDirectory }}

eng/common/scripts/Helpers/ApiView-Helpers.ps1

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ function Set-ApiViewCommentForPR {
168168
$commentText = @()
169169
$commentText += "## API Change Check"
170170
try {
171-
$response = Invoke-RestMethod -Uri $apiviewEndpoint -Method Get -MaximumRetryCount 3
172-
if ($response.Count -eq 0) {
171+
$response = Invoke-WebRequest -Uri $apiviewEndpoint -Method Get -MaximumRetryCount 3
172+
if ($response.StatusCode -ne 200) {
173173
LogWarning "API changes are not detected in this pull request."
174174
$commentText += ""
175175
$commentText += "API changes are not detected in this pull request."
@@ -179,10 +179,17 @@ function Set-ApiViewCommentForPR {
179179
$commentText += ""
180180
$commentText += "APIView identified API level changes in this PR and created the following API reviews"
181181
$commentText += ""
182-
$commentText += "| Language | API Review for Package |"
183-
$commentText += "|----------|---------|"
184-
$response | ForEach-Object {
185-
$commentText += "| $($_.language) | [$($_.packageName)]($($_.url)) |"
182+
183+
if ($RepoName.StartsWith(("azure-sdk-for-"))) {
184+
$response | ForEach-Object {
185+
$commentText += "[$($_.packageName)]($($_.url))"
186+
}
187+
} else {
188+
$commentText += "| Language | API Review for Package |"
189+
$commentText += "|----------|---------|"
190+
$response | ForEach-Object {
191+
$commentText += "| $($_.language) | [$($_.packageName)]($($_.url)) |"
192+
}
186193
}
187194
}
188195
} catch{

eng/common/scripts/Package-Properties.ps1

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ class PackageProps {
7777
$this.ArtifactName = $artifactName
7878
$this.Initialize($name, $version, $directoryPath, $serviceDirectory)
7979
}
80-
hidden [PSCustomObject]ParseYmlForArtifact([string]$ymlPath) {
80+
81+
hidden [PSCustomObject]ParseYmlForArtifact([string]$ymlPath, [bool]$soleCIYml = $false) {
8182
$content = LoadFrom-Yaml $ymlPath
8283
if ($content) {
8384
$artifacts = GetValueSafelyFrom-Yaml $content @("extends", "parameters", "Artifacts")
84-
$artifactForCurrentPackage = $null
85+
$artifactForCurrentPackage = @{}
86+
8587
if ($artifacts) {
8688
# If there's an artifactName match that to the name field from the yml
8789
if ($this.ArtifactName) {
@@ -98,8 +100,9 @@ class PackageProps {
98100
}
99101
}
100102

101-
# if we found an artifact for the current package, we should count this ci file as the source of the matrix for this package
102-
if ($artifactForCurrentPackage) {
103+
# if we found an artifact for the current package OR this is the sole ci.yml for the given service directory,
104+
# we should count this ci file as the source of the matrix for this package
105+
if ($artifactForCurrentPackage -or $soleCIYml) {
103106
$result = [PSCustomObject]@{
104107
ArtifactConfig = [HashTable]$artifactForCurrentPackage
105108
ParsedYml = $content
@@ -116,11 +119,12 @@ class PackageProps {
116119
$RepoRoot = Resolve-Path (Join-Path $PSScriptRoot ".." ".." "..")
117120

118121
$ciFolderPath = Join-Path -Path $RepoRoot -ChildPath (Join-Path "sdk" $this.ServiceDirectory)
119-
$ciFiles = Get-ChildItem -Path $ciFolderPath -Filter "ci*.yml" -File
122+
$ciFiles = @(Get-ChildItem -Path $ciFolderPath -Filter "ci*.yml" -File)
120123
$ciArtifactResult = $null
124+
$soleCIYml = ($ciFiles.Count -eq 1)
121125

122126
foreach ($ciFile in $ciFiles) {
123-
$ciArtifactResult = $this.ParseYmlForArtifact($ciFile.FullName)
127+
$ciArtifactResult = $this.ParseYmlForArtifact($ciFile.FullName, $soleCIYml)
124128
if ($ciArtifactResult) {
125129
break
126130
}
@@ -137,7 +141,7 @@ class PackageProps {
137141
if (-not $this.ArtifactDetails) {
138142
$ciArtifactResult = $this.GetCIYmlForArtifact()
139143

140-
if ($ciArtifactResult) {
144+
if ($ciArtifactResult -and $null -ne $ciArtifactResult.ArtifactConfig) {
141145
$this.ArtifactDetails = [Hashtable]$ciArtifactResult.ArtifactConfig
142146

143147
$repoRoot = Resolve-Path (Join-Path $PSScriptRoot ".." ".." "..")
@@ -147,27 +151,32 @@ class PackageProps {
147151
if (-not $this.ArtifactDetails["triggeringPaths"]) {
148152
$this.ArtifactDetails["triggeringPaths"] = @()
149153
}
150-
else {
151-
$adjustedPaths = @()
152-
153-
# we need to convert relative references to absolute references within the repo
154-
# this will make it extremely easy to compare triggering paths to files in the deleted+changed file list.
155-
for ($i = 0; $i -lt $this.ArtifactDetails["triggeringPaths"].Count; $i++) {
156-
$currentPath = $this.ArtifactDetails["triggeringPaths"][$i]
157-
$newPath = Join-Path $repoRoot $currentPath
158-
if (!$currentPath.StartsWith("/")) {
159-
$newPath = Join-Path $repoRoot $relRoot $currentPath
160-
}
161-
# it is a possibility that users may have a triggerPath dependency on a file that no longer exists.
162-
# before we resolve it to get rid of possible relative references, we should check if the file exists
163-
# if it doesn't, we should just leave it as is. Otherwise we would _crash_ here when a user accidentally
164-
# left a triggeringPath on a file that had been deleted
165-
if (Test-Path $newPath) {
166-
$adjustedPaths += (Resolve-Path -Path $newPath -Relative -RelativeBasePath $repoRoot).TrimStart(".").Replace("`\", "/")
167-
}
154+
155+
# if we know this is the matrix for our file, we should now see if there is a custom matrix config for the package
156+
$serviceTriggeringPaths = GetValueSafelyFrom-Yaml $ciArtifactResult.ParsedYml @("extends", "parameters", "TriggeringPaths")
157+
if ($serviceTriggeringPaths){
158+
$this.ArtifactDetails["triggeringPaths"] += $serviceTriggeringPaths
159+
}
160+
161+
$adjustedPaths = @()
162+
163+
# we need to convert relative references to absolute references within the repo
164+
# this will make it extremely easy to compare triggering paths to files in the deleted+changed file list.
165+
for ($i = 0; $i -lt $this.ArtifactDetails["triggeringPaths"].Count; $i++) {
166+
$currentPath = $this.ArtifactDetails["triggeringPaths"][$i]
167+
$newPath = Join-Path $repoRoot $currentPath
168+
if (!$currentPath.StartsWith("/")) {
169+
$newPath = Join-Path $repoRoot $relRoot $currentPath
170+
}
171+
# it is a possibility that users may have a triggerPath dependency on a file that no longer exists.
172+
# before we resolve it to get rid of possible relative references, we should check if the file exists
173+
# if it doesn't, we should just leave it as is. Otherwise we would _crash_ here when a user accidentally
174+
# left a triggeringPath on a file that had been deleted
175+
if (Test-Path $newPath) {
176+
$adjustedPaths += (Resolve-Path -Path $newPath -Relative -RelativeBasePath $repoRoot).TrimStart(".").Replace("`\", "/")
168177
}
169-
$this.ArtifactDetails["triggeringPaths"] = $adjustedPaths
170178
}
179+
$this.ArtifactDetails["triggeringPaths"] = $adjustedPaths
171180
$this.ArtifactDetails["triggeringPaths"] += $ciYamlPath
172181

173182
$this.CIParameters["CIMatrixConfigs"] = @()
@@ -215,6 +224,22 @@ function Get-PkgProperties {
215224
return $null
216225
}
217226

227+
function Get-PackagesFromPackageInfo([string]$PackageInfoFolder, [bool]$IncludeIndirect, [ScriptBlock]$CustomCompareFunction = $null) {
228+
$packages = Get-ChildItem -R -Path $PackageInfoFolder -Filter "*.json" | ForEach-Object {
229+
Get-Content $_.FullName | ConvertFrom-Json
230+
}
231+
232+
if (-not $includeIndirect) {
233+
$packages = $packages | Where-Object { $_.IncludedForValidation -eq $false }
234+
}
235+
236+
if ($CustomCompareFunction) {
237+
$packages = $packages | Where-Object { &$CustomCompareFunction $_ }
238+
}
239+
240+
return $packages
241+
}
242+
218243

219244
function Get-TriggerPaths([PSCustomObject]$AllPackageProperties) {
220245
$existingTriggeringPaths = @()
@@ -447,7 +472,8 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
447472
# finally, if we have gotten all the way here and we still don't have any packages, we should include the template service
448473
# packages. We should never return NO validation.
449474
if ($packagesWithChanges.Count -eq 0) {
450-
$packagesWithChanges += ($allPackageProperties | Where-Object { $_.ServiceDirectory -eq "template" })
475+
# most of our languages use `template` as the service directory for the template service, but `go` uses `template/aztemplate`.
476+
$packagesWithChanges += ($allPackageProperties | Where-Object { $_.ServiceDirectory -eq "template"-or $_.ServiceDirectory -eq "template/aztemplate" })
451477
foreach ($package in $packagesWithChanges) {
452478
$package.IncludedForValidation = $true
453479
}

eng/common/scripts/logging.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function LogWarning {
3535
Write-Host ("##vso[task.LogIssue type=warning;]$args" -replace "`n", "%0D%0A")
3636
}
3737
elseif (Test-SupportsGitHubLogging) {
38-
Write-Warning ("::warning::$args" -replace "`n", "%0D%0A")
38+
Write-Host ("::warning::$args" -replace "`n", "%0D%0A")
3939
}
4040
else {
4141
Write-Warning "$args"
@@ -56,7 +56,7 @@ function LogErrorForFile($file, $errorString)
5656
Write-Host ("##vso[task.logissue type=error;sourcepath=$file;linenumber=1;columnnumber=1;]$errorString" -replace "`n", "%0D%0A")
5757
}
5858
elseif (Test-SupportsGitHubLogging) {
59-
Write-Error ("::error file=$file,line=1,col=1::$errorString" -replace "`n", "%0D%0A")
59+
Write-Host ("::error file=$file,line=1,col=1::$errorString" -replace "`n", "%0D%0A")
6060
}
6161
else {
6262
Write-Error "[Error in file $file]$errorString"
@@ -68,7 +68,7 @@ function LogError {
6868
Write-Host ("##vso[task.LogIssue type=error;]$args" -replace "`n", "%0D%0A")
6969
}
7070
elseif (Test-SupportsGitHubLogging) {
71-
Write-Error ("::error::$args" -replace "`n", "%0D%0A")
71+
Write-Host ("::error::$args" -replace "`n", "%0D%0A")
7272
}
7373
else {
7474
Write-Error "$args"
@@ -80,7 +80,7 @@ function LogDebug {
8080
Write-Host "[debug]$args"
8181
}
8282
elseif (Test-SupportsGitHubLogging) {
83-
Write-Debug "::debug::$args"
83+
Write-Host "::debug::$args"
8484
}
8585
else {
8686
Write-Debug "$args"

eng/pipelines/templates/stages/1es-redirect.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extends:
2121
template: v1/1ES.Official.PipelineTemplate.yml@1ESPipelineTemplates
2222
parameters:
2323
settings:
24-
skipBuildTagsForGitHubPullRequests: true
24+
skipBuildTagsForGitHubPullRequests: true
2525
sdl:
2626
${{ if and(parameters.GenerateBaselines, eq(variables['Build.SourceBranchName'], 'main'), eq(variables['System.TeamProject'], 'internal')) }}:
2727
autobaseline:
@@ -40,6 +40,8 @@ extends:
4040
${{ else }}:
4141
template: v1/1ES.Unofficial.PipelineTemplate.yml@1ESPipelineTemplates
4242
parameters:
43+
settings:
44+
skipBuildTagsForGitHubPullRequests: true
4345
sdl: # SDLSources stage still runs even all tools are disabled. 1es team uses it for other purposes and they have the following work item to remove the stage.
4446
enableAllTools: false # https://dev.azure.com/mseng/1ES/_workitems/edit/2253084
4547
sourceAnalysisPool:

eng/tools/typespec-requirement/test/typespec-requirement.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ async function checkAllUnder(path: string, responseCache?: string) {
1111
command += ` -_ResponseCache ${responseCache}`;
1212
}
1313

14-
return await execa("pwsh", ["-Command", command], { cwd: repoRoot, reject: false });
14+
const result = await execa("pwsh", ["-Command", command], { cwd: repoRoot, reject: false });
15+
return {
16+
// Merge stdout and stderr, since script writes to stdout in CI but stderr on dev machine
17+
stdout: result.stdout + result.stderr,
18+
exitCode: result.exitCode,
19+
};
1520
}
1621

1722
test.concurrent("No files to check", async ({ expect }) => {
@@ -36,9 +41,9 @@ test.concurrent("Parse error", async ({ expect }) => {
3641
});
3742

3843
test.concurrent("No tspconfig.yaml", async ({ expect }) => {
39-
const { stderr, exitCode } = await checkAllUnder("specification/no-tspconfig");
44+
const { stdout, exitCode } = await checkAllUnder("specification/no-tspconfig");
4045

41-
expect(stderr).toContain("no files named 'tspconfig.yaml'");
46+
expect(stdout).toContain("no files named 'tspconfig.yaml'");
4247
expect(exitCode).toBe(1);
4348
});
4449

@@ -74,12 +79,12 @@ test.concurrent("Hand-written, does not exist in main", async ({ expect }) => {
7479
});
7580

7681
test.concurrent("Hand-written, unexpected response checking main", async ({ expect }) => {
77-
const { stdout, stderr, exitCode } = await checkAllUnder(
82+
const { stdout, exitCode } = await checkAllUnder(
7883
"specification/hand-written",
7984
'@{"https://github.com/Azure/azure-rest-api-specs/tree/main/specification/hand-written/resource-manager/Microsoft.HandWritten/stable"=519}',
8085
);
8186

8287
expect(stdout).toContain("was not generated from TypeSpec");
83-
expect(stderr).toContain("Unexpected response");
88+
expect(stdout).toContain("Unexpected response");
8489
expect(exitCode).toBe(1);
8590
});

eng/tools/typespec-validation/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
},
99
"dependencies": {
1010
"globby": "^14.0.1",
11+
"picocolors": "^1.1.1",
1112
"simple-git": "^3.24.0",
1213
"suppressions": "file:../suppressions",
14+
"strip-ansi": "^7.1.0",
1315
"yaml": "^2.4.2"
1416
},
1517
"devDependencies": {

0 commit comments

Comments
 (0)