From 6bd2bb1586f5e480265a42283f823544cc4d1220 Mon Sep 17 00:00:00 2001 From: agneszitte Date: Thu, 4 Apr 2024 14:47:07 -0400 Subject: [PATCH] ci: Adjust CI Build for Doc-Only PRs validations --- build/workflow/pipeline.yml | 34 +++++---- build/workflow/stage-determine-changes.yml | 71 +++++++++++++++++++ ...dations.yml => stage-docs-validations.yml} | 0 3 files changed, 91 insertions(+), 14 deletions(-) create mode 100644 build/workflow/stage-determine-changes.yml rename build/workflow/{stage-validations.yml => stage-docs-validations.yml} (100%) diff --git a/build/workflow/pipeline.yml b/build/workflow/pipeline.yml index bfe40468d..579d0f053 100644 --- a/build/workflow/pipeline.yml +++ b/build/workflow/pipeline.yml @@ -13,12 +13,8 @@ trigger: - '/' exclude: - .dependabot/ - - .github/ - # don't trigger the CI if only docs files are changed - - doc/* - - '**/*.md' -pr: +pr: branches: include: - main @@ -33,10 +29,6 @@ pr: - '/' exclude: - .dependabot/ - - .github/ - # don't trigger the CI if only docs files are changed - - doc/* - - '**/*.md' variables: # Path where packages (nuget or app packages) will be copied to. @@ -46,18 +38,32 @@ variables: IsReleaseBranch: $[or(eq(variables['Build.SourceBranch'], 'refs/heads/main'), startsWith(variables['Build.SourceBranch'], 'refs/heads/feature/'), startsWith(variables['Build.SourceBranch'], 'refs/heads/release/'))] stages: -- stage: Validations - displayName: Validations +- stage: Determine_Changes + displayName: Determine Changes jobs: - - template: stage-validations.yml + - template: stage-determine-changes.yml + +- stage: Docs_Validations + displayName: Docs Validations + dependsOn: Determine_Changes + # Trigger this stage when docs files are changed + condition: or(eq(dependencies.Determine_Changes.outputs['evaluate_changes.DetermineChanges.docsOnly'], 'true'), eq(dependencies.Determine_Changes.outputs['evaluate_changes.DetermineChanges.mixedChanges'], 'true')) + jobs: + - template: stage-docs-validations.yml - stage: Packages - dependsOn: Validations + displayName: Packages + dependsOn: Determine_Changes + # Don't trigger this stage if only docs files are changed + condition: eq(dependencies.Determine_Changes.outputs['evaluate_changes.DetermineChanges.nonDocsOnly'], 'true') jobs: - template: stage-build-packages.yml - stage: Tests - dependsOn: Validations + displayName: Tests + dependsOn: Determine_Changes + # Don't trigger this stage if only docs files are changed + condition: eq(dependencies.Determine_Changes.outputs['evaluate_changes.DetermineChanges.nonDocsOnly'], 'true') jobs: - template: stage-uitests-wasm.yml - template: stage-build-ios.yml diff --git a/build/workflow/stage-determine-changes.yml b/build/workflow/stage-determine-changes.yml new file mode 100644 index 000000000..cc44eb6bb --- /dev/null +++ b/build/workflow/stage-determine-changes.yml @@ -0,0 +1,71 @@ +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") { + $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 diff --git a/build/workflow/stage-validations.yml b/build/workflow/stage-docs-validations.yml similarity index 100% rename from build/workflow/stage-validations.yml rename to build/workflow/stage-docs-validations.yml