Repository navigation
ci: check text files out with LF on every platform - #82
Conversation
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
left a comment
There was a problem hiding this comment.
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 --eolshows 288 files with LF and 3 with CRLF (Fixtures.ps1,Probe.ps1,Win32Install.ps1). - Reason for the CRLF exceptions:
Invoke-ValidationRound.ps1(line 152) andInvoke-AssignmentProbe.ps1(line 75) joinProbe.ps1with"`r`n".Invoke-ValidationRound.ps1also builds the upload fromWin32Install.ps1(line 382) andFixtures.ps1(line 609).Probe.ps1hashes its own file on the device.
- Help XML: I converted the committed file to CRLF and ran the new code from
Build-Help.ps1on it. The output is the committed file byte for byte. - No
.cmd,.bator.regfiles: 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]::IndexOfwith block copies would scale better. .gitattributescomment:GuestAgent.ps1andInvoke-LabGuestScript.ps1also 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-latestnow ship LF scripts, for anyone who compares file hashes.
# Conflicts: # CHANGELOG.md
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.
|
Follow-up review of the new commits. Verdict: approve. All the nits are addressed:
#62 can close once this stack merges, now that the "no tests ran" fix is in #81. |
|
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
CHANGELOG: a57d25c.
The run that could not be checked: run 45145181831 on this branch, after these commits, passed all five jobs. |
Summary
The repository had no
.gitattributes, so git took the line endings of a checkout from each computer'score.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
.gitattributeswith* text=auto eol=lf. The stored content does not change:git add --renormalize .stages nothing but the new file.Validation/Probe.ps1,Validation/Fixtures.ps1andValidation/Win32Install.ps1are checked out with CRLF on every platform. The kit builds the scripts it uploads to Intune fromProbe.ps1and 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.ps1drops the carriage return of each CRLF pair in the fileExport-MamlCommandHelpwrites, soen-US/IntuneScriptLab-Help.xmlis 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 --eolreportsw/lffor 288 files andw/crlffor the three kit scripts)../Tests/Invoke-Tests.ps1 -CodeCoverageon 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.ps1on Windows PowerShell 5.1: 1,052 tests, 1,005 passed, 44 skipped, the same 3 failed. Also the same as on the CRLF checkout../Tests/Invoke-Tests.ps1 -TestType Uniton PowerShell 7.6.10, which includes the kit's unit tests: the two known unit failures and no other../Build/Build-Help.ps1with-ValidateOnly, with-SkipUpdateand with neither, on the LF checkout: each passes, andgit hash-object --no-filters en-US/IntuneScriptLab-Help.xmlequals the committed blob after each../Build/Build-RuleReference.ps1 -PassThruequalsdocs/Rules.md../Build/Publish-Module.ps1 -WhatIf: passes, andgit statusis clean afterwards.Build/Build-Help.ps1: 0 findings. The standards' check overBuild/: 0 findings.quality-gates.ymlstarted by hand on this branch, run 45129996506:Tests and analysis,Windows PowerShell 5.1,Windows on ARM,Command helpandRelease rehearsalall passed. The Windows runners checked the files out with LF there, and thehelpjob on Linux found the committed compiled help equal to a new build.Notes
git rm --cached -r . && git reset --hardon a clean working tree does that.release.ymlbuilds onwindows-latestwill carry LF in its scripts, where it carried CRLF. PowerShell 7 and Windows PowerShell 5.1 read both. The shipped module has no here-string, so no text it produces changes.