diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 892200d..2263b19 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -1,6 +1,6 @@ name: .NET build and test env: - CURRENT_VERSION: 2.1.${{ github.run_number }} + CURRENT_VERSION: 2.2.${{ github.run_number }} LAST_COMMIT_MESSAGE: ${{ github.event.head_commit.message }} on: @@ -23,7 +23,7 @@ jobs: uses: actions/setup-dotnet@v3 with: dotnet-version: 6.0.x - - uses: actions/setup-node@v3.5.1 + - uses: actions/setup-node@v3.6.0 with: node-version: 18 - name: Restore dependencies @@ -58,8 +58,6 @@ jobs: - name: Build run: dotnet build --configuration Release --no-restore - name: Publish FolderProfileWindows - run: dotnet publish ./Codeuctivity.HtmlRendererCli --configuration Release -f net7.0 -p:PublishProfile=FolderProfileWindows - - name: Publish FolderProfilePortable run: dotnet publish ./Codeuctivity.HtmlRendererCli --configuration Release -f net6.0 -p:PublishProfile=FolderProfilePortable - name: Zip FolderProfilePortable uses: thedoctor0/zip-release@main @@ -82,7 +80,6 @@ jobs: files: | ./Codeuctivity.HtmlRenderer/bin/Release/*.nupkg ./Codeuctivity.HtmlRenderer/bin/Release/*.snupkg - ./Codeuctivity.HtmlRendererCli/bin/Release/net7.0/publish/FolderProfileWindows/Codeuctivity.HtmlRendererCli.exe ./Codeuctivity.HtmlRendererCli/bin/Release/net6.0/publish/FolderProfilePortable/Codeuctivity.HtmlRendererCli.Portable.zip deployTest: @@ -103,8 +100,6 @@ jobs: run: dotnet restore - name: Build run: dotnet build --configuration Release --no-restore - - name: Publish FolderProfileWindows - run: dotnet publish ./Codeuctivity.HtmlRendererCli --configuration Release -f net7.0 -p:PublishProfile=FolderProfileWindows - name: Publish FolderProfilePortable run: dotnet publish ./Codeuctivity.HtmlRendererCli --configuration Release -f net6.0 -p:PublishProfile=FolderProfilePortable - name: Zip FolderProfilePortable @@ -129,5 +124,4 @@ jobs: files: | ./Codeuctivity.HtmlRenderer/bin/Release/*.nupkg ./Codeuctivity.HtmlRenderer/bin/Release/*.snupkg - ./Codeuctivity.HtmlRendererCli/bin/Release/net7.0/publish/FolderProfileWindows/Codeuctivity.HtmlRendererCli.exe ./Codeuctivity.HtmlRendererCli/bin/Release/net6.0/publish/FolderProfilePortable/Codeuctivity.HtmlRendererCli.Portable.zip diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 655d659..9d5c088 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -18,7 +18,7 @@ jobs: pull-requests: write steps: - - uses: actions/stale@v6 + - uses: actions/stale@v7 with: repo-token: ${{ secrets.GITHUB_TOKEN }} stale-issue-message: 'Stale issue message' diff --git a/Codeuctivity.HtmlRenderer/Codeuctivity.HtmlRenderer.csproj b/Codeuctivity.HtmlRenderer/Codeuctivity.HtmlRenderer.csproj index b4a36ae..cece021 100644 --- a/Codeuctivity.HtmlRenderer/Codeuctivity.HtmlRenderer.csproj +++ b/Codeuctivity.HtmlRenderer/Codeuctivity.HtmlRenderer.csproj @@ -39,8 +39,8 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Codeuctivity.HtmlRenderer/Renderer.cs b/Codeuctivity.HtmlRenderer/Renderer.cs index dfa439c..0c9f8c3 100644 --- a/Codeuctivity.HtmlRenderer/Renderer.cs +++ b/Codeuctivity.HtmlRenderer/Renderer.cs @@ -50,7 +50,7 @@ public Renderer(LaunchOptions? launchOptions = null) /// /// Browser fetcher - used to get chromium bins /// - public BrowserFetcher BrowserFetcher { get; private set; } = default!; + public BrowserFetcher BrowserFetcher { get; private set; } private LaunchOptions LaunchOptions { get; } @@ -91,8 +91,8 @@ private async Task InitializeAsync(BrowserFetcher browserFetcher) { BrowserFetcher = browserFetcher; BrowserFetcher.DownloadProgressChanged += DownloadProgressChanged; - - _ = await BrowserFetcher.DownloadAsync(BrowserFetcher.DefaultChromiumRevision ?? string.Empty).ConfigureAwait(false); + var revisionInfo = await BrowserFetcher.DownloadAsync(BrowserFetcher.DefaultChromiumRevision ?? string.Empty).ConfigureAwait(false); + LaunchOptions.ExecutablePath = revisionInfo.ExecutablePath; Browser = await Puppeteer.LaunchAsync(LaunchOptions).ConfigureAwait(false); return this; } diff --git a/Codeuctivity.HtmlRendererCli/Codeuctivity.HtmlRendererCli.csproj b/Codeuctivity.HtmlRendererCli/Codeuctivity.HtmlRendererCli.csproj index 9535902..111418d 100644 --- a/Codeuctivity.HtmlRendererCli/Codeuctivity.HtmlRendererCli.csproj +++ b/Codeuctivity.HtmlRendererCli/Codeuctivity.HtmlRendererCli.csproj @@ -1,10 +1,12 @@ - + Exe - net7.0;net6.0 + net6.0 true Codeuctivity.HtmlRendererCli + true + embedded diff --git a/Codeuctivity.HtmlRendererCli/Program.cs b/Codeuctivity.HtmlRendererCli/Program.cs index 57f8833..186364a 100644 --- a/Codeuctivity.HtmlRendererCli/Program.cs +++ b/Codeuctivity.HtmlRendererCli/Program.cs @@ -37,7 +37,9 @@ public static async Task Main(string[] args) } Console.WriteLine($"Converting {inputPathDocx} to {outputPathHtml} using PuppeteerSharp.Renderer {Version}"); - var browserFetcher = new BrowserFetcher(); + BrowserFetcherOptions options = new BrowserFetcherOptions(); + options.Path = Path.GetTempPath(); + var browserFetcher = new BrowserFetcher(options); Console.WriteLine($"Fetching chromium from web, to {browserFetcher.DownloadsFolder} .... "); browserFetcher.DownloadProgressChanged += BrowserFetcher_DownloadProgressChanged; await using var chromiumRenderer = await Renderer.CreateAsync(browserFetcher, string.Empty); diff --git a/Codeuctivity.HtmlRendererCli/Properties/PublishProfiles/FolderProfileWindows.pubxml b/Codeuctivity.HtmlRendererCli/Properties/PublishProfiles/FolderProfileWindows.pubxml index d3e2de4..a1eeaf4 100644 --- a/Codeuctivity.HtmlRendererCli/Properties/PublishProfiles/FolderProfileWindows.pubxml +++ b/Codeuctivity.HtmlRendererCli/Properties/PublishProfiles/FolderProfileWindows.pubxml @@ -6,13 +6,13 @@ https://go.microsoft.com/fwlink/?LinkID=208121. Release Any CPU - bin\Release\net7.0\publish\FolderProfileWindows\ + bin\Release\net6.0\publish\FolderProfileWindows\ FileSystem - net7.0 + net6.0 true win-x86 true false - false + true \ No newline at end of file diff --git a/Codeuctivity.HtmlRendererCliTests/Codeuctivity.HtmlRendererCliTests.csproj b/Codeuctivity.HtmlRendererCliTests/Codeuctivity.HtmlRendererCliTests.csproj index eb9331b..40890bd 100644 --- a/Codeuctivity.HtmlRendererCliTests/Codeuctivity.HtmlRendererCliTests.csproj +++ b/Codeuctivity.HtmlRendererCliTests/Codeuctivity.HtmlRendererCliTests.csproj @@ -7,8 +7,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/Codeuctivity.HtmlRendererCliTests/RendererCliTests.cs b/Codeuctivity.HtmlRendererCliTests/RendererCliTests.cs index 3883e26..c8be10f 100644 --- a/Codeuctivity.HtmlRendererCliTests/RendererCliTests.cs +++ b/Codeuctivity.HtmlRendererCliTests/RendererCliTests.cs @@ -56,6 +56,8 @@ public void PublishedSelfContainedBinaryShouldWork() }; process.Start(); + var outputResult = GetStreamOutput(process.StandardOutput); + var errorResult = GetStreamOutput(process.StandardError); var isExited = process.WaitForExit(80000); if (!isExited) @@ -66,13 +68,13 @@ public void PublishedSelfContainedBinaryShouldWork() Assert.True(isExited); - Assert.True(File.Exists(actualFilePath)); + Assert.True(File.Exists(actualFilePath), $"StdOut: {outputResult}\nStdErr: {errorResult}\n"); } private static string DotnetPublishFolderProfileWindows(string projectName) { var absolutePath = Path.GetFullPath("../../../../" + projectName); - var expectedBinaryPath = Path.Combine(absolutePath, $"bin/Release/net7.0/publish/FolderProfileWindows/{projectName}.exe"); + var expectedBinaryPath = Path.Combine(absolutePath, $"bin/Release/net6.0/publish/FolderProfileWindows/{projectName}.exe"); if (File.Exists(expectedBinaryPath)) { @@ -84,7 +86,7 @@ private static string DotnetPublishFolderProfileWindows(string projectName) StartInfo = new ProcessStartInfo { FileName = "dotnet", - Arguments = $"publish {absolutePath} --configuration Release -f net7.0 -p:PublishProfile=FolderProfileWindows", + Arguments = $"publish {absolutePath} --configuration Release -f net6.0 -p:PublishProfile=FolderProfileWindows", RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, diff --git a/Codeuctivity.HtmlRendererTests/Codeuctivity.HtmlRendererTests.csproj b/Codeuctivity.HtmlRendererTests/Codeuctivity.HtmlRendererTests.csproj index bc6cd2b..92c30c9 100644 --- a/Codeuctivity.HtmlRendererTests/Codeuctivity.HtmlRendererTests.csproj +++ b/Codeuctivity.HtmlRendererTests/Codeuctivity.HtmlRendererTests.csproj @@ -17,12 +17,12 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Codeuctivity.HtmlRendererTests/RendererTests.cs b/Codeuctivity.HtmlRendererTests/RendererTests.cs index b583450..922dc6c 100644 --- a/Codeuctivity.HtmlRendererTests/RendererTests.cs +++ b/Codeuctivity.HtmlRendererTests/RendererTests.cs @@ -42,11 +42,12 @@ public async Task ShouldConvertHtmlToPdf(string testFileName) var actualImagePathDirectory = Path.Combine(Path.GetTempPath(), testFileName); - if (!IsRunningOnWslOrAzureOrMacos()) + if (!IsRunningOnAzureOrMacos()) { var actualImages = await Rasterize.ConvertToPngAsync(actualFilePath, actualImagePathDirectory); Assert.Single(actualImages); - DocumentAsserter.AssertImageIsEqual(actualImages.Single(), expectReferenceFilePath, 2000); + // File.Copy(actualImages.Single(), expectReferenceFilePath, true); + DocumentAsserter.AssertImageIsEqual(actualImages.Single(), expectReferenceFilePath, 8000); } File.Delete(actualFilePath); } @@ -54,8 +55,8 @@ public async Task ShouldConvertHtmlToPdf(string testFileName) } [Theory] - [InlineData("BasicTextFormatedInlineBackground.html", false, 6000)] - [InlineData("BasicTextFormatedInlineBackground.html", true, 6000)] + [InlineData("BasicTextFormatedInlineBackground.html", false, 9000)] + [InlineData("BasicTextFormatedInlineBackground.html", true, 9000)] public async Task ShouldConvertHtmlToPdfWithOptions(string testFileName, bool printBackground, int allowedPixelDiff) { var sourceHtmlFilePath = $"../../../TestInput/{testFileName}"; @@ -73,7 +74,7 @@ public async Task ShouldConvertHtmlToPdfWithOptions(string testFileName, bool pr var actualImagePathDirectory = Path.Combine(Path.GetTempPath(), testFileName); - if (!IsRunningOnWslOrAzureOrMacos()) + if (!IsRunningOnAzureOrMacos()) { try { @@ -93,7 +94,7 @@ public async Task ShouldConvertHtmlToPdfWithOptions(string testFileName, bool pr await ChromiumProcessDisposedAsserter.AssertNoChromiumProcessIsRunning(); } - private static bool IsRunningOnWslOrAzureOrMacos() + private static bool IsRunningOnAzureOrMacos() { if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD)) { @@ -107,9 +108,8 @@ private static bool IsRunningOnWslOrAzureOrMacos() var version = File.ReadAllText("/proc/version"); var IsAzure = version.IndexOf("azure", StringComparison.OrdinalIgnoreCase) >= 0; - var IsWsl = version.IndexOf("Microsoft", StringComparison.OrdinalIgnoreCase) >= 0; - return IsWsl || IsAzure; + return IsAzure; } [Theory] @@ -137,7 +137,7 @@ public async Task ShouldConvertHtmlToPng(string testFileName) } [Theory] - [InlineData("BasicTextFormatedInlineBackground.html", false, 11000)] + [InlineData("BasicTextFormatedInlineBackground.html", false, 15000)] [InlineData("BasicTextFormatedInlineBackground.html", true, 9500)] public async Task ShouldConvertHtmlToPngScreenshotOptions(string testFileName, bool omitBackground, int allowedPixelDiff) { @@ -158,7 +158,7 @@ public async Task ShouldConvertHtmlToPngScreenshotOptions(string testFileName, b }; await chromiumRenderer.ConvertHtmlToPng(sourceHtmlFilePath, actualFilePath, screenshotOptions); - // File.Copy(actualFilePath, expectReferenceFilePath); + // File.Copy(actualFilePath, expectReferenceFilePath, true); DocumentAsserter.AssertImageIsEqual(actualFilePath, expectReferenceFilePath, allowedPixelDiff); } diff --git a/README.md b/README.md index eb8e5b4..8030c70 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Renders HTML to PDF or PNGs - Based on PuppeteerSharp -- Give the cli version a try - [Codeuctivity.HtmlRendererCli.exe](https://github.com/Codeuctivity/PuppeteerSharp.Renderer/releases) +- Give the CLI version a try - [Codeuctivity.HtmlRendererCli.exe](https://github.com/Codeuctivity/PuppeteerSharp.Renderer/releases) ## Render HTML to PDF @@ -23,10 +23,10 @@ await chromiumRenderer.ConvertHtmlToPng(actualFilePath, pathRasterizedHtml); ## Development -### Linux +### Linux / WSL ```bash -sudo apt install libgbm-dev libatk-bridge2.0-0 +sudo apt install libgbm-dev libatk-bridge2.0-0 libnss3 libcups2 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libpango-1.0-0 libcairo2 libasound2 curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash exit nvm install 18