Skip to content

Commit 4599f4e

Browse files
authored
Merge pull request #657 from unoplatform/dev/agzi/AdjustSamplesListForUnoAndSyncReadMe
docs: Adjust samples list to make it available for the main Uno doc, ReadMe & add ci build stages
2 parents a05ae97 + 91bd094 commit 4599f4e

9 files changed

+686
-585
lines changed

.azure-pipelines.BuildMatrix.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

.vsts-ci.yml

Lines changed: 37 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,37 @@
1-
jobs:
2-
- job: VS_Latest
3-
timeoutInMinutes: 600
4-
5-
pool:
6-
vmImage: windows-2022
7-
8-
steps:
9-
- checkout: self
10-
clean: true
11-
12-
- powershell: |
13-
if($env:System_PullRequest_TargetBranch -eq $null) { $TargetBranch = "master" } else { $TargetBranch = $env:System_PullRequest_TargetBranch; }
14-
15-
$dict = New-Object 'System.Collections.Generic.Dictionary[String,System.Collections.Generic.Dictionary[String,String]]'
16-
$samples = Get-ChildItem -Path **\*.sln -Recurse | Where-Object {$_.FullName -notmatch "\\ArchivedProjects\\"}
17-
foreach($sample in $samples){
18-
19-
$solutionPath=[System.IO.Path]::GetDirectoryName($sample.FullName);
20-
Write-Host "$solutionPath"
21-
22-
git diff --quiet HEAD "origin/$TargetBranch" -- "$solutionPath"
23-
24-
# Only build if there a change in the solution path for the current PR, if we're not in a PR
25-
if( ("$env:System_PullRequest_PullRequestId" -eq '') -or ($global:LASTEXITCODE -ne 0)) {
26-
Write-Host "Adding $solutionPath"
27-
$item = New-Object 'System.Collections.Generic.Dictionary[String,String]'
28-
$item.Add("solutionPath", $sample.FullName)
29-
$name = $sample.Name.Split(".")[0]
30-
if(!$dict.ContainsKey($name)){
31-
$dict.Add($name, $item)
32-
}
33-
}
34-
$global:LASTEXITCODE = 0
35-
36-
}
37-
38-
$SolutionsJson = $dict | ConvertTo-Json -Compress
39-
40-
Write-Host $SolutionsJson
41-
Write-Host "##vso[task.setvariable variable=samplesJson;isOutput=true]$SolutionsJson"
42-
name: generateJson
43-
displayName: Generate Json of Samples
44-
45-
- template: .azure-pipelines.BuildMatrix.yml
46-
47-
# - task: PublishBuildArtifacts@1
48-
# inputs:
49-
# pathtoPublish: $(Build.ArtifactStagingDirectory)
1+
trigger:
2+
branches:
3+
include:
4+
- master
5+
- feature/*
6+
7+
pr:
8+
branches:
9+
include:
10+
- master
11+
- feature/*
12+
13+
stages:
14+
- stage: Determine_Changes
15+
displayName: Determine Changes
16+
jobs:
17+
- template: build/stage-determine-changes.yml
18+
19+
# TODO: Changes will be made in a following PR to fix the related errors
20+
# and enable Spell Checking and Markdown Linting
21+
# Related issue: https://github.com/unoplatform/uno-private/issues/286
22+
#
23+
# - stage: Docs_Validations
24+
# displayName: Docs Validations
25+
# dependsOn: Determine_Changes
26+
# # Trigger this stage when docs files are changed
27+
# condition: or(eq(dependencies.Determine_Changes.outputs['evaluate_changes.DetermineChanges.docsOnly'], 'true'), eq(dependencies.Determine_Changes.outputs['evaluate_changes.DetermineChanges.mixedChanges'], 'true'))
28+
# jobs:
29+
# - template: build/stage-docs-validations.yml
30+
31+
- stage: Build_Samples
32+
displayName: Build Samples
33+
dependsOn: Determine_Changes
34+
# Don't trigger this stage if only docs files are changed
35+
condition: ne(dependencies.Determine_Changes.outputs['evaluate_changes.DetermineChanges.docsOnly'], 'true')
36+
jobs:
37+
- template: build/stage-build-samples.yml

README.md

Lines changed: 23 additions & 454 deletions
Large diffs are not rendered by default.

build-samples.yml

Lines changed: 0 additions & 59 deletions
This file was deleted.

build/stage-build-samples.yml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
jobs:
2+
- job: PrepareBuildList
3+
displayName: Prepare Build List
4+
timeoutInMinutes: 600
5+
pool:
6+
vmImage: windows-2022
7+
steps:
8+
- checkout: self
9+
clean: true
10+
- powershell: |
11+
# Determine the context of the build (PR or push)
12+
$isPR = "$(Build.Reason)" -eq "PullRequest"
13+
14+
# Normalize the branch names based on context and set the target branch accordingly
15+
if ($isPR) {
16+
$targetBranch = "$(System.PullRequest.TargetBranch)" -replace 'refs/heads/', ''
17+
} else {
18+
$targetBranch = "master"
19+
}
20+
Write-Host "Build context determined: $(if ($isPR) { 'Pull Request targeting ' + $targetBranch } else { 'Push to master' })"
21+
22+
# Initialize a dictionary to keep track of solutions that have changed and need building.
23+
$dict = New-Object 'System.Collections.Generic.Dictionary[String,System.Collections.Generic.Dictionary[String,String]]'
24+
$samples = Get-ChildItem -Path **\*.sln -Recurse | Where-Object { $_.FullName -notmatch "\\ArchivedProjects\\" }
25+
foreach ($sample in $samples) {
26+
$solutionPath = [System.IO.Path]::GetDirectoryName($sample.FullName)
27+
Write-Host "Evaluating $solutionPath"
28+
29+
# Perform a git diff to check for changes in the solution path relative to the target branch.
30+
git diff --quiet HEAD "origin/$targetBranch" -- "$solutionPath"
31+
if ($env:System_PullRequest_PullRequestId -eq '' -or $LASTEXITCODE -ne 0) {
32+
Write-Host "Changes detected, adding $solutionPath to build list"
33+
$item = New-Object 'System.Collections.Generic.Dictionary[String,String]'
34+
$item.Add("solutionPath", $sample.FullName)
35+
$name = $sample.Name.Split(".")[0]
36+
if (!$dict.ContainsKey($name)) {
37+
$dict.Add($name, $item)
38+
}
39+
}
40+
$LASTEXITCODE = 0 # Reset last exit code to ensure accurate detection for each iteration.
41+
}
42+
43+
# Convert the dictionary of changed solutions to JSON and output it for subsequent jobs.
44+
$solutionsJson = $dict | ConvertTo-Json -Compress
45+
Write-Host "JSON of changed solutions: $solutionsJson"
46+
Write-Host "##vso[task.setvariable variable=samplesJson;isOutput=true]$solutionsJson"
47+
name: passJsonOutput
48+
displayName: 'Generate Json of Samples'
49+
50+
- job: BuildSamples
51+
displayName: Build
52+
dependsOn: PrepareBuildList
53+
# Condition to ensure this job only runs if the previous job succeeded and there are changes in the samples solutions.
54+
condition: and(succeeded(), ne(dependencies.PrepareBuildList.outputs['passJsonOutput.samplesJson'], '{}'))
55+
pool:
56+
vmImage: 'windows-2022'
57+
strategy:
58+
# Implementing matrix strategy based on changes detected in previous PrepareBuildList job.
59+
matrix: $[ dependencies.PrepareBuildList.outputs['passJsonOutput.samplesJson'] ]
60+
variables:
61+
UseDotNetNativeToolchain: false
62+
steps:
63+
- checkout: self
64+
clean: true
65+
- template: templates/dotnet-install-windows.yml
66+
67+
# Conditionally apply configurations for builds from the 'canaries' branch.
68+
- ${{ if startsWith(variables['Build.SourceBranch'], 'refs/heads/canaries') }}:
69+
- template: templates/canary-updater.yml
70+
parameters:
71+
solution: $(solutionPath)
72+
73+
# Build the project and handle build validation.
74+
- powershell: |
75+
Set-PSDebug -Trace 1
76+
Write-Host "Starting build for $(solutionPath)"
77+
# NOTE: Currently, the CI just validates that the sample builds, and we don't publish actual apps.
78+
# In future, if we publish actual apps, it could happen that AndroidAddKeepAlives=false may cause issues.
79+
# So it will be safer to remove it. For now, we set it to false as it makes the build much faster.
80+
dotnet build $(solutionPath) /p:AndroidAddKeepAlives=false /p:Configuration=Release /p:WasmShellMonoRuntimeExecutionMode=Interpreter /p:PublishTrimmed=false /p:WasmShellILLinkerEnabled=false /p:EnableCoreMrtTooling=false /p:RunAOTCompilation=false /p:MtouchUseLlvm=false "/bl:$(build.artifactstagingdirectory)\$(Agent.JobName).binlog"
81+
82+
# Locate test projects and execute tests if applicable.
83+
$folderPath = [System.IO.Path]::GetDirectoryName("$(solutionPath)")
84+
$testProject = Get-Item -Path $folderPath\**\*.Tests.csproj -ErrorAction SilentlyContinue
85+
if ($testProject) {
86+
Write-Host "Testing project: $($testProject.FullName)"
87+
& dotnet test $testProject.FullName -c Release --collect "XPlat code coverage" --logger trx --no-build
88+
} else {
89+
Write-Host "No tests found for project: $($folderPath)"
90+
}
91+
92+
# Ensure the build fails on error.
93+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
94+
95+
# Configure Git to handle long paths and clean the repository to avoid disk space issues.
96+
git config --system core.longpaths true
97+
git clean -fdx
98+
Write-Host "Cleanup complete, preparing for next operations."
99+
displayName: Build Sample
100+
101+
- task: PublishBuildArtifacts@1
102+
condition: always()
103+
retryCountOnTaskFailure: 3
104+
inputs:
105+
PathtoPublish: $(build.artifactstagingdirectory)
106+
ArtifactName: samples
107+
ArtifactType: Container

build/stage-determine-changes.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
jobs:
2+
- job: evaluate_changes
3+
displayName: 'Check for Doc Only Changes'
4+
pool:
5+
vmImage: 'ubuntu-latest'
6+
steps:
7+
- powershell: |
8+
# Determine the context of the build (PR or push) and set the target branch accordingly
9+
$isPR = "$(Build.Reason)" -eq "PullRequest"
10+
11+
# Normalize the target branch name for PR builds or default to 'master' for push builds
12+
$targetBranchName = $isPR ? "$(System.PullRequest.TargetBranch)" -replace 'refs/heads/', '' : "master"
13+
Write-Host "Build context determined: $(if ($isPR) { 'Pull Request targeting ' + $targetBranchName } else { 'Push' })"
14+
15+
# Fetch the target or default base branch and determine the merge base
16+
git fetch origin $targetBranchName
17+
$mergeBase = git merge-base HEAD "origin/$targetBranchName"
18+
Write-Host "Merge base with '$targetBranchName' identified at $mergeBase"
19+
20+
Write-Host "Comparing changes from $mergeBase..."
21+
$gitDiffCommand = "git diff $mergeBase --name-only"
22+
$changedFiles = Invoke-Expression $gitDiffCommand
23+
$docsOnly = $false
24+
$nonDocsOnly = $false
25+
$mixedChanges = $false
26+
$docFiles = 0
27+
$nonDocFiles = 0
28+
29+
if ($changedFiles) {
30+
Write-Host "Changed files:"
31+
Write-Host $changedFiles
32+
} else {
33+
Write-Host "No files have changed."
34+
}
35+
36+
foreach ($file in $changedFiles -split "`n") {
37+
# Identifying changes as documentation if they occur:
38+
# Within any 'doc' folder in the repo (at any level), or
39+
# Are Markdown files at the root level or within subdirectories
40+
$isDoc = $file -match "/doc/" -or # Path contains '/doc/' indicating it's within a doc folder at any level
41+
$file -match "^doc/" -or # Path starts with 'doc/' indicating it's in a root-level doc folder
42+
$file -match "\.md$" # File ends with .md indicating it's a Markdown file
43+
44+
if ($isDoc) {
45+
$docFiles++
46+
} else {
47+
$nonDocFiles++
48+
}
49+
}
50+
51+
Write-Host "Documentation files changed: $docFiles"
52+
Write-Host "Non-documentation files changed: $nonDocFiles"
53+
54+
if ($docFiles -gt 0 -and $nonDocFiles -eq 0) {
55+
$docsOnly = $true
56+
Write-Host "All changes are documentation-only."
57+
} elseif ($docFiles -gt 0 -and $nonDocFiles -gt 0) {
58+
$mixedChanges = $true
59+
Write-Host "Mixed changes detected: Both documentation and non-documentation files have been modified."
60+
} elseif ($nonDocFiles -gt 0) {
61+
$nonDocsOnly = $true
62+
Write-Host "Non-documentation changes detected."
63+
}
64+
65+
# Explicitly write the final values for clarity
66+
Write-Host "Final values:"
67+
Write-Host "docsOnly: $docsOnly"
68+
Write-Host "nonDocsOnly: $nonDocsOnly"
69+
Write-Host "mixedChanges: $mixedChanges"
70+
71+
# Output the results as pipeline variables
72+
Write-Host "##vso[task.setvariable variable=docsOnly;isOutput=true]$docsOnly"
73+
Write-Host "##vso[task.setvariable variable=nonDocsOnly;isOutput=true]$nonDocsOnly"
74+
Write-Host "##vso[task.setvariable variable=mixedChanges;isOutput=true]$mixedChanges"
75+
name: DetermineChanges

build/stage-docs-validations.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# TODO: Changes will be made in a following PR to fix the related errors
2+
# and enable Spell Checking and Markdown Linting
3+
# Related issue: https://github.com/unoplatform/uno-private/issues/286
4+
#
5+
# jobs:
6+
#
7+
# - job: spell_checking
8+
# displayName: 'Spell Checking Validation'
9+
10+
# - job: markdown_linting
11+
# displayName: 'Markdown Linting Validation'
File renamed without changes.

0 commit comments

Comments
 (0)