Skip to content

ci: check text files out with LF on every platform - #82

Merged
fadwen merged 5 commits into
mainfrom
ci/line-endings
Nov 23, 2026
Merged

fadwen merged 5 commits into
mainfrom
ci/line-endings

Conversation

@fadwen

@fadwen fadwen commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Summary

The repository had no .gitattributes, so git took the line endings of a checkout from each computer's core.autocrlf. Every tracked file is stored with LF, but a Windows runner and a Windows developer got CRLF and a Linux runner LF, so a comparison of file text could pass on one and fail on the other. This change checks text files out with LF on every platform (CIC-11 of ai-powershell-standards 2.0.0) and deals with the two places where that matters. Closes #62.

Changes

  • New: .gitattributes with * text=auto eol=lf. The stored content does not change: git add --renormalize . stages nothing but the new file.
  • Validation/Probe.ps1, Validation/Fixtures.ps1 and Validation/Win32Install.ps1 are checked out with CRLF on every platform. The 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.
  • Build/Build-Help.ps1 drops the carriage return of each CRLF pair in the file Export-MamlCommandHelp writes, so en-US/IntuneScriptLab-Help.xml is the committed file byte for byte wherever it is built. Without this, every help build on a Windows checkout with LF left the file differing from the committed one in its line endings alone.
  • CHANGELOG.md: an entry under Added.

Verification

Run on Windows 11 26H2 with PowerShell 7.6.10 and Windows PowerShell 5.1.26100, on a working tree checked out again after the attribute was committed (git ls-files --eol reports w/lf for 288 files and w/crlf for the three kit scripts).

  • ./Tests/Invoke-Tests.ps1 -CodeCoverage on PowerShell 7.6.10: 1,052 tests, 1,041 passed, 8 skipped, 3 failed, coverage 95.11 percent. The same figures as on the CRLF checkout, and the same three failures, the ones Repair-IntuneScript corrupts an ANSI script on a host with a UTF-8 system code page #75 and In-box module table does not list UOPProviders, present on Windows 11 26H2 #76 describe.
  • ./Tests/Invoke-Tests.ps1 on Windows PowerShell 5.1: 1,052 tests, 1,005 passed, 44 skipped, the same 3 failed. Also the same as on the CRLF checkout.
  • Both full runs were made before the three kit scripts were put back on CRLF. After that, ./Tests/Invoke-Tests.ps1 -TestType Unit on PowerShell 7.6.10, which includes the kit's unit tests: the two known unit failures and no other.
  • ./Build/Build-Help.ps1 with -ValidateOnly, with -SkipUpdate and with neither, on the LF checkout: each passes, and git hash-object --no-filters en-US/IntuneScriptLab-Help.xml equals the committed blob after each.
  • ./Build/Build-RuleReference.ps1 -PassThru equals docs/Rules.md.
  • ./Build/Publish-Module.ps1 -WhatIf: passes, and git status is clean afterwards.
  • PSScriptAnalyzer 1.25.0 on Build/Build-Help.ps1: 0 findings. The standards' check over Build/: 0 findings.
  • quality-gates.yml started by hand on this branch, run 45129996506: Tests and analysis, Windows PowerShell 5.1, Windows on ARM, Command help and Release rehearsal all passed. The Windows runners checked the files out with LF there, and the help job on Linux found the committed compiled help equal to a new build.

Notes

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
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

@fadwen fadwen left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: approve. Reviewed against ai-powershell-standards (CIC-11). Checked in a Linux sandbox with pwsh 7.6.0.

