From e68c8392734f486ea0487c6bdc4bbce51d2caf38 Mon Sep 17 00:00:00 2001 From: Stefan Seeland <168659+stesee@users.noreply.github.com> Date: Sat, 16 Aug 2025 20:55:20 +0200 Subject: [PATCH 1/3] Update dependencies and improve GitHub Actions workflow for .NET projects --- .github/workflows/dotnet.yml | 154 +++++++----------- .vscode/settings.json | 8 +- OpenXmlToHtml/OpenXmlToHtml.csproj | 4 +- OpenXmlToHtmlCli/OpenXmlToHtmlCli.csproj | 4 +- .../OpenXmlToHtmlOpenApiTests.csproj | 6 +- .../OpenXmlToHtmlIntegrationTests.cs | 7 +- OpenXmlToHtmlTests/OpenXmlToHtmlTests.csproj | 6 +- 7 files changed, 83 insertions(+), 106 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 1c0a30e..5357d52 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -14,116 +14,88 @@ jobs: matrix: os: [ubuntu-latest, windows-latest] steps: - - uses: actions/checkout@v4 - - name: Setup .NET - uses: actions/setup-dotnet@v4 - with: - dotnet-version: 8.0.x - - name: Restore dependencies - run: dotnet restore - - name: Build - run: dotnet build --configuration Release --no-restore - - name: Test - run: dotnet test --no-build --verbosity normal --configuration Release - - name: Publish Unit Test Results - uses: actions/upload-artifact@v4 - if: failure() - with: - name: TestResult - path: "TestResult/**/*" + - uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + - name: Restore dependencies + run: dotnet restore + - name: Build + run: dotnet build --configuration Release --no-restore + - name: Test + run: dotnet test --no-build --verbosity normal --configuration Release + - name: Publish Unit Test Results + uses: actions/upload-artifact@v4 + if: failure() + with: + name: TestResult + path: "TestResult/**/*" deployRelease: if: ${{ github.ref == 'refs/heads/release' }} runs-on: windows-latest - needs: build + needs: build steps: - - uses: actions/checkout@v4 - - name: Setup .NET - uses: actions/setup-dotnet@v4 - with: - dotnet-version: 8.0.x - - name: Restore dependencies - run: dotnet restore - - name: Build - run: | + - uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + - name: Restore dependencies + run: dotnet restore + - name: Build + run: | dotnet build --configuration Release --no-restore dotnet publish ./OpenXmlToHtmlOpenApi -c Release /p:WebPublishMethod=Package dotnet publish ./OpenXmlToHtmlCli -c Release - - name: Zip - uses: thedoctor0/zip-release@main - with: - path: .\OpenXmlToHtmlCli\bin\Release\net8.0\win-x64\publish - type: 'zip' - filename: 'OpenXmlToHtmlCli.zip' - - name: NugetPush - env: + - name: Zip + run: | + Compress-Archive -Path ".\OpenXmlToHtmlCli\bin\Release\net8.0\win-x64\publish\*" -DestinationPath ".\OpenXmlToHtmlCli.zip" -Force + - name: NugetPush + env: NUGET_TOKEN_EXISTS: ${{ secrets.NUGET_TOKEN }} - if: env.NUGET_TOKEN_EXISTS != '' - run: | + if: env.NUGET_TOKEN_EXISTS != '' + run: | dotnet nuget push .\OpenXmlToHtml\bin\Release\*.nupkg --skip-duplicate --api-key ${{secrets.NUGET_TOKEN}} --source https://api.nuget.org/v3/index.json - - name: Github Prelease - shell: bash - env: - GITHUB_TOKEN: ${{ github.TOKEN }} - if: env.GITHUB_TOKEN != '' - run: | + - name: Github Prelease + shell: bash + env: + GITHUB_TOKEN: ${{ github.TOKEN }} + if: env.GITHUB_TOKEN != '' + run: | gh release create ${{env.CURRENT_VERSION}} ./OpenXmlToHtmlOpenApi/bin/Release/net8.0/OpenXmlToHtmlOpenApi.zip ./OpenXmlToHtmlCli.zip ./OpenXmlToHtml/bin/Release/*.*nupkg --generate-notes - deployTest: if: ${{ github.ref == 'refs/heads/main' }} runs-on: windows-latest - needs: build + needs: build steps: - - uses: actions/checkout@v4 - - name: Setup .NET - uses: actions/setup-dotnet@v4 - with: - dotnet-version: 8.0.x - - name: Restore dependencies - run: dotnet restore - - name: Build - run: | + - uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + - name: Restore dependencies + run: dotnet restore + - name: Build + run: | dotnet build --configuration Release --no-restore dotnet publish ./OpenXmlToHtmlOpenApi -c Release /p:WebPublishMethod=Package dotnet publish ./OpenXmlToHtmlCli -c Release - - name: Zip - uses: thedoctor0/zip-release@main - with: - path: .\OpenXmlToHtmlCli\bin\Release\net8.0\win-x64\publish - type: 'zip' - filename: 'OpenXmlToHtmlCli.zip' - - name: NugetPush - env: + - name: Zip + run: | + Compress-Archive -Path ".\OpenXmlToHtmlCli\bin\Release\net8.0\win-x64\publish\*" -DestinationPath ".\OpenXmlToHtmlCli.zip" -Force + - name: NugetPush + env: NUGET_TOKEN_EXISTS: ${{ secrets.NUGET_TEST_TOKEN }} - if: env.NUGET_TOKEN_EXISTS != '' - run: | + if: env.NUGET_TOKEN_EXISTS != '' + run: | dotnet nuget push .\OpenXmlToHtml\bin\Release\*.nupkg --skip-duplicate --api-key ${{secrets.NUGET_TEST_TOKEN}} --source https://apiint.nugettest.org/v3/index.json - - name: Github Prelease - shell: bash - env: - GITHUB_TOKEN: ${{ github.TOKEN }} - if: env.GITHUB_TOKEN != '' - run: | + - name: Github Prelease + shell: bash + env: + GITHUB_TOKEN: ${{ github.TOKEN }} + if: env.GITHUB_TOKEN != '' + run: | gh release create ${{env.CURRENT_VERSION}} ./OpenXmlToHtmlOpenApi/bin/Release/net8.0/OpenXmlToHtmlOpenApi.zip ./OpenXmlToHtmlCli.zip ./OpenXmlToHtml/bin/Release/*.*nupkg --prerelease --generate-notes - - deployAzure: - if: ${{ github.ref == 'refs/heads/release' || github.ref == 'refs/heads/AzureAppPublishUsingGithubActions'}} - runs-on: ubuntu-latest - needs: build - steps: - - uses: actions/checkout@v4 - - name: Setup .NET - uses: actions/setup-dotnet@v4 - with: - dotnet-version: 8.0.x - - name: Restore dependencies - run: dotnet restore - - name: Build - run: dotnet build --configuration Release --no-restore - - name: Publish - run: dotnet publish ./OpenXmlToHtmlOpenApi/OpenXmlToHtmlOpenApi.csproj --configuration Release -o ./Publish - - uses: azure/webapps-deploy@v3 - with: - publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} - package: './Publish' diff --git a/.vscode/settings.json b/.vscode/settings.json index 200e5dd..dfdd276 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,5 +9,11 @@ "nupkg", "snupkg" ], - "editor.formatOnSave": true + "editor.formatOnSave": true, + "dotnet.testDiscovery.enabled": true, + "dotnet.testProjectPath": [ + "OpenXmlToHtmlTests", + "OpenXmlToHtmlOpenApiTests" + ], + "testing.autoRun.mode": "rerun" } \ No newline at end of file diff --git a/OpenXmlToHtml/OpenXmlToHtml.csproj b/OpenXmlToHtml/OpenXmlToHtml.csproj index 4a91b97..044e24a 100644 --- a/OpenXmlToHtml/OpenXmlToHtml.csproj +++ b/OpenXmlToHtml/OpenXmlToHtml.csproj @@ -40,9 +40,9 @@ - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/OpenXmlToHtmlCli/OpenXmlToHtmlCli.csproj b/OpenXmlToHtmlCli/OpenXmlToHtmlCli.csproj index cee23c1..16256fd 100644 --- a/OpenXmlToHtmlCli/OpenXmlToHtmlCli.csproj +++ b/OpenXmlToHtmlCli/OpenXmlToHtmlCli.csproj @@ -9,7 +9,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -17,7 +17,7 @@ - + diff --git a/OpenXmlToHtmlOpenApiTests/OpenXmlToHtmlOpenApiTests.csproj b/OpenXmlToHtmlOpenApiTests/OpenXmlToHtmlOpenApiTests.csproj index 6df0114..46b415d 100644 --- a/OpenXmlToHtmlOpenApiTests/OpenXmlToHtmlOpenApiTests.csproj +++ b/OpenXmlToHtmlOpenApiTests/OpenXmlToHtmlOpenApiTests.csproj @@ -7,16 +7,16 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/OpenXmlToHtmlTests/OpenXmlToHtmlIntegrationTests.cs b/OpenXmlToHtmlTests/OpenXmlToHtmlIntegrationTests.cs index f1a61ff..29cf8ed 100644 --- a/OpenXmlToHtmlTests/OpenXmlToHtmlIntegrationTests.cs +++ b/OpenXmlToHtmlTests/OpenXmlToHtmlIntegrationTests.cs @@ -1,8 +1,7 @@ using Codeuctivity.HtmlRenderer; using Codeuctivity.OpenXmlToHtml; using PdfSharp.Pdf.IO; -using SixLabors.ImageSharp; -using SixLabors.ImageSharp.PixelFormats; +using SkiaSharp; using System.Collections.Generic; using System.IO; using System.Linq; @@ -68,8 +67,8 @@ public async Task ShouldConvertDocumentAndExportImagesIntegrativeTest(string tes private static bool IsValidBitmap(byte[] blob) { - var image = Image.Load(blob); - return image.Width > 1 && image.Height > 1; + using var image = SKBitmap.Decode(blob); + return image != null && image.Width > 1 && image.Height > 1; } [Fact] diff --git a/OpenXmlToHtmlTests/OpenXmlToHtmlTests.csproj b/OpenXmlToHtmlTests/OpenXmlToHtmlTests.csproj index ad831e9..7176345 100644 --- a/OpenXmlToHtmlTests/OpenXmlToHtmlTests.csproj +++ b/OpenXmlToHtmlTests/OpenXmlToHtmlTests.csproj @@ -18,13 +18,13 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + - + runtime; build; native; contentfiles; analyzers; buildtransitive all From e819d73bc6ac029bd45220ceba9186a37595425c Mon Sep 17 00:00:00 2001 From: Stefan Seeland <168659+stesee@users.noreply.github.com> Date: Sat, 16 Aug 2025 21:03:57 +0200 Subject: [PATCH 2/3] Enhance error handling in ExportImageHandler and improve Linux utility class documentation --- OpenXmlToHtml/ExportImageHandler.cs | 7 ++++++- OpenXmlToHtml/Tooling/Linux.cs | 18 ++++++++++++++++-- OpenXmlToHtmlCli/Program.cs | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/OpenXmlToHtml/ExportImageHandler.cs b/OpenXmlToHtml/ExportImageHandler.cs index 8ff399e..500eddc 100644 --- a/OpenXmlToHtml/ExportImageHandler.cs +++ b/OpenXmlToHtml/ExportImageHandler.cs @@ -33,6 +33,11 @@ public ExportImageHandler(IDictionary images) /// public XElement TransformImage(ImageInfo imageInfo) { + if (imageInfo?.Image == null) + { + throw new ArgumentException("ImageInfo or Image cannot be null", nameof(imageInfo)); + } + var cid = Guid.NewGuid().ToString(); using var memoryStream = new MemoryStream(); imageInfo.Image.CopyTo(memoryStream); @@ -41,7 +46,7 @@ public XElement TransformImage(ImageInfo imageInfo) var cidReference = $"cid: {cid}"; - return new XElement(Xhtml.img, new XAttribute(NoNamespace.src, cidReference), imageInfo.ImgStyleAttribute, imageInfo?.AltText != null ? new XAttribute(NoNamespace.alt, imageInfo.AltText) : null); + return new XElement(Xhtml.img, new XAttribute(NoNamespace.src, cidReference), imageInfo.ImgStyleAttribute, !string.IsNullOrEmpty(imageInfo?.AltText) ? new XAttribute(NoNamespace.alt, imageInfo.AltText) : null); } } } \ No newline at end of file diff --git a/OpenXmlToHtml/Tooling/Linux.cs b/OpenXmlToHtml/Tooling/Linux.cs index f1fc3fd..37a869c 100644 --- a/OpenXmlToHtml/Tooling/Linux.cs +++ b/OpenXmlToHtml/Tooling/Linux.cs @@ -4,10 +4,20 @@ namespace Codeuctivity.OpenXmlToHtml.Tooling { - public class Linux + /// + /// Utility class for Linux-specific operations and Azure Linux environment detection + /// + public static class Linux { + /// + /// Command to install Chromium dependencies on Linux systems + /// public static readonly string ChromiumInstallCommand = "export DEBIAN_FRONTEND=noninteractive && apt update && apt upgrade -y && apt install mc libgconf-2-4 libatk1.0-0 libatk-bridge2.0-0 libgdk-pixbuf2.0-0 libgtk-3-0 libgbm-dev libasound2 libnss3 -y"; + /// + /// Sets up Linux dependencies required for Chromium operation + /// + /// Thrown when dependency installation fails public static void SetupDependencies() { var azureLinuxAppChromeDependencies = ChromiumInstallCommand; @@ -31,10 +41,14 @@ public static void SetupDependencies() if (process.ExitCode != 0) { - throw new Exception($"Failed to execute '{ChromiumInstallCommand}'"); + throw new InvalidOperationException($"Failed to execute '{ChromiumInstallCommand}'"); } } + /// + /// Determines whether the current environment is running on Azure Linux + /// + /// True if running on Azure Linux, false otherwise public static bool IsRunningOnAzureLinux() { var websiteSku = Environment.GetEnvironmentVariable("WEBSITE_SKU"); diff --git a/OpenXmlToHtmlCli/Program.cs b/OpenXmlToHtmlCli/Program.cs index dc84d0f..fb0934a 100644 --- a/OpenXmlToHtmlCli/Program.cs +++ b/OpenXmlToHtmlCli/Program.cs @@ -5,7 +5,7 @@ namespace OpenXmlToHtmlCli { - internal class Program + internal static class Program { private static async Task Main(string[] args) { From 2a894f3c24f82512466958575057ee1c554f3ff3 Mon Sep 17 00:00:00 2001 From: Stefan Seeland <168659+stesee@users.noreply.github.com> Date: Sun, 17 Aug 2025 08:44:51 +0200 Subject: [PATCH 3/3] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- OpenXmlToHtml/ExportImageHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenXmlToHtml/ExportImageHandler.cs b/OpenXmlToHtml/ExportImageHandler.cs index 500eddc..0b6617a 100644 --- a/OpenXmlToHtml/ExportImageHandler.cs +++ b/OpenXmlToHtml/ExportImageHandler.cs @@ -46,7 +46,7 @@ public XElement TransformImage(ImageInfo imageInfo) var cidReference = $"cid: {cid}"; - return new XElement(Xhtml.img, new XAttribute(NoNamespace.src, cidReference), imageInfo.ImgStyleAttribute, !string.IsNullOrEmpty(imageInfo?.AltText) ? new XAttribute(NoNamespace.alt, imageInfo.AltText) : null); + return new XElement(Xhtml.img, new XAttribute(NoNamespace.src, cidReference), imageInfo.ImgStyleAttribute, !string.IsNullOrEmpty(imageInfo.AltText) ? new XAttribute(NoNamespace.alt, imageInfo.AltText) : null); } } } \ No newline at end of file