-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Add Support for Changed Spec Identification in spec-gen-sdk-runner tool #32763
Open
raych1
wants to merge
6
commits into
main
Choose a base branch
from
user/raych1/support-git-op
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+443
−20
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d01682b
Increase timeout for generation job
raych1 886a0f4
increase timeout to 60 hours
raych1 ec42f9b
Added git op to the wrapper tool
raych1 c008111
clean all files before generation
raych1 d2b361a
update specGenCommand for multiple generation
raych1 8d11f9c
Log successful info in else
raych1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import path from "node:path"; | ||
Check failure on line 1 in eng/tools/spec-gen-sdk-runner/src/change-files.ts
|
||
import { | ||
execAsync, | ||
getChangedFiles, | ||
searchRelatedParentFolders, | ||
searchRelatedTypeSpecProjectBySharedLibrary, | ||
searchSharedLibrary, | ||
} from "./utils.js"; | ||
import { logMessage } from "./log.js"; | ||
import { SpecGenSdkCmdInput } from "./types.js"; | ||
|
||
const readmeMdRegex = /^readme.md$/; | ||
const typespecProjectRegex = /^tspconfig.yaml$/; | ||
const typespecProjectSharedLibraryRegex = /[^/]+\.Shared/; | ||
|
||
type ChangedSpecs = { | ||
[K in "readmeMd" | "typespecProject"]?: string; | ||
} & { | ||
specs: string[]; | ||
}; | ||
|
||
export async function detectChangedSpecConfigFiles( | ||
commandInput: SpecGenSdkCmdInput, | ||
): Promise<ChangedSpecs[]> { | ||
const prChangedFiles: string[] = getChangedFiles(commandInput.localSpecRepoPath) ?? []; | ||
if (prChangedFiles.length === 0) { | ||
logMessage("No files changed in the PR"); | ||
} | ||
logMessage(`Changed files in the PR: ${prChangedFiles.length}`); | ||
const fileList = prChangedFiles.filter((p) => !p.includes("/scenarios/")); | ||
const { stdout: headCommitRaw } = await execAsync("git rev-parse HEAD"); | ||
const headCommit = headCommitRaw.trim(); // Trim any newline characters | ||
const { stdout: treeIdRaw } = await execAsync(`git rev-parse ${headCommit}^{tree}`); | ||
const treeId = treeIdRaw.trim(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we looking at git here? We should just be using the files on disk and assume that repo is correctly checked out. |
||
|
||
logMessage(`Related readme.md and typespec project list:`); | ||
const changedSpecs: ChangedSpecs[] = []; | ||
const readmeMDResult = await searchRelatedParentFolders(fileList, { | ||
searchFileRegex: readmeMdRegex, | ||
specFolder: commandInput.localSpecRepoPath, | ||
treeId, | ||
}); | ||
const typespecProjectResult = await searchRelatedParentFolders(fileList, { | ||
searchFileRegex: typespecProjectRegex, | ||
specFolder: commandInput.localSpecRepoPath, | ||
treeId, | ||
}); | ||
const typespecProjectSharedLibraries = searchSharedLibrary(fileList, { | ||
searchFileRegex: typespecProjectSharedLibraryRegex, | ||
specFolder: commandInput.localSpecRepoPath, | ||
treeId, | ||
}); | ||
const typespecProjectResultSearchedBySharedLibrary = | ||
await searchRelatedTypeSpecProjectBySharedLibrary(typespecProjectSharedLibraries, { | ||
searchFileRegex: typespecProjectRegex, | ||
specFolder: commandInput.localSpecRepoPath, | ||
treeId, | ||
}); | ||
for (const folderPath of Object.keys(typespecProjectResultSearchedBySharedLibrary)) { | ||
if (typespecProjectResult[folderPath]) { | ||
typespecProjectResult[folderPath] = [ | ||
...typespecProjectResult[folderPath], | ||
...typespecProjectResultSearchedBySharedLibrary[folderPath], | ||
]; | ||
} else { | ||
typespecProjectResult[folderPath] = typespecProjectResultSearchedBySharedLibrary[folderPath]; | ||
} | ||
} | ||
const result: { [folderPath: string]: string[] } = {}; | ||
for (const folderPath of Object.keys(readmeMDResult)) { | ||
result[folderPath] = readmeMDResult[folderPath]; | ||
} | ||
|
||
for (const folderPath of Object.keys(typespecProjectResult)) { | ||
result[folderPath] = typespecProjectResult[folderPath]; | ||
} | ||
for (const folderPath of Object.keys(result)) { | ||
const readmeMdPath = path.join(folderPath, "readme.md"); | ||
const cs: ChangedSpecs = { | ||
readmeMd: readmeMdPath, | ||
specs: readmeMDResult[folderPath], | ||
}; | ||
|
||
if (typespecProjectResult[folderPath]) { | ||
delete cs.readmeMd; | ||
cs.specs = typespecProjectResult[folderPath]; | ||
cs.typespecProject = path.join(folderPath, "tspconfig.yaml"); | ||
logMessage(`\t tspconfig.yaml file: ${cs.typespecProject}`); | ||
} else { | ||
logMessage(`\t readme.md file: ${readmeMdPath}`); | ||
} | ||
changedSpecs.push(cs); | ||
} | ||
|
||
return changedSpecs; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is special about "scenarios" here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We intend to exclude SDK generation for changes coming from the
scenarios
folder.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are also other paths like examples should those be included? I'm mostly asking this question as it seems a little odd to only figure out this one folder type if what you are looking for is json files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some other file types also need to be included, such as
*.tsp, tspconfig.yaml, readme.md
.Changes in the
examples
folder would need to trigger the automation run because samples would be used in the SDK test/sample generation step. I am not aware of any other folders we might have in the specification folder. I will also add 'specification' to the filter.