winget-create icon indicating copy to clipboard operation
winget-create copied to clipboard

Update WingetCreate to ensure CRLF line endings

Open denelon opened this issue 3 years ago • 10 comments

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

denelon avatar Aug 27 '22 14:08 denelon

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?

jedieaston avatar Aug 29 '22 12:08 jedieaston

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!

Trenly avatar Aug 29 '22 14:08 Trenly

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

russellbanks avatar Aug 30 '22 10:08 russellbanks

Are you using wingetcreate update --submit or submitting it yourself using git push and a PR? That might have something to do with it.

jedieaston avatar Aug 30 '22 16:08 jedieaston

Are you using wingetcreate update --submit or submitting it yourself using git push and a PR?

wingetcreate update --submit

russellbanks avatar Aug 30 '22 17:08 russellbanks

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

Trenly avatar Sep 01 '22 20:09 Trenly

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

Trenly avatar Sep 01 '22 20:09 Trenly

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.

vedantmgoyal9 avatar Sep 03 '22 15:09 vedantmgoyal9

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.

vedantmgoyal9 avatar Sep 03 '22 15:09 vedantmgoyal9

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.

jedieaston avatar Sep 08 '22 12:09 jedieaston