build: move code format to a GH workflow, emit rich errors #20822
<img width="2699" height="450" alt="image" src="https://github.com/user-attachments/assets/5bfd1cd5-120d-4a71-92cc-07a0dbf153a5" />
<img width="472" height="133" alt="image" src="https://github.com/user-attachments/assets/987efb8e-608f-4414-87b3-e65573da5c35" />
Is it really necessary to run linters/ci on dev branches? I'd only run it on PRs personally.
I didn't know this was a thing.
But the good news is, it's the default since v4!
Should it really be per hunk?
And I think this needs core.quotePath=false. And perhaps it would be more efficient to avoid N git diff calls here?
$file = $null
git -c core.quotePath=false diff --no-color -U0 HEAD | ForEach-Object {
if ($_ -cmatch '^\+\+\+ b/(.*)$') {
$file = $Matches[1]
}
elseif ($null -ne $file -and $_ -cmatch '^@@ .* \+(\d+)') {
$line = [int]$Matches[1]
Write-Host ("::error file={0},line={1},title=Format::{0} is improperly formatted" -f ($file, $line))
$file = $null
}
}
This could misidentify lines containing +++ b/... but... eh?
probably not, no
good to know!
why does it need core.quotePath=false?
I am not very bothered by N git diff calls; this is a CI script and if it exhibits pathological behavior oh well? :P
Commands that output paths (e.g. ls-files, diff), will quote "unusual" characters in the pathname
(do we have those?)
Non-ASCII is considered unusual in this context AFAICS.
I think we currently have no Unicode paths, but if we ever do, then a file named "中文.txt" would look like this:
> git diff -U0 HEAD
diff --git "a/\344\270\255\346\226\207.txt" "b/\344\270\255\346\226\207.txt"
new file mode 100644
...
> git -c core.quotePath=false diff -U0 HEAD
diff --git a/中文.txt b/中文.txt
new file mode 100644
...
Technically you want unescaped UTF8 here, so I think it'd be a good fit.
Should it really be per hunk?
FWIW, it was not per hunk ;P
Approved these changes.
lhecker
DHowett
This allows us to emit GitHub-native error messages which will appear in the Files view. See screenshots below.