XamlStyler
XamlStyler copied to clipboard
Formatting on GitHub Actions fails with "Could not find a part of the path"
Describe the bug
I can't run XamlStyler on GitHub Actions.
To Reproduce
Steps to reproduce the behavior:
-
$ dotnet tool install XamlStyler.Console -
Run on GitHub Actions (
macos-latestrunner) with the following step:- name: Verify XAML code formatting run: dotnet tool run xstyler --recursive --file **/*.xaml --passive
Observe the failure:
Run dotnet tool run xstyler --recursive --file Quiz/**/*.xaml --passive
dotnet tool run xstyler --recursive --file Quiz/**/*.xaml --passive
shell: /bin/bash -e {0}
env:
DOTNET_ROOT: /Users/runner/.dotnet
Checking: Quiz/**/*.xaml
Unhandled exception. System.IO.DirectoryNotFoundException: Could not find a part of the path '/Users/runner/work/Quiz/Quiz/Quiz/**/*.xaml'.
at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`[2](https://github.com/bartekpacia/Quiz/actions/runs/4908692762/jobs/8764618955#step:8:2) errorRewriter)
at Microsoft.Win[3](https://github.com/bartekpacia/Quiz/actions/runs/4908692762/jobs/8764618955#step:8:3)2.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int6[4](https://github.com/bartekpacia/Quiz/actions/runs/4908692762/jobs/8764618955#step:8:4) preallocationSize)
at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int[6](https://github.com/bartekpacia/Quiz/actions/runs/4908692762/jobs/8764618955#step:8:6)4 preallocationSize)
at System.IO.Strategies.FileStreamHelpers.ChooseStrategy(FileStream fileStream, String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int[6](https://github.com/bartekpacia/Quiz/actions/runs/4908692762/jobs/8764618955#step:8:7)4 preallocationSize)
at System.IO.StreamReader.ValidateArgsAndOpenPath(String path, Encoding encoding, Int32 bufferSize)
at System.IO.StreamReader..ctor(String path)
at Xavalon.XamlStyler.Console.XamlStylerConsole.TryProcessFile(String file) in /home/vsts/work/1/s/src/XamlStyler.Console/XamlStylerConsole.cs:line 239
at Xavalon.XamlStyler.Console.XamlStylerConsole.Process(ProcessType processType) in /home/vsts/work/1/s/src/XamlStyler.Console/XamlStylerConsole.cs:line 194
at Xavalon.XamlStyler.Console.Program.<>c.<Main>b__0_2(CommandLineOptions options) in /home/vsts/work/1/s/src/XamlStyler.Console/Program.cs:line 3[7](https://github.com/bartekpacia/Quiz/actions/runs/4908692762/jobs/8764618955#step:8:8)
at CommandLine.ParserResultExtensions.WithParsed[T](ParserResult`1 result, Action`1 action)
at Xavalon.XamlStyler.Console.Program.Main(String[] args) in /home/vsts/work/1/s/src/XamlStyler.Console/Program.cs:line 17
Error: Process completed with exit code [13]
At first I was running on windows-latest and thought the bug was because PowerShell 7 (the default shell on windows-latest runner) doesn't have globs like bash-like shells do. That's why I switched to macos-latest. Unfortunately the error persists.
What's strange is that the same exact command work just fine on my MacBook Air M1 (macOS 13 Ventura).
Screenshots

Expected behavior
I expect the tool to work on GitHub Actions' macos-latest runner.
External Configuration
Version Info (please complete the following information):
- OS:
macos-latestGitHub Action runner (which is macOS 12 Monterey currently) - Visual Studio: N/A
- XAML Styler: Console (3.2206.4)
Additional context
Apparently the difference in behavior is caused by the shell used. bash is used on GitHub Action
My project is named
Quiz
bash-5.2$ dotnet tool run xstyler --recursive --file Quiz/**/*.xaml
Processing: Quiz/**/*.xaml
Unhandled exception. System.IO.DirectoryNotFoundException: Could not find a part of the path '/Users/bartek/dev/bartekpacia/Quiz/Quiz/**/*.xaml'.
at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
at System.IO.Strategies.FileStreamHelpers.ChooseStrategy(FileStream fileStream, String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int64 preallocationSize)
at System.IO.StreamReader.ValidateArgsAndOpenPath(String path, Encoding encoding, Int32 bufferSize)
at System.IO.StreamReader..ctor(String path)
at Xavalon.XamlStyler.Console.XamlStylerConsole.TryProcessFile(String file) in /home/vsts/work/1/s/src/XamlStyler.Console/XamlStylerConsole.cs:line 239
at Xavalon.XamlStyler.Console.XamlStylerConsole.Process(ProcessType processType) in /home/vsts/work/1/s/src/XamlStyler.Console/XamlStylerConsole.cs:line 194
at Xavalon.XamlStyler.Console.Program.<>c.<Main>b__0_2(CommandLineOptions options) in /home/vsts/work/1/s/src/XamlStyler.Console/Program.cs:line 37
at CommandLine.ParserResultExtensions.WithParsed[T](ParserResult`1 result, Action`1 action)
at Xavalon.XamlStyler.Console.Program.Main(String[] args) in /home/vsts/work/1/s/src/XamlStyler.Console/Program.cs:line 17
bash-5.2$
Yet it works when I don't specify Quiz explicitly:
bash-5.2$ dotnet tool run xstyler --recursive --file **/*.xaml
Processing: Quiz/App.xaml
Processing: Quiz/AppShell.xaml
Processing: Quiz/CreatePage.xaml
Processing: Quiz/MainPage.xaml
Processing: Quiz/PlayPage.xaml
Processed 5 of 5 files.
But it only processed 5 files (not what I want), whereas zsh processed 8 (which is what I want):
zsh-5.9$ dotnet tool run xstyler --recursive --file **/*.xaml
Processing: Quiz/App.xaml
Processing: Quiz/AppShell.xaml
Processing: Quiz/CreatePage.xaml
Processing: Quiz/MainPage.xaml
Processing: Quiz/Platforms/Windows/App.xaml
Processing: Quiz/PlayPage.xaml
Processing: Quiz/Resources/Styles/Colors.xaml
Processing: Quiz/Resources/Styles/Styles.xaml
Processed 8 of 8 files.
Edit
Looks like bash doesn't perform recursive wildcard expansion by default (SO link).
bash-5.2$ shopt -s globstar
bash-5.2$ dotnet tool run xstyler --recursive --file Quiz/**/*.xaml
Processing: Quiz/App.xaml
Processing: Quiz/AppShell.xaml
Processing: Quiz/CreatePage.xaml
Processing: Quiz/MainPage.xaml
Processing: Quiz/Platforms/Windows/App.xaml
Processing: Quiz/PlayPage.xaml
Processing: Quiz/Resources/Styles/Colors.xaml
Processing: Quiz/Resources/Styles/Styles.xaml
Processed 8 of 8 files.
Works fine after enabling it :) Bear in mind that the globstar shell option is supported since Bash v4. The default Bash on macOS is v3.2, and it doesn't have globstar. To install a non-ancient Bash, you can do brew install bash.
So, for the future wanderers, if you want to use XamlStyler.Console in your GitHub Actions, you can do the following:
- name: Install non-ancient Bash
run: brew install bash
- name: Verify XAML code formatting
shell: bash
run: |
shopt -s globstar
dotnet tool run xstyler --recursive --file Quiz/**/*.xaml --passive
There's probably a way to do a recursive glob in PowerShell v7 but I didn't bother finding it.
I'll reopen in case someone finds for PowerShell v7 :)