Skip to content

Commit 421a8c4

Browse files
Adds CI Workflow w/ XAML Styler check and test pass
Disables broken test, see #63 Adds workflow inputs for manual runs
1 parent 0cbcb00 commit 421a8c4

5 files changed

Lines changed: 320 additions & 3 deletions

File tree

.config/dotnet-tools.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"xamlstyler.console": {
6+
"version": "3.2501.8",
7+
"commands": [
8+
"xstyler"
9+
]
10+
}
11+
}
12+
}

.github/workflows/build.yml

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
2+
# https://docs.github.com/actions/using-workflows/about-workflows
3+
# https://docs.github.com/actions/using-workflows/workflow-syntax-for-github-actions
4+
5+
name: CI
6+
7+
# Controls when the action will run.
8+
on:
9+
# Triggers the workflow on push or pull request events but only for the main or release branches
10+
push:
11+
branches: [ main, 'dev', 'feature/*' ]
12+
pull_request:
13+
branches: [ main, 'dev', 'feature/*' ]
14+
15+
# Allows you to run this workflow manually from the Actions tab (with inputs!)
16+
# https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#onworkflow_dispatchinputs
17+
workflow_dispatch:
18+
inputs:
19+
diagnostics:
20+
description: 'Enable diagnostics (binlogs, dumps, etc) for this run'
21+
required: false
22+
default: false
23+
type: boolean
24+
verbosity:
25+
description: 'MSBuild verbosity (quiet, minimal, normal, detailed, diagnostic)'
26+
required: true
27+
default: 'normal'
28+
type: choice
29+
options:
30+
- quiet
31+
- minimal
32+
- normal
33+
- detailed
34+
- diagnostic
35+
configuration:
36+
description: 'Build configuration to use'
37+
required: true
38+
default: 'Debug'
39+
type: choice
40+
options:
41+
- Debug
42+
- Release
43+
merge_group:
44+
45+
env:
46+
DOTNET_VERSION: ${{ '9.0.x' }}
47+
CONFIGURATION: ${{ github.event.inputs.configuration || 'Debug' }}
48+
VERBOSITY: ${{ github.event.inputs.verbosity || 'normal' }}
49+
IS_MAIN: ${{ github.ref == 'refs/heads/main' }}
50+
IS_PR: ${{ startsWith(github.ref, 'refs/pull/') }}
51+
52+
jobs:
53+
# Check XAML Styling before trying to do anything else as a gate
54+
Xaml-Style-Check:
55+
runs-on: windows-2022
56+
57+
steps:
58+
- name: Install .NET SDK v${{ env.DOTNET_VERSION }}
59+
uses: actions/setup-dotnet@v5.1.0
60+
with:
61+
dotnet-version: ${{ env.DOTNET_VERSION }}
62+
63+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
64+
- name: Checkout Repository
65+
uses: actions/checkout@v6.0.2
66+
with:
67+
submodules: recursive
68+
69+
# Restore Tools from Manifest list in the Repository
70+
- name: Restore dotnet tools
71+
run: dotnet tool restore
72+
73+
- name: Check XAML Styling
74+
run: powershell -version 5.1 -command "./ApplyXamlStyling.ps1 -Passive" -ErrorAction Stop
75+
76+
build:
77+
needs: [Xaml-Style-Check]
78+
runs-on: windows-2022
79+
80+
# Steps represent a sequence of tasks that will be executed as part of the job
81+
steps:
82+
# give UWP more room to breathe
83+
- name: Configure Pagefile
84+
uses: al-cheb/configure-pagefile-action@v1.5
85+
with:
86+
minimum-size: 32GB
87+
maximum-size: 32GB
88+
disk-root: "C:"
89+
90+
- name: Enable User-Mode Dumps collecting
91+
if: (github.event.inputs.diagnostics || 'false') == 'true'
92+
shell: powershell
93+
run: |
94+
New-Item '${{ github.workspace }}\CrashDumps' -Type Directory
95+
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps' -Name 'DumpFolder' -Type ExpandString -Value '${{ github.workspace }}\CrashDumps'
96+
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps' -Name 'DumpCount' -Type DWord -Value '10'
97+
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps' -Name 'DumpType' -Type DWord -Value '2'
98+
99+
- name: Install .NET SDK v${{ env.DOTNET_VERSION }}
100+
uses: actions/setup-dotnet@v5.1.0
101+
with:
102+
dotnet-version: ${{ env.DOTNET_VERSION }}
103+
104+
- name: .NET Info (if diagnostics)
105+
if: (github.event.inputs.diagnostics || 'false') == 'true'
106+
run: dotnet --info
107+
108+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
109+
- name: Checkout Repository
110+
uses: actions/checkout@v6.0.2
111+
with:
112+
submodules: recursive
113+
114+
# Restore Tools from Manifest list in the Repository
115+
- name: Restore dotnet tools
116+
run: dotnet tool restore
117+
118+
- name: Add msbuild to PATH
119+
uses: microsoft/setup-msbuild@v2
120+
with:
121+
vs-version: '[17.9,)'
122+
123+
# Build solution
124+
- name: MSBuild
125+
run: >
126+
msbuild.exe /restore
127+
/p:Configuration=${{ env.CONFIGURATION }}
128+
/p:Platform=x64
129+
/m
130+
${{ github.event.inputs.diagnostics == 'true' && '/bl' || '' }}
131+
/v:${{ env.VERBOSITY }}
132+
XamlStudio.slnx
133+
134+
# Run tests
135+
- name: Setup VSTest Path
136+
uses: darenm/setup-vstest@3a16d909a1f3bbc65b52f8270d475d905e7d3e44
137+
138+
- name: Run XAML Studio Unit Tests
139+
id: test-platform
140+
run: vstest.console.exe ./XamlStudio.Toolkit.UnitTests/**/XamlStudio.Toolkit.UnitTests.build.appxrecipe /Framework:FrameworkUap10 /logger:"trx;LogFileName=XamlStudio.trx" /Blame
141+
142+
- name: Artifact - Diagnostic Logs
143+
uses: actions/upload-artifact@v6
144+
if: ${{ (github.event.inputs.diagnostics || 'false') == 'true' && always() }}
145+
with:
146+
name: build-logs-xaml-studio
147+
path: ./**/*.*log
148+
149+
- name: Artifact - ILC Repro
150+
uses: actions/upload-artifact@v6
151+
if: ${{ (github.event.inputs.diagnostics || 'false') == 'true' && always() }}
152+
with:
153+
name: ilc-repro
154+
path: ./*.zip
155+
156+
# https://github.com/dorny/paths-filter#custom-processing-of-changed-files
157+
- name: Detect If any Dump Files
158+
id: detect-dump
159+
if: always()
160+
working-directory: ${{ github.workspace }}
161+
run: |
162+
echo "DUMP_FILE=$(Get-ChildItem .\CrashDumps\*.dmp -ErrorAction SilentlyContinue)" >> $env:GITHUB_OUTPUT
163+
164+
- name: Artifact - WER crash dumps
165+
uses: actions/upload-artifact@v6
166+
if: ${{ (github.event.inputs.diagnostics || 'false') == 'true' && always() }}
167+
with:
168+
name: CrashDumps-xaml-studio
169+
path: '${{ github.workspace }}/CrashDumps'
170+
171+
- name: Analyze Dump
172+
if: ${{ steps.detect-dump.outputs.DUMP_FILE != '' && (github.event.inputs.diagnostics || 'false') == 'true' && always() }}
173+
run: |
174+
dotnet tool install --global dotnet-dump
175+
dotnet-dump analyze ${{ steps.detect-dump.outputs.DUMP_FILE }} -c "clrstack" -c "pe -lines" -c "exit"

ApplyXamlStyling.ps1

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<#
2+
.SYNOPSIS
3+
Modify XAML files to adhere to XAML Styler settings.
4+
5+
.DESCRIPTION
6+
The Apply XAML Stying Script can be used to check or modify XAML files with the repo's XAML Styler settings.
7+
Learn more about XAML Styler at https://github.com/Xavalon/XamlStyler
8+
9+
By default, uses git status to check all new or modified files.
10+
11+
Use "PS> Help .\ApplyXamlStyling.ps1 -Full" for more details on parameters.
12+
13+
.PARAMETER LastCommit
14+
Runs against last commit vs. current changes
15+
16+
.PARAMETER Unstaged
17+
Runs against unstaged changed files
18+
19+
.PARAMETER Staged
20+
Runs against staged files vs. current changes
21+
22+
.PARAMETER Main
23+
Runs against main vs. current branch
24+
25+
.PARAMETER Passive
26+
Runs a passive check against all files in the repo for the CI
27+
28+
.EXAMPLE
29+
PS> .\ApplyXamlStyling.ps1 -Main
30+
#>
31+
param(
32+
[switch]$LastCommit = $false,
33+
[switch]$Unstaged = $false,
34+
[switch]$Staged = $false,
35+
[switch]$Main = $false,
36+
[switch]$Passive = $false
37+
)
38+
39+
Write-Output "Use 'Help .\ApplyXamlStyling.ps1' for more info or '-Main' to run against all files."
40+
Write-Output ""
41+
Write-Output "Restoring dotnet tools..."
42+
dotnet tool restore
43+
44+
if (-not $Passive)
45+
{
46+
# Look for unstaged changed files by default
47+
$gitDiffCommand = "git status -s --porcelain"
48+
49+
if ($Main)
50+
{
51+
Write-Output 'Checking Current Branch against `main` Files Only'
52+
$branch = git status | Select-String -Pattern "On branch (?<branch>.*)$"
53+
if ($null -eq $branch.Matches)
54+
{
55+
$branch = git status | Select-String -Pattern "HEAD detached at (?<branch>.*)$"
56+
if ($null -eq $branch.Matches)
57+
{
58+
Write-Error 'Don''t know how to fetch branch from `git status`:'
59+
git status | Write-Error
60+
exit 1
61+
}
62+
}
63+
$branch = $branch.Matches.groups[1].Value
64+
$gitDiffCommand = "git diff origin/main $branch --name-only --diff-filter=ACM"
65+
}
66+
elseif ($Unstaged)
67+
{
68+
# Look for unstaged files
69+
Write-Output "Checking Unstaged Files"
70+
$gitDiffCommand = "git diff --name-only --diff-filter=ACM"
71+
}
72+
elseif ($Staged)
73+
{
74+
# Look for staged files
75+
Write-Output "Checking Staged Files Only"
76+
$gitDiffCommand = "git diff --cached --name-only --diff-filter=ACM"
77+
}
78+
elseif ($LastCommit)
79+
{
80+
# Look at last commit files
81+
Write-Output "Checking the Last Commit's Files Only"
82+
$gitDiffCommand = "git diff HEAD^ HEAD --name-only --diff-filter=ACM"
83+
}
84+
else
85+
{
86+
Write-Output "Checking Git Status Files Only"
87+
}
88+
89+
Write-Output "Running Git Diff: $gitDiffCommand"
90+
$files = Invoke-Expression $gitDiffCommand | Select-String -Pattern "\.xaml$"
91+
92+
if (-not $Passive -and -not $Main -and -not $Unstaged -and -not $Staged -and -not $LastCommit)
93+
{
94+
# Remove 'status' column of 3 characters at beginning of lines
95+
$files = $files | ForEach-Object { $_.ToString().Substring(3) }
96+
}
97+
98+
if ($files.count -gt 0)
99+
{
100+
dotnet tool run xstyler -c .\settings.xamlstyler -f $files
101+
}
102+
else
103+
{
104+
Write-Output "No XAML Files found to style..."
105+
}
106+
}
107+
else
108+
{
109+
Write-Output "Checking all files (passively)"
110+
$files = Get-ChildItem *.xaml -Recurse | Select-Object -ExpandProperty FullName | Where-Object { $_ -notmatch "(\\obj\\)|(\\bin\\)" }
111+
112+
if ($files.count -gt 0)
113+
{
114+
dotnet tool run xstyler -p -c .\settings.xamlstyler -f $files
115+
116+
if ($lastExitCode -eq 1)
117+
{
118+
Write-Error 'XAML Styling is incorrect, please run `ApplyXamlStyling.ps1 -Main` locally.'
119+
}
120+
121+
# Return XAML Styler Status
122+
exit $lastExitCode
123+
}
124+
else
125+
{
126+
exit 0
127+
}
128+
}

XamlStudio.Toolkit.UnitTests/XmlToXamlTreeTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,9 @@ await EnqueueAsync(async () =>
299299
});
300300
}
301301

302+
// TODO: https://github.com/dotnet/XAMLStudio/issues/63
302303
[TestMethod]
304+
[Ignore]
303305
public async Task NamespacedControl_XmlToXamlTest()
304306
{
305307
await EnqueueAsync(async () =>
@@ -484,4 +486,4 @@ await EnqueueAsync(async () =>
484486
await UnloadTestContentAsync(fwe);
485487
});
486488
}
487-
}
489+
}

XamlStudio/Views/Document.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
<Setter Target="SplitterBar.(Grid.RowSpan)" Value="3" />
6161
<Setter Target="SplitterBar.(Grid.ColumnSpan)" Value="1" />
6262
<Setter Target="SplitterBar.ResizeDirection" Value="Columns" />
63-
<!-- Workaround for https://github.com/CommunityToolkit/Windows/issues/748 -->
63+
<!-- Workaround for https://github.com/CommunityToolkit/Windows/issues/748 -->
6464
<Setter Target="SplitterBar.Orientation" Value="Vertical" />
6565

6666
<Setter Target="SplitterCommandBarLeft.(Grid.Row)" Value="0" />
@@ -109,7 +109,7 @@
109109
<Setter Target="SplitterBar.(Grid.RowSpan)" Value="3" />
110110
<Setter Target="SplitterBar.(Grid.ColumnSpan)" Value="1" />
111111
<Setter Target="SplitterBar.ResizeDirection" Value="Columns" />
112-
<!-- Workaround for https://github.com/CommunityToolkit/Windows/issues/748 -->
112+
<!-- Workaround for https://github.com/CommunityToolkit/Windows/issues/748 -->
113113
<Setter Target="SplitterBar.Orientation" Value="Vertical" />
114114

115115
<Setter Target="SplitterCommandBarLeft.(Grid.Row)" Value="0" />

0 commit comments

Comments
 (0)