majkinetor / au

Chocolatey Automatic Package Updater Module
GNU General Public License v2.0
227 stars 71 forks source link

Allow setting character encoding on report file #260

Closed sumo300 closed 1 year ago

sumo300 commented 2 years ago

Report creation should allow setting what character encoding to use for writing the file (i.e. UTF-8).

There is currently an issue when using Azure DevOps to upload a markdown report as a build summary as it requires either UTF-8 or Text. During the pipeline, if the file is attempted to be changed to the correct encoding and written back to the same file, errors occur because the file is locked. There is a workaround in that the contents of the original report can be written to a different file, but it would be far easier if there was a property to set the encoding of the report.

sumo300 commented 2 years ago

Doing some further investigation into this issue. This is specifically affecting Azure DevOps (ADO) which requires a UTF-8 or Text file attached as a markdown report for its summary task (the markdown then shows up in a tab for viewing when a build completes).

The issue seems to arise when using Microsoft's hosted ADO agents (Windows 2019 right now) as the PowerShell sessions on that host is set to UTF-16 LE (little endian) and therefore the report file written uses that encoding.

To ensure any host is supported, the current encoding would need to be detected, then used to re-write the file to UTF-8.

Thus the need for an option to be added to provide the encoding desired for the report output file.