Skip to content

Commit a097f96

Browse files
azure-sdksima-zhu
andauthored
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 <[email protected]>
1 parent 6e39307 commit a097f96

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

eng/common/scripts/Verify-Links.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function NormalizeUrl([string]$url){
3030
$url = "file://" + (Resolve-Path $url).ToString();
3131
}
3232

33+
Write-Verbose "The url to check against: $url."
3334
$uri = [System.Uri]$url;
3435

3536
if ($script:baseUrl -eq "") {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
param (
2+
# The root repo we scaned with.
3+
[string] $RootRepo = '$PSScriptRoot/../../..',
4+
# The target branch to compare with.
5+
[string] $targetBranch = "origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH}"
6+
)
7+
$deletedFiles = (git diff $targetBranch HEAD --name-only --diff-filter=D)
8+
$renamedFiles = (git diff $targetBranch HEAD --diff-filter=R)
9+
$changedMarkdowns = (git diff $targetBranch HEAD --name-only -- '*.md')
10+
11+
$beforeRenameFiles = @()
12+
# Retrieve the 'renamed from' files. Git command only returns back the files after rename.
13+
# In order to have the files path before rename, it has to do some regex checking.
14+
# It is better to be replaced by more reliable commands if any.
15+
foreach ($file in $renamedFiles) {
16+
if ($file -match "^rename from (.*)$") {
17+
$beforeRenameFiles += $file -replace "^rename from (.*)$", '$1'
18+
}
19+
}
20+
# A combined list of deleted and renamed files.
21+
$relativePathLinks = ($deletedFiles + $beforeRenameFiles)
22+
# Removed the deleted markdowns.
23+
$changedMarkdowns = $changedMarkdowns | Where-Object { $deletedFiles -notcontains $_ }
24+
# Scan all markdowns and find if it contains the deleted or renamed files.
25+
$markdownContainLinks = @()
26+
$allMarkdownFiles = Get-ChildItem -Path $RootRepo -Recurse -Include *.md
27+
foreach ($f in $allMarkdownFiles) {
28+
$filePath = $f.FullName
29+
$content = Get-Content -Path $filePath -Raw
30+
foreach ($l in $relativePathLinks) {
31+
if ($content -match $l) {
32+
$markdownContainLinks += $filePath
33+
break
34+
}
35+
}
36+
}
37+
38+
# Convert markdowns path of the PR to absolute path.
39+
$adjustedReadmes = $changedMarkdowns | Foreach-Object { Resolve-Path $_ }
40+
$markdownContainLinks += $adjustedReadmes
41+
42+
# Get rid of any duplicated ones.
43+
$allMarkdowns = [string[]]($markdownContainLinks | Sort-Object | Get-Unique)
44+
45+
Write-Host "Here are all markdown files we need to check based on the changed files:"
46+
foreach ($file in $allMarkdowns) {
47+
Write-Host " $file"
48+
}
49+
return $allMarkdowns

0 commit comments

Comments
 (0)