-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run apiview checks in pr to detect public api changes (#3283)
- Loading branch information
Showing
25 changed files
with
1,994 additions
and
73 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
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 -or ($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
40 changes: 40 additions & 0 deletions
40
eng/emitters/pipelines/templates/jobs/detect-api-changes.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
parameters: | ||
Artifacts: [] | ||
BuildArtifactName: "" | ||
LanguageShortName: "Unknown" | ||
DependsOn: "" | ||
|
||
jobs: | ||
- job: DetectApiChanges | ||
dependsOn: ${{ parameters.DependsOn }} | ||
pool: | ||
name: $(LINUXPOOL) | ||
image: $(LINUXVMIMAGE) | ||
os: linux | ||
steps: | ||
- download: current | ||
artifact: ${{ parameters.BuildArtifactName }} | ||
displayName: Download build artifacts | ||
- pwsh: | | ||
$apiChangeDetectRequestUrl = "https://apiview.dev/PullRequest/DetectApiChanges" | ||
echo "##vso[task.setvariable variable=ApiChangeDetectRequestUrl]$apiChangeDetectRequestUrl" | ||
displayName: "Set API change detect request URL" | ||
condition: eq(variables['ApiChangeDetectRequestUrl'], '') | ||
- task: Powershell@2 | ||
inputs: | ||
filePath: $(Build.SourcesDirectory)/eng/emitters/scripts/Detect-Api-Changes.ps1 | ||
arguments: > | ||
-ArtifactList ('${{ convertToJson(parameters.Artifacts) }}' | ConvertFrom-Json | Select-Object Name) | ||
-ArtifactPath $(Agent.BuildDirectory)/${{ parameters.BuildArtifactName }} | ||
-CommitSha '$(Build.SourceVersion)' | ||
-BuildId $(Build.BuildId) | ||
-PullRequestNumber $(System.PullRequest.PullRequestNumber) | ||
-RepoFullName $(Build.Repository.Name) | ||
-APIViewUri $(ApiChangeDetectRequestUrl) | ||
-BuildArtifactName ${{ parameters.BuildArtifactName }} | ||
-DevopsProject $(System.TeamProject) | ||
-LanguageShortName ${{ parameters.LanguageShortName }} | ||
pwsh: true | ||
displayName: Detect API changes | ||
condition: and(succeededOrFailed(), eq(variables['Build.Reason'],'PullRequest')) |
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.