Skip to content

Commit

Permalink
Merge branch 'main' into ianna/adlsBackupParam
Browse files Browse the repository at this point in the history
  • Loading branch information
IannGeorges authored Feb 25, 2025
2 parents 098ad92 + 2f4175a commit 9180789
Show file tree
Hide file tree
Showing 187 changed files with 32,618 additions and 140 deletions.
45 changes: 43 additions & 2 deletions eng/common/scripts/Package-Properties.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class PackageProps {
$result = [PSCustomObject]@{
ArtifactConfig = [HashTable]$artifactForCurrentPackage
ParsedYml = $content
Location = $ymlPath
}

return $result
Expand Down Expand Up @@ -126,6 +127,14 @@ class PackageProps {

if ($ciArtifactResult) {
$this.ArtifactDetails = [Hashtable]$ciArtifactResult.ArtifactConfig

if (-not $this.ArtifactDetails["triggeringPaths"]) {
$this.ArtifactDetails["triggeringPaths"] = @()
}
$RepoRoot = Resolve-Path (Join-Path $PSScriptRoot ".." ".." "..")
$relativePath = (Resolve-Path -Path $ciArtifactResult.Location -Relative -RelativeBasePath $RepoRoot).TrimStart(".").Replace("`\", "/")
$this.ArtifactDetails["triggeringPaths"] += $relativePath

$this.CIParameters["CIMatrixConfigs"] = @()

# if we know this is the matrix for our file, we should now see if there is a custom matrix config for the package
Expand Down Expand Up @@ -207,6 +216,7 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
}

foreach ($file in $targetedFiles) {
$pathComponents = $file -split "/"
$shouldExclude = $false
foreach ($exclude in $excludePaths) {
if ($file.StartsWith($exclude,'CurrentCultureIgnoreCase')) {
Expand All @@ -219,12 +229,12 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
}
$filePath = (Join-Path $RepoRoot $file)

# handle direct changes to packages
$shouldInclude = $filePath -like (Join-Path "$pkgDirectory" "*")

# this implementation guesses the working directory of the ci.yml
# handle changes to files that are RELATED to each package
foreach($triggerPath in $triggeringPaths) {
$resolvedRelativePath = (Join-Path $RepoRoot $triggerPath)
# utilize the various trigger paths against the targeted file here
if (!$triggerPath.StartsWith("/")){
$resolvedRelativePath = (Join-Path $RepoRoot "sdk" "$($pkg.ServiceDirectory)" $triggerPath)
}
Expand All @@ -237,6 +247,36 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
if ($includedForValidation) {
$pkg.IncludedForValidation = $true
}
break
}
}

# handle service-level changes to the ci.yml files
# we are using the ci.yml file being added automatically to each artifactdetails as the input
# for this task. This is because we can resolve a service directory from the ci.yml, and if
# there is a single ci.yml in that directory, we can assume that any file change in that directory
# will apply to all packages that exist in that directory.
$triggeringCIYmls = $triggeringPaths | Where-Object { $_ -like "*ci*.yml" }

foreach($yml in $triggeringCIYmls) {
# given that this path is coming from the populated triggering paths in the artifact,
# we can assume that the path to the ci.yml will successfully resolve.
$ciYml = Join-Path $RepoRoot $yml
# ensure we terminate the service directory with a /
$directory = [System.IO.Path]::GetDirectoryName($ciYml).Replace("`\", "/") + "/"
$soleCIYml = (Get-ChildItem -Path $directory -Filter "ci*.yml" -File).Count -eq 1

if ($soleCIYml -and $filePath.Replace("`\", "/").StartsWith($directory)) {
if (-not $shouldInclude) {
$pkg.IncludedForValidation = $true
$shouldInclude = $true
}
break
}
else {
# if the ci.yml is not the only file in the directory, we cannot assume that any file changed within the directory that isn't the ci.yml
# should trigger this package
Write-Host "Skipping adding package for file `"$file`" because the ci yml `"$yml`" is not the only file in the service directory `"$directory`""
}
}

Expand Down Expand Up @@ -280,6 +320,7 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
# packages. We should never return NO validation.
if ($packagesWithChanges.Count -eq 0) {
$packagesWithChanges += ($allPackageProperties | Where-Object { $_.ServiceDirectory -eq "template" })
$packagesWithChanges[0].IncludedForValidation = $true
}

return $packagesWithChanges
Expand Down
2 changes: 1 addition & 1 deletion eng/common/testproxy/target_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0-dev.20241213.1
1.0.0-dev.20250221.1
73 changes: 57 additions & 16 deletions eng/tools/typespec-validation/src/rules/sdk-tspconfig-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class TspconfigParameterSubRuleBase extends TspconfigSubRuleBase {
}

class TspconfigEmitterOptionsSubRuleBase extends TspconfigSubRuleBase {
private emitterName: string;
protected emitterName: string;

constructor(emitterName: string, keyToValidate: string, expectedValue: ExpectedValueType) {
super(keyToValidate, expectedValue);
Expand Down Expand Up @@ -141,7 +141,14 @@ function isManagementSdk(folder: string): boolean {
function skipForDataPlane(folder: string): SkipResult {
return {
shouldSkip: !isManagementSdk(folder),
reason: "This rule is only applicable for management SDKs.",
reason: "This rule is only applicable for management plane SDKs.",
};
}

function skipForManagementPlane(folder: string): SkipResult {
return {
shouldSkip: isManagementSdk(folder),
reason: "This rule is only applicable for data plane SDKs.",
};
}

Expand Down Expand Up @@ -230,7 +237,43 @@ export class TspConfigTsMgmtModularPackageNameMatchPatternSubRule extends Tspcon
}
}

// ----- Go management sub rules -----
// ----- Go data plane sub rules -----
export class TspConfigGoDpServiceDirMatchPatternSubRule extends TspconfigEmitterOptionsSubRuleBase {
constructor() {
super("@azure-tools/typespec-go", "service-dir", new RegExp(/^sdk\/.*$/));
}
protected skip(_: any, folder: string) {
return skipForManagementPlane(folder);
}
}

export class TspConfigGoDpPackageDirectoryMatchPatternSubRule extends TspconfigEmitterOptionsSubRuleBase {
constructor() {
super("@azure-tools/typespec-go", "package-dir", new RegExp(/^az.*$/));
}
protected skip(_: any, folder: string) {
return skipForManagementPlane(folder);
}
}

export class TspConfigGoDpModuleMatchPatternSubRule extends TspconfigEmitterOptionsSubRuleBase {
constructor() {
super(
"@azure-tools/typespec-go",
"module",
new RegExp(/^github.com\/Azure\/azure-sdk-for-go\/.*$/),
);
}
protected validate(config: any): RuleResult {
let module = config?.options?.[this.emitterName]?.module;
if (module === undefined) return { success: true };
return super.validate(config);
}
protected skip(_: any, folder: string) {
return skipForManagementPlane(folder);
}
}

export class TspConfigGoMgmtServiceDirMatchPatternSubRule extends TspconfigEmitterOptionsSubRuleBase {
constructor() {
super("@azure-tools/typespec-go", "service-dir", new RegExp(/^sdk\/resourcemanager\/[^\/]*$/));
Expand Down Expand Up @@ -280,31 +323,26 @@ export class TspConfigGoMgmtGenerateExamplesTrueSubRule extends TspconfigEmitter
}
}

export class TspConfigGoMgmtGenerateFakesTrueSubRule extends TspconfigEmitterOptionsSubRuleBase {
export class TspConfigGoMgmtHeadAsBooleanTrueSubRule extends TspconfigEmitterOptionsSubRuleBase {
constructor() {
super("@azure-tools/typespec-go", "generate-fakes", true);
super("@azure-tools/typespec-go", "head-as-boolean", true);
}
protected skip(_: any, folder: string) {
return skipForDataPlane(folder);
}
}

export class TspConfigGoMgmtHeadAsBooleanTrueSubRule extends TspconfigEmitterOptionsSubRuleBase {
// ----- Go az sub rules -----
export class TspConfigGoAzGenerateFakesTrueSubRule extends TspconfigEmitterOptionsSubRuleBase {
constructor() {
super("@azure-tools/typespec-go", "head-as-boolean", true);
}
protected skip(_: any, folder: string) {
return skipForDataPlane(folder);
super("@azure-tools/typespec-go", "generate-fakes", true);
}
}

export class TspConfigGoMgmtInjectSpansTrueSubRule extends TspconfigEmitterOptionsSubRuleBase {
export class TspConfigGoAzInjectSpansTrueSubRule extends TspconfigEmitterOptionsSubRuleBase {
constructor() {
super("@azure-tools/typespec-go", "inject-spans", true);
}
protected skip(_: any, folder: string) {
return skipForDataPlane(folder);
}
}

// ----- Python management sub rules -----
Expand Down Expand Up @@ -386,9 +424,12 @@ export const defaultRules = [
new TspConfigGoMgmtModuleEqualStringSubRule(),
new TspConfigGoMgmtFixConstStutteringTrueSubRule(),
new TspConfigGoMgmtGenerateExamplesTrueSubRule(),
new TspConfigGoMgmtGenerateFakesTrueSubRule(),
new TspConfigGoAzGenerateFakesTrueSubRule(),
new TspConfigGoMgmtHeadAsBooleanTrueSubRule(),
new TspConfigGoMgmtInjectSpansTrueSubRule(),
new TspConfigGoAzInjectSpansTrueSubRule(),
new TspConfigGoDpServiceDirMatchPatternSubRule(),
new TspConfigGoDpPackageDirectoryMatchPatternSubRule(),
new TspConfigGoDpModuleMatchPatternSubRule(),
new TspConfigPythonMgmtPackageDirectorySubRule(),
new TspConfigPythonMgmtPackageNameEqualStringSubRule(),
new TspConfigPythonMgmtGenerateTestTrueSubRule(),
Expand Down
117 changes: 89 additions & 28 deletions eng/tools/typespec-validation/test/sdk-tspconfig-validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ import {
TspConfigGoMgmtModuleEqualStringSubRule,
TspConfigGoMgmtFixConstStutteringTrueSubRule,
TspConfigGoMgmtGenerateExamplesTrueSubRule,
TspConfigGoMgmtGenerateFakesTrueSubRule,
TspConfigGoMgmtHeadAsBooleanTrueSubRule,
TspConfigGoMgmtInjectSpansTrueSubRule,
TspConfigGoAzGenerateFakesTrueSubRule,
TspConfigGoAzInjectSpansTrueSubRule,
TspConfigGoDpModuleMatchPatternSubRule,
TspConfigGoDpPackageDirectoryMatchPatternSubRule,
TspConfigGoDpServiceDirMatchPatternSubRule,
TspConfigJavaAzPackageDirectorySubRule,
TspConfigPythonMgmtPackageDirectorySubRule,
TspConfigPythonMgmtPackageNameEqualStringSubRule,
Expand Down Expand Up @@ -105,31 +108,38 @@ function createEmitterOptionTestCases(
validValue: boolean | string,
invalidValue: boolean | string,
subRules: TspconfigSubRuleBase[],
allowUndefined: boolean = false,
): Case[] {
const cases: Case[] = [
{
description: `Validate ${emitterName}'s option:${key} with valid value ${validValue}`,
folder,
tspconfigContent: createEmitterOptionExample(emitterName, { key: key, value: validValue }),
success: true,
subRules,
},
{
description: `Validate ${emitterName}'s option:${key} with invalid value ${invalidValue}`,
folder,
tspconfigContent: createEmitterOptionExample(emitterName, { key: key, value: invalidValue }),
success: false,
subRules,
},
{
description: `Validate ${emitterName}'s option:${key} with undefined value`,
folder,
tspconfigContent: createEmitterOptionExample(emitterName),
success: false,
subRules,
},
];
if (key.includes(".")) {
const cases: Case[] = [];

cases.push({
description: `Validate ${emitterName}'s option:${key} with valid value ${validValue}`,
folder,
tspconfigContent: createEmitterOptionExample(emitterName, { key: key, value: validValue }),
success: true,
subRules,
});

cases.push({
description: `Validate ${emitterName}'s option:${key} with invalid value ${invalidValue}`,
folder,
tspconfigContent: createEmitterOptionExample(emitterName, {
key: key,
value: invalidValue,
}),
success: false,
subRules,
});

cases.push({
description: `Validate ${emitterName}'s option:${key} with undefined value`,
folder,
tspconfigContent: createEmitterOptionExample(emitterName),
success: allowUndefined ? true : false,
subRules,
});

if (!allowUndefined && key.includes(".")) {
cases.push({
description: `Validate ${emitterName}'s option:${key} with incomplete key`,
folder,
Expand Down Expand Up @@ -267,7 +277,16 @@ const goManagementGenerateFakesTestCases = createEmitterOptionTestCases(
"generate-fakes",
true,
false,
[new TspConfigGoMgmtGenerateFakesTrueSubRule()],
[new TspConfigGoAzGenerateFakesTrueSubRule()],
);

const goDpGenerateFakesTestCases = createEmitterOptionTestCases(
"@azure-tools/typespec-go",
"",
"generate-fakes",
true,
false,
[new TspConfigGoAzGenerateFakesTrueSubRule()],
);

const goManagementHeadAsBooleanTestCases = createEmitterOptionTestCases(
Expand All @@ -285,7 +304,44 @@ const goManagementInjectSpansTestCases = createEmitterOptionTestCases(
"inject-spans",
true,
false,
[new TspConfigGoMgmtInjectSpansTrueSubRule()],
[new TspConfigGoAzInjectSpansTrueSubRule()],
);

const goDpInjectSpansTestCases = createEmitterOptionTestCases(
"@azure-tools/typespec-go",
"",
"inject-spans",
true,
false,
[new TspConfigGoAzInjectSpansTrueSubRule()],
);

const goDpModuleTestCases = createEmitterOptionTestCases(
"@azure-tools/typespec-go",
"",
"module",
"github.com/Azure/azure-sdk-for-go/aaa",
"github.com/Azure/azure-sdk-for-cpp/bbb",
[new TspConfigGoDpModuleMatchPatternSubRule()],
true,
);

const goDpPackageDirTestCases = createEmitterOptionTestCases(
"@azure-tools/typespec-go",
"",
"package-dir",
"az1/2/3",
"bzasd",
[new TspConfigGoDpPackageDirectoryMatchPatternSubRule()],
);

const goDpServiceDirTestCases = createEmitterOptionTestCases(
"@azure-tools/typespec-go",
"",
"service-dir",
"sdk/2/3",
"sd/k",
[new TspConfigGoDpServiceDirMatchPatternSubRule()],
);

const javaManagementPackageDirTestCases = createEmitterOptionTestCases(
Expand Down Expand Up @@ -389,6 +445,11 @@ describe("tspconfig", function () {
...goManagementGenerateFakesTestCases,
...goManagementHeadAsBooleanTestCases,
...goManagementInjectSpansTestCases,
...goDpGenerateFakesTestCases,
...goDpInjectSpansTestCases,
...goDpModuleTestCases,
...goDpPackageDirTestCases,
...goDpServiceDirTestCases,
// java
...javaManagementPackageDirTestCases,
// python
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9180789

Please sign in to comment.