Skip to content

Commit

Permalink
Some basic changes to preproces
Browse files Browse the repository at this point in the history
  • Loading branch information
sima-zhu committed Nov 5, 2020
1 parent 8af4f79 commit 6e15d74
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
17 changes: 16 additions & 1 deletion eng/common/pipelines/templates/steps/verify-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,29 @@ parameters:
BranchReplacementName: "${env:SYSTEM_PULLREQUEST_SOURCECOMMITID}"

steps:
- pwsh:
$deleted = git ls-files --deleted
echo "##vso[task.setvariable variable=deletedFiles]$deleted"
displayName: Retrieved deleted files
workingDirectory: '${{ parameters.WorkingDirectory }}'
- task: PowerShell@2
displayName: Retrieved all markdowns to scan
inputs:
pwsh: true
workingDirectory: '${{ parameters.WorkingDirectory }}'
filePath: ${{ parameters.ScriptDirectory }}/Scan-files-against-links.ps1
arguments: >
-gitUrl: $(Build.Repository.Uri)
-link $(deletedFiles)
-changedMarkdowns ${{ parameters.Urls }}
- task: PowerShell@2
displayName: Link verification check
inputs:
pwsh: true
workingDirectory: '${{ parameters.WorkingDirectory }}/${{ parameters.Directory }}'
filePath: ${{ parameters.ScriptDirectory }}/Verify-Links.ps1
arguments: >
-urls ${{ parameters.Urls }}
-urls $(markdownsToScan)
-rootUrl "file://${{ parameters.WorkingDirectory }}/${{ parameters.Directory }}"
-recursive: ${{ parameters.Recursive }}
-ignoreLinksFile ${{ parameters.IgnoreLinksFile }}
Expand Down
23 changes: 23 additions & 0 deletions eng/common/scripts/Scan-files-against-links.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
param (
[string] $gitUrl,
# These are the files relative paths which has been deleted from PR. Need to scan whether any markdowns include these links
[string[]] $links,
[string[]] $changedMarkdowns
)
$fullPathLinks = @()
foreach ($link in $links) {
$fullPathLinks += ($gitUrl + $link)
}

$urls = @()
foreach ($f in (Get-ChildItem -Path ./ -Recurse -Include *.md)) {
foreach($l in fullPathLinks) {
$content = Get-Content -Path $f -Raw
if ($content -match $l) {
$urls += $f
break
}
}
}
$urls += (git diff origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH} HEAD --name-only -- '*.md' | Get-Unique)
echo "##vso[task.setvariable variable=markdownsToScan]$urls"

0 comments on commit 6e15d74

Please sign in to comment.