From 5825e2a06c2ca31e59d2a87c0b4f4d5c65f25f23 Mon Sep 17 00:00:00 2001 From: Jeffrey Stuhr <110697945+fadwen@users.noreply.github.com> Date: Sat, 21 Nov 2026 18:32:12 -0800 Subject: [PATCH 1/4] ci: check text files out with LF on every platform Without a .gitattributes file, git decided the line endings of a checkout from each computer's core.autocrlf setting. Every tracked file is stored with LF, but a Windows runner and a Windows developer got CRLF and a Linux runner LF, so a test that compares the text of a file with a here-string could pass on one and fail on the other. "* text=auto eol=lf" checks every text file out with LF everywhere. The stored content does not change: git add --renormalize stages nothing but the new file. Closes #62 --- .gitattributes | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..db1579c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +# Text files are stored and checked out with LF on every platform, so that a Windows runner, +# a Linux runner and a developer test the same bytes (CIC-11 of the PowerShell standards). +* text=auto eol=lf From fdba969e78065b15d351a188770d7410868edc50 Mon Sep 17 00:00:00 2001 From: Jeffrey Stuhr <110697945+fadwen@users.noreply.github.com> Date: Sun, 22 Nov 2026 23:17:19 -0800 Subject: [PATCH 2/4] ci: keep the kit payloads on CRLF and build the help with LF Two things follow from checking text files out with LF. The validation kit builds the scripts it uploads to Intune from Probe.ps1 and joins the parts with CRLF, so an LF checkout would upload scripts with mixed line endings where a Windows checkout uploaded CRLF throughout. Probe.ps1, Fixtures.ps1 and Win32Install.ps1 are therefore checked out with CRLF on every platform. Export-MamlCommandHelp writes the platform's line endings. On a Windows checkout with LF, every help build left en-US/IntuneScriptLab-Help.xml differing from the committed file in its line endings alone. Build-Help.ps1 now drops the carriage return of each CRLF pair, so the file is the committed one byte for byte wherever it is built. Refs #62 --- .gitattributes | 7 +++++++ Build/Build-Help.ps1 | 18 +++++++++++++++++- CHANGELOG.md | 5 +++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index db1579c..de170f2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,10 @@ # Text files are stored and checked out with LF on every platform, so that a Windows runner, # a Linux runner and a developer test the same bytes (CIC-11 of the PowerShell standards). * text=auto eol=lf + +# The scripts the validation kit uploads to Intune or runs on the lab devices are checked out +# with CRLF on every platform, as a Windows checkout had them before this file existed, so that +# a round sends the same bytes wherever it is started from. +Validation/Fixtures.ps1 text eol=crlf +Validation/Probe.ps1 text eol=crlf +Validation/Win32Install.ps1 text eol=crlf diff --git a/Build/Build-Help.ps1 b/Build/Build-Help.ps1 index 5340fd8..fbb9b85 100644 --- a/Build/Build-Help.ps1 +++ b/Build/Build-Help.ps1 @@ -199,7 +199,23 @@ if ($null -eq $built) { throw "Export-MamlCommandHelp produced no IntuneScriptLab-Help.xml under $maml" } $null = New-Item -ItemType Directory -Path $culture -Force -Copy-Item -LiteralPath $built.FullName -Destination $shipped -Force + +# Export-MamlCommandHelp writes the line endings of the platform, CRLF on Windows. The committed +# file is stored and checked out with LF and CI compares a new build with it byte for byte, so +# the carriage return of every CRLF pair is dropped and the file is the same wherever it is +# built. Bytes, not text: the byte order mark and everything else stay exactly as PlatyPS wrote +# them. +$builtBytes = [System.IO.File]::ReadAllBytes($built.FullName) +$lastIndex = $builtBytes.Length - 1 +$shippedBytes = [System.Collections.Generic.List[byte]]::new($builtBytes.Length) +for ($index = 0; $index -le $lastIndex; $index++) { + $isCarriageReturn = $builtBytes[$index] -eq 13 -and $index -lt $lastIndex + $isCarriageReturnOfPair = $isCarriageReturn -and $builtBytes[$index + 1] -eq 10 + if (-not $isCarriageReturnOfPair) { + $shippedBytes.Add($builtBytes[$index]) + } +} +[System.IO.File]::WriteAllBytes($shipped, $shippedBytes.ToArray()) Remove-Item -LiteralPath $maml -Recurse -Force # Backups from Update-MarkdownCommandHelp; git holds the previous version diff --git a/CHANGELOG.md b/CHANGELOG.md index 0df392f..54ea5e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,11 @@ entries are carried over from the manifest's release notes. - A `rehearsal` job in `quality-gates.yml` that runs `Build/Publish-Module.ps1 -WhatIf` on every pull request, so that a release which would fail at the tag fails before the merge. The same workflow now also runs every night, and checks PSScriptAnalyzer's `ScriptSecurity` rules. +- A `.gitattributes` file that checks every text file out with LF on every platform, so that a + Windows runner, a Linux runner and a developer test the same bytes. The three scripts the + validation kit uploads or runs on the lab devices keep CRLF everywhere. `Build/Build-Help.ps1` + writes the compiled help with LF wherever it runs, so a build on Windows gives the committed + file byte for byte. ### Changed From 42b6ecb79b6ce5fc3543251f9c1ca26ce0b1eb11 Mon Sep 17 00:00:00 2001 From: Jeffrey Stuhr <110697945+fadwen@users.noreply.github.com> Date: Mon, 23 Nov 2026 01:13:46 -0800 Subject: [PATCH 3/4] perf(build): drop the help file's carriage returns in block copies Build-Help.ps1 removed the carriage return of every CRLF pair from the compiled help one byte at a time, which took 2.8 seconds for the 322 KB file on PowerShell 7.6. It now finds each carriage return with [Array]::IndexOf and copies the bytes between two pairs as a block, which takes 59 milliseconds for the same file. A carriage return that no line feed follows is kept, as before, and the output for the help file and for eight edge cases is the same byte for byte. --- Build/Build-Help.ps1 | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/Build/Build-Help.ps1 b/Build/Build-Help.ps1 index fbb9b85..34882bc 100644 --- a/Build/Build-Help.ps1 +++ b/Build/Build-Help.ps1 @@ -206,16 +206,29 @@ $null = New-Item -ItemType Directory -Path $culture -Force # built. Bytes, not text: the byte order mark and everything else stay exactly as PlatyPS wrote # them. $builtBytes = [System.IO.File]::ReadAllBytes($built.FullName) -$lastIndex = $builtBytes.Length - 1 -$shippedBytes = [System.Collections.Generic.List[byte]]::new($builtBytes.Length) -for ($index = 0; $index -le $lastIndex; $index++) { - $isCarriageReturn = $builtBytes[$index] -eq 13 -and $index -lt $lastIndex - $isCarriageReturnOfPair = $isCarriageReturn -and $builtBytes[$index + 1] -eq 10 - if (-not $isCarriageReturnOfPair) { - $shippedBytes.Add($builtBytes[$index]) +$shippedStream = [System.IO.MemoryStream]::new($builtBytes.Length) +try { + # The bytes between one CRLF pair and the next are copied as a block. A carriage return that + # no line feed follows is not part of a pair and stays where it is. + $copyFrom = 0 + $searchFrom = 0 + while ($searchFrom -lt $builtBytes.Length) { + $carriageReturn = [Array]::IndexOf($builtBytes, [byte]13, $searchFrom) + if ($carriageReturn -lt 0) { + break + } + + $searchFrom = $carriageReturn + 1 + if ($searchFrom -lt $builtBytes.Length -and $builtBytes[$searchFrom] -eq 10) { + $shippedStream.Write($builtBytes, $copyFrom, $carriageReturn - $copyFrom) + $copyFrom = $searchFrom + } } + $shippedStream.Write($builtBytes, $copyFrom, $builtBytes.Length - $copyFrom) + [System.IO.File]::WriteAllBytes($shipped, $shippedStream.ToArray()) +} finally { + $shippedStream.Dispose() } -[System.IO.File]::WriteAllBytes($shipped, $shippedBytes.ToArray()) Remove-Item -LiteralPath $maml -Recurse -Force # Backups from Update-MarkdownCommandHelp; git holds the previous version From a57d25ca70d01e3aab112ad7f8482cb6b9345ae8 Mon Sep 17 00:00:00 2001 From: Jeffrey Stuhr <110697945+fadwen@users.noreply.github.com> Date: Mon, 23 Nov 2026 01:13:46 -0800 Subject: [PATCH 4/4] docs: say which scripts keep CRLF and what a release now ships The comment in .gitattributes described the three CRLF scripts as the ones the kit uploads or runs on a device, which is also true of kit scripts that stay LF. What sets the three apart is that the kit joins their text with CRLF, uploads it to Intune, or hashes it on the device, and the comment says that now. The changelog entry adds a consequence of the LF checkout that the entry did not state: a release is staged from a checkout on a Windows runner, so the scripts in a published package change from CRLF to LF, and with them their file hashes. --- .gitattributes | 8 +++++--- CHANGELOG.md | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.gitattributes b/.gitattributes index de170f2..0014c3e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,9 +2,11 @@ # a Linux runner and a developer test the same bytes (CIC-11 of the PowerShell standards). * text=auto eol=lf -# The scripts the validation kit uploads to Intune or runs on the lab devices are checked out -# with CRLF on every platform, as a Windows checkout had them before this file existed, so that -# a round sends the same bytes wherever it is started from. +# The three scripts whose text the validation kit joins with CRLF, uploads to Intune, or hashes +# on the lab device are checked out with CRLF on every platform, as a Windows checkout had them +# before this file existed, so that a round sends the same bytes wherever it is started from. +# The kit's other scripts that are delivered to a device, such as New-IslHarnessUser.ps1, are LF +# like the rest: they are sent as they are, and nothing depends on their line endings. Validation/Fixtures.ps1 text eol=crlf Validation/Probe.ps1 text eol=crlf Validation/Win32Install.ps1 text eol=crlf diff --git a/CHANGELOG.md b/CHANGELOG.md index eb12398..2943efc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,9 @@ entries are carried over from the manifest's release notes. Windows runner, a Linux runner and a developer test the same bytes. The three scripts the validation kit uploads or runs on the lab devices keep CRLF everywhere. `Build/Build-Help.ps1` writes the compiled help with LF wherever it runs, so a build on Windows gives the committed - file byte for byte. + file byte for byte. A release is staged from a checkout on a Windows runner, so the scripts of + a package published from now on have LF line endings where that checkout gave them CRLF, and + their file hashes differ from those of an earlier version for that reason alone. ### Changed