forked from Azure/azure-sdk-for-js
-
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 2861 (Azure#20837)
* Use common script for git diff changes * remove extra files * suppress spell check * suppress false positive cspelling * Address comments * make changes to cspell * Suppress to right values * More fix Co-authored-by: sima-zhu <[email protected]>
- Loading branch information
Showing
9 changed files
with
110 additions
and
103 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
18 changes: 9 additions & 9 deletions
18
eng/common/pipelines/templates/steps/eng-common-workflow-enforcer.yml
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
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,38 @@ | ||
# cSpell:ignore Committish | ||
# cSpell:ignore PULLREQUEST | ||
# cSpell:ignore TARGETBRANCH | ||
# cSpell:ignore SOURCECOMMITID | ||
function Get-ChangedFiles { | ||
param ( | ||
[string]$SourceCommittish= "${env:SYSTEM_PULLREQUEST_SOURCECOMMITID}", | ||
[string]$TargetCommittish = ("origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH}" -replace "refs/heads/"), | ||
[string]$DiffPath, | ||
[string]$DiffFilterType = "d" | ||
) | ||
# If ${env:SYSTEM_PULLREQUEST_TARGETBRANCH} is empty, then return empty. | ||
if ($TargetCommittish -eq "origin/") { | ||
Write-Host "There is no target branch passed in. " | ||
return "" | ||
} | ||
|
||
# Add config to disable the quote and encoding on file name. | ||
# Ref: https://github.com/msysgit/msysgit/wiki/Git-for-Windows-Unicode-Support#disable-quoted-file-names | ||
# Ref: https://github.com/msysgit/msysgit/wiki/Git-for-Windows-Unicode-Support#disable-commit-message-transcoding | ||
# Git PR diff: https://docs.github.com/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-comparing-branches-in-pull-requests#three-dot-and-two-dot-git-diff-comparisons | ||
$command = "git -c core.quotepath=off -c i18n.logoutputencoding=utf-8 diff `"$TargetCommittish...$SourceCommittish`" --name-only --diff-filter=$DiffFilterType" | ||
if ($DiffPath) { | ||
$command = $command + " -- `'$DiffPath`'" | ||
} | ||
Write-Host $command | ||
$changedFiles = Invoke-Expression -Command $command | ||
if(!$changedFiles) { | ||
Write-Host "No changed files in git diff between $TargetCommittish and $SourceCommittish" | ||
} | ||
else { | ||
Write-Host "Here are the diff files:" | ||
foreach ($file in $changedFiles) { | ||
Write-Host " $file" | ||
} | ||
} | ||
return $changedFiles | ||
} |
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
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,40 @@ | ||
|
||
# cSpell:ignore Committish | ||
# cSpell:ignore committish | ||
# cSpell:ignore PULLREQUEST | ||
# cSpell:ignore TARGETBRANCH | ||
# cSpell:ignore SOURCECOMMITID | ||
# cSpell:ignore elete | ||
# cSpell:ignore ename | ||
<# | ||
.SYNOPSIS | ||
Returns git diff changes in pull request. | ||
.DESCRIPTION | ||
The script is to return diff changes in pull request. | ||
.PARAMETER SourceCommittish | ||
The branch committish PR merges from. | ||
Definition of committish: https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefcommit-ishacommit-ishalsocommittish | ||
.PARAMETER TargetCommittish | ||
The branch committish PR targets to merge into. | ||
.PARAMETER DiffPath | ||
The files which git diff to scan against. Support regex match. E.g. "eng/common/*", "*.md" | ||
.PARAMETER DiffFilterType | ||
The filter type A(a)dd, D(d)elete, R(r)ename, U(u)pate. | ||
E.g. 'ad' means filter out the newly added file and deleted file | ||
E.g. '' means no filter on file mode. | ||
#> | ||
[CmdletBinding()] | ||
param ( | ||
[string] $SourceCommittish = "${env:SYSTEM_PULLREQUEST_SOURCECOMMITID}", | ||
[string] $TargetCommittish = ("origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH}" -replace "refs/heads/"), | ||
[string] $DiffPath = "", | ||
[string] $DiffFilterType = 'd' | ||
) | ||
|
||
Set-StrictMode -Version 3 | ||
. (Join-Path $PSScriptRoot common.ps1) | ||
|
||
return Get-ChangedFiles -SourceCommittish $SourceCommittish ` | ||
-TargetCommittish $TargetCommittish ` | ||
-DiffPath $DiffPath ` | ||
-DiffFilterType $DiffFilterType |
48 changes: 6 additions & 42 deletions
48
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 |
---|---|---|
@@ -1,49 +1,13 @@ | ||
# cSpell:ignore Committish | ||
# cSpell:ignore PULLREQUEST | ||
# cSpell:ignore TARGETBRANCH | ||
param ( | ||
# The root repo we scaned with. | ||
# The root repo we scanned with. | ||
[string] $RootRepo = '$PSScriptRoot/../../..', | ||
# The target branch to compare with. | ||
[string] $targetBranch = ("origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH}" -replace "/refs/heads/") | ||
) | ||
$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 | ||
} | ||
} | ||
} | ||
. (Join-Path $PSScriptRoot common.ps1) | ||
|
||
# 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 | ||
return Get-ChangedFiles -TargetCommittish $targetBranch -DiffPath '*.md' |
This file was deleted.
Oops, something went wrong.