forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync eng/common directory with azure-sdk-tools for PR 1170 (Azure#17276)
* Added the preprocess scripts. * string array to string Co-authored-by: Sima Zhu <sizhu@microsoft.com>
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
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
49 changes: 49 additions & 0 deletions
49
eng/common/scripts/get-markdown-files-from-changed-files.ps1
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,49 @@ | ||
param ( | ||
# The root repo we scaned with. | ||
[string] $RootRepo = '$PSScriptRoot/../../..', | ||
# The target branch to compare with. | ||
[string] $targetBranch = "origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH}" | ||
) | ||
$deletedFiles = (git diff $targetBranch HEAD --name-only --diff-filter=D) | ||
$renamedFiles = (git diff $targetBranch HEAD --diff-filter=R) | ||
$changedMarkdowns = (git diff $targetBranch HEAD --name-only -- '*.md') | ||
|
||
$beforeRenameFiles = @() | ||
# Retrieve the 'renamed from' files. Git command only returns back the files after rename. | ||
# In order to have the files path before rename, it has to do some regex checking. | ||
# It is better to be replaced by more reliable commands if any. | ||
foreach ($file in $renamedFiles) { | ||
if ($file -match "^rename from (.*)$") { | ||
$beforeRenameFiles += $file -replace "^rename from (.*)$", '$1' | ||
} | ||
} | ||
# A combined list of deleted and renamed files. | ||
$relativePathLinks = ($deletedFiles + $beforeRenameFiles) | ||
# Removed the deleted markdowns. | ||
$changedMarkdowns = $changedMarkdowns | Where-Object { $deletedFiles -notcontains $_ } | ||
# Scan all markdowns and find if it contains the deleted or renamed files. | ||
$markdownContainLinks = @() | ||
$allMarkdownFiles = Get-ChildItem -Path $RootRepo -Recurse -Include *.md | ||
foreach ($f in $allMarkdownFiles) { | ||
$filePath = $f.FullName | ||
$content = Get-Content -Path $filePath -Raw | ||
foreach ($l in $relativePathLinks) { | ||
if ($content -match $l) { | ||
$markdownContainLinks += $filePath | ||
break | ||
} | ||
} | ||
} | ||
|
||
# Convert markdowns path of the PR to absolute path. | ||
$adjustedReadmes = $changedMarkdowns | Foreach-Object { Resolve-Path $_ } | ||
$markdownContainLinks += $adjustedReadmes | ||
|
||
# Get rid of any duplicated ones. | ||
$allMarkdowns = [string[]]($markdownContainLinks | Sort-Object | Get-Unique) | ||
|
||
Write-Host "Here are all markdown files we need to check based on the changed files:" | ||
foreach ($file in $allMarkdowns) { | ||
Write-Host " $file" | ||
} | ||
return $allMarkdowns |