Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 63 additions & 91 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@
"nupkg",
"snupkg"
],
"editor.formatOnSave": true
"editor.formatOnSave": true,
"dotnet.testDiscovery.enabled": true,
"dotnet.testProjectPath": [
"OpenXmlToHtmlTests",
"OpenXmlToHtmlOpenApiTests"
],
"testing.autoRun.mode": "rerun"
}
7 changes: 6 additions & 1 deletion OpenXmlToHtml/ExportImageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public ExportImageHandler(IDictionary<string, byte[]> images)
/// <returns></returns>
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);
Expand All @@ -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);
}
}
}
4 changes: 2 additions & 2 deletions OpenXmlToHtml/OpenXmlToHtml.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Codeuctivity.OpenXmlPowerTools" Version="8.0.374" />
<PackageReference Include="Codeuctivity.OpenXmlPowerTools" Version="9.0.385" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.6.0.109712">
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.15.0.120848">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
18 changes: 16 additions & 2 deletions OpenXmlToHtml/Tooling/Linux.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@

namespace Codeuctivity.OpenXmlToHtml.Tooling
{
public class Linux
/// <summary>
/// Utility class for Linux-specific operations and Azure Linux environment detection
/// </summary>
public static class Linux
{
/// <summary>
/// Command to install Chromium dependencies on Linux systems
/// </summary>
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";

/// <summary>
/// Sets up Linux dependencies required for Chromium operation
/// </summary>
/// <exception cref="InvalidOperationException">Thrown when dependency installation fails</exception>
public static void SetupDependencies()
{
var azureLinuxAppChromeDependencies = ChromiumInstallCommand;
Expand All @@ -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}'");
}
}

/// <summary>
/// Determines whether the current environment is running on Azure Linux
/// </summary>
/// <returns>True if running on Azure Linux, false otherwise</returns>
public static bool IsRunningOnAzureLinux()
{
var websiteSku = Environment.GetEnvironmentVariable("WEBSITE_SKU");
Expand Down
4 changes: 2 additions & 2 deletions OpenXmlToHtmlCli/OpenXmlToHtmlCli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.6.0.109712">
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.15.0.120848">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>

<PackageReference Include="Microsoft.NET.ILLink.Tasks" Version="8.0.19" />
<PackageReference Include="Microsoft.NET.ILLink.Tasks" Version="9.0.8" />
<ProjectReference Include="..\OpenXmlToHtml\OpenXmlToHtml.csproj" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion OpenXmlToHtmlCli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace OpenXmlToHtmlCli
{
internal class Program
internal static class Program
{
private static async Task<int> Main(string[] args)
{
Expand Down
6 changes: 3 additions & 3 deletions OpenXmlToHtmlOpenApiTests/OpenXmlToHtmlOpenApiTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AngleSharp" Version="1.2.0" />
<PackageReference Include="AngleSharp" Version="1.3.0" />
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.13" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
7 changes: 3 additions & 4 deletions OpenXmlToHtmlTests/OpenXmlToHtmlIntegrationTests.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -68,8 +67,8 @@ public async Task ShouldConvertDocumentAndExportImagesIntegrativeTest(string tes

private static bool IsValidBitmap(byte[] blob)
{
var image = Image.Load<Rgba32>(blob);
return image.Width > 1 && image.Height > 1;
using var image = SKBitmap.Decode(blob);
return image != null && image.Width > 1 && image.Height > 1;
}

[Fact]
Expand Down
6 changes: 3 additions & 3 deletions OpenXmlToHtmlTests/OpenXmlToHtmlTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
</PackageReference>
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="PdfSharp.netstandard" Version="1.3.2" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.6.0.109712">
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.15.0.120848">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Loading