Verified

  • No stored content changes: git add --renormalize . stages nothing.
  • Fresh clone of ci/line-endings: git ls-files --eol shows 288 files with LF and 3 with CRLF (Fixtures.ps1, Probe.ps1, Win32Install.ps1).
  • Reason for the CRLF exceptions:
    • Invoke-ValidationRound.ps1 (line 152) and Invoke-AssignmentProbe.ps1 (line 75) join Probe.ps1 with "`r`n".
    • Invoke-ValidationRound.ps1 also builds the upload from Win32Install.ps1 (line 382) and Fixtures.ps1 (line 609).
    • Probe.ps1 hashes its own file on the device.
  • Help XML: I converted the committed file to CRLF and ran the new code from Build-Help.ps1 on it. The output is the committed file byte for byte.
  • No .cmd, .bat or .reg files: none are tracked, so nothing else needs CRLF.

Partly verified: closes #62. The "no tests ran" check in #81 (TST-42) is still open, and #62 covers it. Close #62 after that's fixed.

Unverified: full suites and the rehearsal on Windows (run 45129996506). This PR has no checks because its base isn't main.

Nits

  • Speed of the carriage-return loop in Build-Help.ps1: it goes through the file one byte at a time, about 1.7 s for the 315 KB help file. Fine for now. [Array]::IndexOf with block copies would scale better.
  • .gitattributes comment: GuestAgent.ps1 and Invoke-LabGuestScript.ps1 also run on the guest and stay LF. The comment could say "scripts whose text the kit joins with CRLF".
  • CHANGELOG: mention that release packages built on windows-latest now ship LF scripts, for anyone who compares file hashes.

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.
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.
@fadwen

fadwen commented Nov 23, 2026

Copy link
Copy Markdown
Owner Author

Follow-up review of the new commits. Verdict: approve. All the nits are addressed:

  • 42b6ecb: the carriage returns are now stripped with [Array]::IndexOf and block copies. The logic keeps a lone CR and handles the last byte correctly.
  • a57d25c: the .gitattributes comment now names the scripts that keep CRLF, and the CHANGELOG says what a release now ships.

#62 can close once this stack merges, now that the "no tests ran" fix is in #81.

@fadwen

fadwen commented Nov 23, 2026

Copy link
Copy Markdown
Owner Author

The three nits are addressed on this branch, and the open point about #62 is settled by #81.

Closes #62: the "no tests ran" check is fixed in d65d978 on #81, which merges before this pull request, and this branch has it by merge. #62 can close with this one.

Carriage-return loop in Build-Help.ps1: 42b6ecb.

  • It now finds each carriage return with [Array]::IndexOf and copies the bytes between two CRLF pairs as a block.
  • For the help file with CRLF (321,947 bytes) the old loop took 2.8 s and the new code 59 ms on PowerShell 7.6.10.
  • The output is the same as the old loop's, byte for byte, for that file and for eight edge cases, among them a lone carriage return and one at the end of the file.
  • ./Build/Build-Help.ps1 -SkipUpdate on Windows still gives the committed file, 315,868 bytes, with no difference in git diff.

.gitattributes comment: a57d25c.

  • It now describes the three scripts as the ones whose text the kit joins with CRLF, uploads to Intune, or hashes on the device.
  • One correction to the review note: GuestAgent.ps1 and Invoke-LabGuestScript.ps1 do not run on the guest. The first is dot-sourced by the drivers on the computer that runs the round, and the second sends another script through the guest agent. The comment names New-IslHarnessUser.ps1 as a kit script that is delivered to a device and stays LF.

CHANGELOG: a57d25c.

  • The entry now says that the scripts of a package published from now on have LF line endings, and that their file hashes differ from those of earlier versions for that reason.
  • That a checkout on a hosted Windows runner gave CRLF before is the documented behaviour of those runners. No published package was downloaded to confirm it.

The run that could not be checked: run 45145181831 on this branch, after these commits, passed all five jobs.

Base automatically changed from ci/standards-gates to main November 23, 2026 10:11
@fadwen
fadwen merged commit 7204ab3 into main Nov 23, 2026
5 checks passed
@fadwen
fadwen deleted the ci/line-endings branch November 23, 2026 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CI gates: failed blocks pass, runs are unshuffled, tools are unpinned, no release rehearsal (TST-42, TST-46, CIC-02, CIC-10, CIC-11)

1 participant