From c804b2d2fbda04cd29c0cd9b897df72c878649b7 Mon Sep 17 00:00:00 2001 From: agneszitte Date: Wed, 27 Mar 2024 21:07:05 -0400 Subject: [PATCH 1/3] ci: Adjust CI Build for Doc-Only PRs validations --- azure-pipelines.yml | 30 +++++--- build/stage-determine-changes.yml | 70 +++++++++++++++++++ ...dations.yml => stage-docs-validations.yml} | 0 3 files changed, 89 insertions(+), 11 deletions(-) create mode 100644 build/stage-determine-changes.yml rename build/{stage-validations.yml => stage-docs-validations.yml} (100%) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 61b3d6e97..356c3ca4c 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -12,9 +12,6 @@ - '/' exclude: - .github/ - # don't trigger the CI if only docs files are changed - - doc/* - - '**/*.md' pr: branches: @@ -30,9 +27,6 @@ pr: - '/' exclude: - .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. @@ -49,18 +43,32 @@ variables: # AndroidNdkDirectory: C:\Microsoft\AndroidNDK64\android-ndk-r16b stages: -- stage: Validations - displayName: Validations +- stage: Determine_Changes + displayName: Determine Changes jobs: - - template: build/stage-validations.yml + - template: build/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: build/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: build/stage-build-packages.yml - stage: Build_Samples - dependsOn: Validations + displayName: Build Samples + 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: build/stage-build-ios.yml - template: build/stage-build-android.yml diff --git a/build/stage-determine-changes.yml b/build/stage-determine-changes.yml new file mode 100644 index 000000000..48d28ff44 --- /dev/null +++ b/build/stage-determine-changes.yml @@ -0,0 +1,70 @@ +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 'master' for push builds + $targetBranchName = $isPR ? $prTargetBranch -replace 'refs/heads/', '' : "master" + + 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") { + if ($file.EndsWith(".md") -or $file -like "*/toc.yml") { + $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 \ No newline at end of file diff --git a/build/stage-validations.yml b/build/stage-docs-validations.yml similarity index 100% rename from build/stage-validations.yml rename to build/stage-docs-validations.yml From d73c83d4ee6b5c39fa23f05ff71f0c3e42735c04 Mon Sep 17 00:00:00 2001 From: agneszitte Date: Tue, 2 Apr 2024 16:59:07 -0400 Subject: [PATCH 2/3] ci: Adjust CI Build for Doc-Only PRs validations with adjustments to be more directory based --- azure-pipelines.yml | 14 +------------- build/stage-determine-changes.yml | 7 ++++--- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 356c3ca4c..d360e4358 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -7,13 +7,7 @@ - legacy/* - feature/* - paths: - include: - - '/' - exclude: - - .github/ - -pr: +pr: branches: include: - master @@ -22,12 +16,6 @@ pr: - legacy/* - feature/* - paths: - include: - - '/' - exclude: - - .github/ - variables: # Path where packages (nuget or app packages) will be copied to. PackageOutputPath: $(Build.ArtifactStagingDirectory) diff --git a/build/stage-determine-changes.yml b/build/stage-determine-changes.yml index 48d28ff44..83e82523b 100644 --- a/build/stage-determine-changes.yml +++ b/build/stage-determine-changes.yml @@ -11,7 +11,6 @@ jobs: # Normalize the target branch name for PR builds or default to 'master' for push builds $targetBranchName = $isPR ? $prTargetBranch -replace 'refs/heads/', '' : "master" - 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 @@ -36,7 +35,9 @@ jobs: } foreach ($file in $changedFiles -split "`n") { - if ($file.EndsWith(".md") -or $file -like "*/toc.yml") { + $isDoc = $file.StartsWith("doc/") -or $file -match "^.*/?[^/]*\.md$" -or $file.StartsWith(".github/") + + if ($isDoc) { $docFiles++ } else { $nonDocFiles++ @@ -67,4 +68,4 @@ jobs: 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 \ No newline at end of file + name: DetermineChanges From 33a1302cbe35a8c02557293575a3147f840c0802 Mon Sep 17 00:00:00 2001 From: agneszitte Date: Wed, 3 Apr 2024 15:59:29 -0400 Subject: [PATCH 3/3] ci: Adjust the regex patterns to identify changes for documentation if they occur within the doc folder, are Markdown files at the root level (with no subdirectories involved), or are Markdown files within the .github folder (including its subdirectories) --- azure-pipelines.yml | 2 +- build/stage-determine-changes.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index d360e4358..551883c0b 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -7,7 +7,7 @@ - legacy/* - feature/* -pr: +pr: branches: include: - master diff --git a/build/stage-determine-changes.yml b/build/stage-determine-changes.yml index 83e82523b..6f1394fd2 100644 --- a/build/stage-determine-changes.yml +++ b/build/stage-determine-changes.yml @@ -35,7 +35,7 @@ jobs: } foreach ($file in $changedFiles -split "`n") { - $isDoc = $file.StartsWith("doc/") -or $file -match "^.*/?[^/]*\.md$" -or $file.StartsWith(".github/") + $isDoc = $file.StartsWith("doc/") -or ($file -match "^[^/]+\.md$") -or ($file -match "^\.github/.*\.md$") if ($isDoc) { $docFiles++