Update WingetCreate to ensure CRLF line endings
Description of the new feature / enhancement
Update WingetCreate to ensure CRLF line endings in manifest files.
Part of:
- https://github.com/microsoft/winget-pkgs/issues/72254
Proposed technical implementation details
No response
File.WriteAllLines() seems to use the Environment.NewLine property, which defines whether we get CRLF or LF depending on platform.
Here's the file where it's defined: https://github.com/dotnet/runtime/blob/9a06ea11fd1ac7600dc98b36d41eb151c57c9e84/src/libraries/System.Private.CoreLib/src/System/IO/TextWriter.cs#L36
As such we always get CRLF on Windows (and I tested it, wingetcreate update outputs a manifest with CRLF line endings). Unless we need to guarantee this on other platforms for https://github.com/microsoft/winget-create/discussions/160 I think this isn't an issue?
@Trenly have you seen wingetcreate output LF line endings?
To be fair, I haven't seen it output LF endings. I think your assessment is correct that on Windows it will always use CRLF, similar to YamlCreate. I think that it would be good to guarantee it on other platforms, but for the majority of cases, it seems to be working as expected.
Thanks for looking into it Easton!
As such we always get CRLF on Windows
If this is the case, how come PRs like this happen, after manifests have been normalised to CRLF:
- https://github.com/microsoft/winget-pkgs/pull/74952
Are you using wingetcreate update --submit or submitting it yourself using git push and a PR? That might have something to do with it.
Are you using
wingetcreate update --submitor submitting it yourself usinggit pushand a PR?
wingetcreate update --submit
I'm leaving this here for anyone with a time machine;
In looking at YamlCreate (current version 2.1.4) - It uses [System.IO.File]::WriteAllLines(String, String[], Encoding) to create the final output in the files. This is the same method used here in WingetCreate. I've created a PR (microsoft/winget-pkgs#76948) that will capture some additional debug information around YamlCreate and what line ending Environment.NewLine is using, so we can see if this will be an issue
It looks like we might have to guarantee this, even on Windows. Here's two PR's - one which was a creation from yesterday, where WingetCreate output a file with LF endings
https://github.com/microsoft/winget-pkgs/pulls?q=is%3Apr+SmartSoft.SmartFTP+10.0.3007.0
To be fair, I haven't seen it output LF endings.
How's that even possible? I've seen most of the manifests which needed renormalization were either by @wingetbot or WinGet-Create. Since YamlCreate.ps1 mostly runs on Windows, I've rarely seen it outputting manifests with LF line endings unless I've configured it in Git (and the line endings are changed during commit & push) or changed some system settings.
Also, I would say to prioritize this issue since OhMyPosh, KiwixJS, Datadog Agent and some other packages use wingetcreate as a part of their CI/CD pipelines and we would have to renormalize the manifests every now and then, once the PRs from these packages is merged.
My guess is that the GitHub API is changing the line endings to LF on upload, but I don't have any proof of it. Still need to do some testing.