diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..0014c3e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,12 @@ +# 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 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/Build/Build-Help.ps1 b/Build/Build-Help.ps1 index 5340fd8..34882bc 100644 --- a/Build/Build-Help.ps1 +++ b/Build/Build-Help.ps1 @@ -199,7 +199,36 @@ 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) +$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() +} Remove-Item -LiteralPath $maml -Recurse -Force # Backups from Update-MarkdownCommandHelp; git holds the previous version diff --git a/CHANGELOG.md b/CHANGELOG.md index 71e919e..2943efc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,13 @@ 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. +- 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. 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