Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 0 additions & 4 deletions eng/pipelines/spec-gen-sdk.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
parameters:
- name: SdkRepoCommit
type: string
Expand Down Expand Up @@ -31,10 +31,6 @@
displayName: 'Skip SDK pull request creation'

trigger: none
pr:
paths:
include:
- specification/**

extends:
template: /eng/pipelines/templates/stages/archetype-spec-gen-sdk.yml
Expand Down
32 changes: 30 additions & 2 deletions eng/tools/spec-gen-sdk-runner/src/command-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
Expand Down Expand Up @@ -283,6 +283,9 @@
* @param breakingChangeLabel - The breaking change label.
* @param hasBreakingChange - A flag indicating whether there are breaking changes.
* @param hasManagementPlaneSpecs - A flag indicating whether there are management plane specs.
* @param stagedArtifactsFolder - The staged artifacts folder.
* @param apiViewRequestData - The API view request data.
* @param sdkGenerationExecuted - A flag indicating whether the SDK generation was executed.
* @returns the run status code.
*/
export function generateArtifact(
Expand All @@ -293,6 +296,7 @@
hasManagementPlaneSpecs: boolean,
stagedArtifactsFolder: string,
apiViewRequestData: APIViewRequestData[],
sdkGenerationExecuted: boolean = true,
): number {
const specGenSdkArtifactName = "spec-gen-sdk-artifact";
const specGenSdkArtifactFileName = specGenSdkArtifactName + ".json";
Expand All @@ -305,13 +309,20 @@
if (!fs.existsSync(specGenSdkArtifactAbsoluteFolder)) {
fs.mkdirSync(specGenSdkArtifactAbsoluteFolder, { recursive: true });
}
let isSpecGenSdkCheckRequired = false;
if (sdkGenerationExecuted) {
isSpecGenSdkCheckRequired = getRequiredSettingValue(
hasManagementPlaneSpecs,
commandInput.sdkLanguage as SdkName,
);
}

// Write artifact
const artifactInfo: SpecGenSdkArtifactInfo = {
language: commandInput.sdkLanguage,
result,
labelAction: hasBreakingChange,
isSpecGenSdkCheckRequired:
hasManagementPlaneSpecs && SpecGenSdkRequiredSettings[commandInput.sdkLanguage as SdkName],
isSpecGenSdkCheckRequired,
apiViewRequestData: apiViewRequestData,
};
fs.writeFileSync(
Expand Down Expand Up @@ -348,3 +359,20 @@
}
return specConfigPath;
}

/**
* Get the required setting value for the SDK check based on the spec PR types.
* @param hasManagementPlaneSpecs - A flag indicating whether there are management plane specs.
* @param sdkName - The SDK name.
* @returns boolean indicating whether the SDK check is required.
*/
export function getRequiredSettingValue(
hasManagementPlaneSpecs: boolean,
sdkName: SdkName,
): boolean {
if (hasManagementPlaneSpecs) {
return SpecGenSdkRequiredSettings[sdkName].managementPlane;
} else {
return SpecGenSdkRequiredSettings[sdkName].dataPlane;
}
}
7 changes: 7 additions & 0 deletions eng/tools/spec-gen-sdk-runner/src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import fs from "node:fs";
import path from "node:path";
import { runSpecGenSdkCommand, resetGitRepo, SpecConfigs } from "./utils.js";
Expand Down Expand Up @@ -90,11 +90,17 @@
let hasManagementPlaneSpecs = false;
let overallRunHasBreakingChange = false;
let currentRunHasBreakingChange = false;
let sdkGenerationExecuted = true;
let overallExecutionResult = "";
let currentExecutionResult = "";
let stagedArtifactsFolder = "";
const apiViewRequestData: APIViewRequestData[] = [];

if (changedSpecs.length === 0) {
sdkGenerationExecuted = false;
overallExecutionResult = "succeeded";
}

for (const changedSpec of changedSpecs) {
if (!changedSpec.typespecProject && !changedSpec.readmeMd) {
logMessage("Runner: no spec config file found in the changed files", LogLevel.Warn);
Expand Down Expand Up @@ -179,6 +185,7 @@
hasManagementPlaneSpecs,
stagedArtifactsFolder,
apiViewRequestData,
sdkGenerationExecuted,
) || statusCode;
return statusCode;
}
Expand Down
4 changes: 4 additions & 0 deletions eng/tools/spec-gen-sdk-runner/src/spec-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import path from "node:path";
import {
getChangedFiles,
Expand Down Expand Up @@ -31,6 +31,10 @@
.filter((p) => p.startsWith("specification/"))
.filter((p) => !p.includes("/scenarios/"));

if (fileList.length === 0) {
logMessage("No relevant files changed under 'specification' folder in the PR");
return [];
}
logMessage(`Related readme.md and typespec project list:`);
const changedSpecs: ChangedSpecs[] = [];

Expand Down
44 changes: 37 additions & 7 deletions eng/tools/spec-gen-sdk-runner/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/**
* Represents the input parameters required for spec-gen-sdk command execution.
*/
Expand Down Expand Up @@ -46,7 +46,7 @@
result: string;
labelAction?: boolean;
isSpecGenSdkCheckRequired: boolean;
apiViewRequestData: APIViewRequestData [];
apiViewRequestData: APIViewRequestData[];
}

/**
Expand All @@ -59,13 +59,43 @@
| "azure-sdk-for-net"
| "azure-sdk-for-python";

/**
* Represents the plane types for SDK generation settings
*/
export interface PlaneTypeSettings {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, I will enhance this type when need to support the separation of TypeSpec and OpenAPI specs.

/**
* Whether spec-gen-sdk check is required for data plane
*/
dataPlane: boolean;

/**
* Whether spec-gen-sdk check is required for management plane
*/
managementPlane: boolean;
}

/**
* Required check settings for all languages.
*/
export const SpecGenSdkRequiredSettings: Record<SdkName, boolean> = {
"azure-sdk-for-go": true,
"azure-sdk-for-java": true,
"azure-sdk-for-js": false,
"azure-sdk-for-net": false,
"azure-sdk-for-python": true,
export const SpecGenSdkRequiredSettings: Record<SdkName, PlaneTypeSettings> = {
"azure-sdk-for-go": {
dataPlane: true,
managementPlane: true,
},
"azure-sdk-for-java": {
dataPlane: false,
managementPlane: true,
},
"azure-sdk-for-js": {
dataPlane: false,
managementPlane: false,
},
"azure-sdk-for-net": {
dataPlane: false,
managementPlane: false,
},
"azure-sdk-for-python": {
dataPlane: true,
managementPlane: true,
},
};
File renamed without changes.
Loading