-
Notifications
You must be signed in to change notification settings - Fork 27
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
3a02247
commit 5853f22
Showing
3 changed files
with
95 additions
and
14 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,75 @@ | ||
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 set the target branch accordingly | ||
$prTargetBranch = "$(System.PullRequest.TargetBranch)" | ||
$isPR = -not [string]::IsNullOrWhiteSpace($prTargetBranch) | ||
# Normalize the target branch name for PR builds or default to 'main' for push builds | ||
$targetBranchName = $isPR ? $prTargetBranch -replace 'refs/heads/', '' : "main" | ||
Write-Host "Build context determined: $(if ($isPR) { 'Pull Request targeting ' + $targetBranchName } else { 'Push' })" | ||
# Fetch the target or default base branch and determine the merge base | ||
git fetch origin $targetBranchName | ||
$mergeBase = git merge-base HEAD "origin/$targetBranchName" | ||
Write-Host "Merge base with '$targetBranchName' identified at $mergeBase" | ||
Write-Host "Comparing changes from $mergeBase..." | ||
$gitDiffCommand = "git diff $mergeBase --name-only" | ||
$changedFiles = Invoke-Expression $gitDiffCommand | ||
$docsOnly = $false | ||
$nonDocsOnly = $false | ||
$mixedChanges = $false | ||
$docFiles = 0 | ||
$nonDocFiles = 0 | ||
if ($changedFiles) { | ||
Write-Host "Changed files:" | ||
Write-Host $changedFiles | ||
} else { | ||
Write-Host "No files have changed." | ||
} | ||
foreach ($file in $changedFiles -split "`n") { | ||
# Identifying changes as documentation if they occur: | ||
# Within the doc folder, or | ||
# Are Markdown files at the root level (with no subdirectories involved), or | ||
# Are Markdown files within the .github folder (including its subdirectories) | ||
$isDoc = $file.StartsWith("doc/") -or ($file -match "^[^/]+\.md$") -or ($file -match "^\.github/.*\.md$") | ||
if ($isDoc) { | ||
$docFiles++ | ||
} else { | ||
$nonDocFiles++ | ||
} | ||
} | ||
Write-Host "Documentation files changed: $docFiles" | ||
Write-Host "Non-documentation files changed: $nonDocFiles" | ||
if ($docFiles -gt 0 -and $nonDocFiles -eq 0) { | ||
$docsOnly = $true | ||
Write-Host "All changes are documentation-only." | ||
} elseif ($docFiles -gt 0 -and $nonDocFiles -gt 0) { | ||
$mixedChanges = $true | ||
Write-Host "Mixed changes detected: Both documentation and non-documentation files have been modified." | ||
} elseif ($nonDocFiles -gt 0) { | ||
$nonDocsOnly = $true | ||
Write-Host "Non-documentation changes detected." | ||
} | ||
# Explicitly write the final values for clarity | ||
Write-Host "Final values:" | ||
Write-Host "docsOnly: $docsOnly" | ||
Write-Host "nonDocsOnly: $nonDocsOnly" | ||
Write-Host "mixedChanges: $mixedChanges" | ||
# Output the results as pipeline variables | ||
Write-Host "##vso[task.setvariable variable=docsOnly;isOutput=true]$docsOnly" | ||
Write-Host "##vso[task.setvariable variable=nonDocsOnly;isOutput=true]$nonDocsOnly" | ||
Write-Host "##vso[task.setvariable variable=mixedChanges;isOutput=true]$mixedChanges" | ||
name: DetermineChanges |
File renamed without changes.