-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Adjust CI Build for Doc-Only PRs validations
- Loading branch information
1 parent
d2eb75c
commit 9ae36f1
Showing
2 changed files
with
82 additions
and
20 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,69 @@ | ||
jobs: | ||
- job: evaluate_changes | ||
displayName: 'Check for Doc Only Changes' | ||
pool: | ||
vmImage: 'ubuntu-latest' | ||
steps: | ||
- powershell: | | ||
# Determine the context of the build (PR or push) and fetch the target branch if necessary | ||
$prTargetBranch = "$(System.PullRequest.TargetBranch)" | ||
$isPR = -not [string]::IsNullOrWhiteSpace($prTargetBranch) | ||
$defaultBaseBranch = "master" | ||
Write-Host "Build context determined: $(if ($isPR) { 'Pull Request' } else { 'Push' })" | ||
if ($isPR) { | ||
Write-Host "It's a PR build. Fetching the target branch ($defaultBaseBranch)..." | ||
git fetch origin $defaultBaseBranch | ||
$mergeBase = git merge-base HEAD "origin/$defaultBaseBranch" | ||
Write-Host "Merge base identified at $mergeBase" | ||
} else { | ||
Write-Host "It's a push build. Finding the most recent common ancestor with $defaultBaseBranch..." | ||
git fetch origin $defaultBaseBranch | ||
$mergeBase = git merge-base HEAD "origin/$defaultBaseBranch" | ||
Write-Host "Merge base for push build identified at $mergeBase" | ||
} | ||
Write-Host "Comparing changes from $mergeBase..." | ||
$gitDiffCommand = "git diff $mergeBase --name-only" | ||
$changedFiles = Invoke-Expression $gitDiffCommand | ||
$docsOnly = $true | ||
$nonDocsOnly = $false | ||
$mixedChanges = $false | ||
if ($changedFiles) { | ||
Write-Host "Changed files:" | ||
Write-Host $changedFiles | ||
} else { | ||
Write-Host "No files have changed." | ||
} | ||
foreach ($file in $changedFiles -split "`n") { | ||
if ($file.EndsWith(".md") -or $file -like "*/toc.yml") { | ||
if ($nonDocsOnly) { | ||
$mixedChanges = $true | ||
$docsOnly = $false | ||
break | ||
} | ||
} else { | ||
$nonDocsOnly = $true | ||
if ($docsOnly) { | ||
$docsOnly = $false | ||
$mixedChanges = $true | ||
} else { | ||
break | ||
} | ||
} | ||
} | ||
if ($docsOnly) { | ||
Write-Host "All changes are documentation-only." | ||
} elseif ($mixedChanges) { | ||
Write-Host "Mixed changes detected: Both documentation and non-documentation files have been modified." | ||
} else { | ||
Write-Host "Non-documentation changes detected." | ||
} | ||
# Output the results as pipeline variables | ||
Write-Host "##vso[task.setvariable variable=docsOnly]$docsOnly" | ||
Write-Host "##vso[task.setvariable variable=nonDocsOnly]$nonDocsOnly" | ||
Write-Host "##vso[task.setvariable variable=mixedChanges]$mixedChanges" |